##// END OF EJS Templates
Removed strange 'exists' method in post manager, fixed tests in which it was...
Removed strange 'exists' method in post manager, fixed tests in which it was used

File last commit:

r330:dd8357bc default
r396:0d260248 default
Show More
mdx_neboard.py
118 lines | 3.3 KiB | text/x-python | PythonLexer
neko259
Added jump view to open message of any thread by id. This fixes #49
r98 from django.core.urlresolvers import reverse
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52 import markdown
from markdown.inlinepatterns import Pattern
from markdown.util import etree
neko259
Added jump view to open message of any thread by id. This fixes #49
r98 import boards
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52
neko259
Implemented RSS support. This fixes #11
r89 __author__ = 'neko259'
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52
neko259
Speed up parsing by moving constants to module scape
r302 AUTOLINK_PATTERN = r'(https?://\S+)'
neko259
Fixed quotes parsing
r303 QUOTE_PATTERN = r'^(?<!>)(>[^>].+)$'
neko259
Speed up parsing by moving constants to module scape
r302 REFLINK_PATTERN = r'((>>)(\d+))'
SPOILER_PATTERN = r'%%(.+)%%'
COMMENT_PATTERN = r'^(//(.+))'
neko259
Added strikethrough text to the text parser
r330 STRIKETHROUGH_PATTERN = r'~(.+)~'
neko259
Speed up parsing by moving constants to module scape
r302
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52 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')
neko259
Changed parser to show quotes and reflinks as they are posted, not with borders and '#' character.
r90 quote_element.text = m.group(2)
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52
return quote_element
class ReflinkPattern(Pattern):
def handleMatch(self, m):
post_id = m.group(4)
Pavel Ryapolov
Parsing reflinks without jumper
r310
neko259
Fixed parsing of links without jumpers (still needed in refmaps).
r311 posts = boards.models.Post.objects.filter(id=post_id)
if posts.count() > 0:
Pavel Ryapolov
Parsing reflinks without jumper
r310 ref_element = etree.Element('a')
neko259
Fixed parsing of links without jumpers (still needed in refmaps).
r311 post = posts[0]
Pavel Ryapolov
Parsing reflinks without jumper
r310 if post.thread:
neko259
Fixed parsing of links without jumpers (still needed in refmaps).
r311 link = reverse(boards.views.thread, kwargs={'post_id': post.thread.id}) \
+ '#' + post_id
Pavel Ryapolov
Parsing reflinks without jumper
r310 else:
neko259
Fixed reflinks to threads parsing
r313 link = reverse(boards.views.thread, kwargs={'post_id': post_id})
Pavel Ryapolov
Parsing reflinks without jumper
r310
ref_element.set('href', link)
ref_element.text = m.group(2)
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52
neko259
Fixed small issue with reflinks to non-existing posts
r314 return ref_element
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52
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
Added strikethrough text to the text parser
r330 class StrikeThroughPattern(Pattern):
def handleMatch(self, m):
quote_element = etree.Element('span')
quote_element.set('class', 'strikethrough')
quote_element.text = m.group(2)
return quote_element
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52 class NeboardMarkdown(markdown.Extension):
def extendMarkdown(self, md, md_globals):
neko259
Removed image tag from markdown. Refactored markdown extension code. This fixes #21
r100 self._add_neboard_patterns(md)
self._delete_patterns(md)
def _delete_patterns(self, md):
del md.parser.blockprocessors['quote']
del md.inlinePatterns['image_link']
del md.inlinePatterns['image_reference']
def _add_neboard_patterns(self, md):
neko259
Speed up parsing by moving constants to module scape
r302 autolink = AutolinkPattern(AUTOLINK_PATTERN, md)
quote = QuotePattern(QUOTE_PATTERN, md)
reflink = ReflinkPattern(REFLINK_PATTERN, md)
spoiler = SpoilerPattern(SPOILER_PATTERN, md)
comment = CommentPattern(COMMENT_PATTERN, md)
neko259
Added strikethrough text to the text parser
r330 strikethrough = StrikeThroughPattern(STRIKETHROUGH_PATTERN, md)
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52
md.inlinePatterns[u'autolink_ext'] = autolink
neko259
#12 Added spoilers and comments.
r56 md.inlinePatterns[u'spoiler'] = spoiler
neko259
Added strikethrough text to the text parser
r330 md.inlinePatterns[u'strikethrough'] = strikethrough
neko259
#12 Added spoilers and comments.
r56 md.inlinePatterns[u'comment'] = comment
neko259
Changed parser to show quotes and reflinks as they are posted, not with borders and '#' character.
r90 md.inlinePatterns[u'reflink'] = reflink
md.inlinePatterns[u'quote'] = quote
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):
neko259
Changed parser to show quotes and reflinks as they are posted, not with borders and '#' character.
r90 return markdown.markdown(markup, [neboard_extension], safe_mode=True)