scragg0x / realms-wiki

Git based wiki inspired by Gollum
http://realms.io
GNU General Public License v2.0
831 stars 90 forks source link

Hooking Wiki.get_page #95

Closed gazpachoking closed 8 years ago

gazpachoking commented 8 years ago

So, I'm trying to write a really quick plugin which will autolink to our github issues from the wiki. (sorta like github does itself.) That worked out almost perfectly with this little snippet:

import re

from realms.modules.wiki.models import Wiki

@Wiki.after('get_page')
def wiki_get_page(name, sha=None, rv=None, **kwargs):
    rv['data'] = re.sub(r'(?<![\w\d])(#(\d{3,4}))(?![\w\d])',
                        r'[\1](https://github.com/Flexget/Flexget/issues/\2)',
                        rv['data'])

The only issue is that when you go to edit the page, the replaced markdown will be shown in the edit view, and thus saved the long way back to the wiki.

Is there a better way to go about this at the moment? If not, can we make somewhere better to hook for viewing only?

scragg0x commented 8 years ago

You would want to add that logic to the markdown renderer in JavaScript. MDR

gazpachoking commented 8 years ago

Javascript, ugh. :wink: I actually decided we don't need this, but thanks for the info all the same.