##// END OF EJS Templates
Limit number of tags shown in the navigation bar to only the most popular ones.
Limit number of tags shown in the navigation bar to only the most popular ones.

File last commit:

r56:d4201a19 default
r57:dcbc67f3 default
Show More
mdx_neboard.py
83 lines | 2.3 KiB | text/x-python | PythonLexer
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52 import markdown
from markdown.inlinepatterns import Pattern
from markdown.util import etree
__author__ = 'vurdalak'
class AutolinkPattern(Pattern):
def handleMatch(self, m):
link_element = etree.Element('a')
href = m.group(2)
link_element.set('href', href)
link_element.text = href
return link_element
class QuotePattern(Pattern):
def handleMatch(self, m):
quote_element = etree.Element('span')
quote_element.set('class', 'quote')
quote_element.text = m.group(3)
return quote_element
class ReflinkPattern(Pattern):
def handleMatch(self, m):
ref_element = etree.Element('a')
post_id = m.group(4)
ref_element.set('href', '#' + str(post_id))
ref_element.text = '#' + post_id
return ref_element
neko259
#12 Added spoilers and comments.
r56 class SpoilerPattern(Pattern):
def handleMatch(self, m):
quote_element = etree.Element('span')
quote_element.set('class', 'spoiler')
quote_element.text = m.group(2)
return quote_element
class CommentPattern(Pattern):
def handleMatch(self, m):
quote_element = etree.Element('span')
quote_element.set('class', 'comment')
quote_element.text = '//' + m.group(3)
return quote_element
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52 class NeboardMarkdown(markdown.Extension):
AUTOLINK_PATTERN = r'(http://\S+)'
QUOTE_PATTERN = r'(>){1}(.+)'
REFLINK_PATTERN = r'((>){2}(\d+))'
neko259
#12 Added spoilers and comments.
r56 SPOILER_PATTERN = r'%%(.+)%%'
COMMENT_PATTERN = r'(//(.+))'
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52
def extendMarkdown(self, md, md_globals):
autolink = AutolinkPattern(self.AUTOLINK_PATTERN, md)
quote = QuotePattern(self.QUOTE_PATTERN, md)
reflink = ReflinkPattern(self.REFLINK_PATTERN, md)
neko259
#12 Added spoilers and comments.
r56 spoiler = SpoilerPattern(self.SPOILER_PATTERN, md)
comment = CommentPattern(self.COMMENT_PATTERN, md)
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52
md.inlinePatterns[u'autolink_ext'] = autolink
neko259
#38 Added smooth scroll to up with jQuery. #12 Fixed parsing of entities (quotes etc).
r55 md.inlinePatterns.add(u'reflink', reflink, '<entity')
md.inlinePatterns.add(u'quote', quote, '<entity')
neko259
#12 Added spoilers and comments.
r56 md.inlinePatterns[u'spoiler'] = spoiler
md.inlinePatterns[u'comment'] = comment
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52
def makeExtension(configs=None):
return NeboardMarkdown(configs=configs)
neboard_extension = makeExtension()
def markdown_extended(markup):
return markdown.markdown(markup, [neboard_extension])