##// END OF EJS Templates
Made post preview border less 'invasive'
Made post preview border less 'invasive'

File last commit:

r699:e0309bfd 1.8-dev
r711:849df175 default
Show More
mdx_neboard.py
202 lines | 4.8 KiB | text/x-python | PythonLexer
neko259
Replace '--' with '—' character
r699 # coding=utf-8
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52 import markdown
neko259
Removed tag popularity ratings, they are too slow. Added API to get tag...
r651 from markdown.inlinepatterns import Pattern, SubstituteTagPattern
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52 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 quoting single character
r644 QUOTE_PATTERN = r'^(?<!>)(>[^>].*)$'
neko259
Speed up parsing by moving constants to module scape
r302 REFLINK_PATTERN = r'((>>)(\d+))'
neko259
Fixed using multiple spoilers in one post
r487 SPOILER_PATTERN = r'%%([^(%%)]+)%%'
neko259
Speed up parsing by moving constants to module scape
r302 COMMENT_PATTERN = r'^(//(.+))'
neko259
Added strikethrough text to the text parser
r330 STRIKETHROUGH_PATTERN = r'~(.+)~'
neko259
Replace '--' with '—' character
r699 DASH_PATTERN = r'--'
neko259
Speed up parsing by moving constants to module scape
r302
neko259
Split up post model into post and thread to normalise models. Still need some refactoring
r398
neko259
Added a new format panel to the text form
r438 class TextFormatter():
"""
An interface for formatter that can be used in the text format panel
"""
name = ''
# Left and right tags for the button preview
preview_left = ''
preview_right = ''
# Left and right characters for the textarea input
format_left = ''
format_right = ''
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
neko259
Added a new format panel to the text form
r438 class QuotePattern(Pattern, TextFormatter):
name = ''
preview_left = '<span class="quote">&gt; '
preview_right = '</span>'
format_left = '&gt;'
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52 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
Split up post model into post and thread to normalise models. Still need some refactoring
r398 post = posts[0]
Pavel Ryapolov
Parsing reflinks without jumper
r310
neko259
Added post url caching to cache post replies and id urls
r589 ref_element.set('href', post.get_url())
Pavel Ryapolov
Parsing reflinks without jumper
r310 ref_element.text = m.group(2)
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52
neko259
Split up post model into post and thread to normalise models. Still need some refactoring
r398 return ref_element
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52
neko259
Added a new format panel to the text form
r438 class SpoilerPattern(Pattern, TextFormatter):
name = 's'
preview_left = '<span class="spoiler">'
preview_right = '</span>'
format_left = '%%'
format_right = '%%'
neko259
#12 Added spoilers and comments.
r56 def handleMatch(self, m):
quote_element = etree.Element('span')
quote_element.set('class', 'spoiler')
quote_element.text = m.group(2)
return quote_element
neko259
Added a new format panel to the text form
r438 class CommentPattern(Pattern, TextFormatter):
name = ''
preview_left = '<span class="comment">// '
preview_right = '</span>'
format_left = '//'
neko259
#12 Added spoilers and comments.
r56 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 a new format panel to the text form
r438 class StrikeThroughPattern(Pattern, TextFormatter):
name = 's'
preview_left = '<span class="strikethrough">'
preview_right = '</span>'
format_left = '~'
format_right = '~'
neko259
Added strikethrough text to the text parser
r330 def handleMatch(self, m):
quote_element = etree.Element('span')
quote_element.set('class', 'strikethrough')
quote_element.text = m.group(2)
return quote_element
neko259
Added a new format panel to the text form
r438 class ItalicPattern(TextFormatter):
name = 'i'
preview_left = '<i>'
preview_right = '</i>'
format_left = '_'
format_right = '_'
class BoldPattern(TextFormatter):
name = 'b'
preview_left = '<b>'
preview_right = '</b>'
format_left = '__'
format_right = '__'
neko259
Added proper formatting when several lines are selected
r440 class CodePattern(TextFormatter):
name = 'code'
preview_left = '<code>'
preview_right = '</code>'
format_left = ' '
neko259
Replace '--' with '—' character
r699 class DashPattern(Pattern):
def handleMatch(self, m):
return u'—'
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
Fixed post reply parsing
r406 strikethrough = StrikeThroughPattern(STRIKETHROUGH_PATTERN, md)
neko259
Replace '--' with '—' character
r699 dash = DashPattern(DASH_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
Fixed post reply parsing
r406 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
Replace '--' with '—' character
r699 md.inlinePatterns[u'dash'] = dash
neko259
Changed parser to show quotes and reflinks as they are posted, not with borders and '#' character.
r90
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52
neko259
Small method name change
r442 def make_extension(configs=None):
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52 return NeboardMarkdown(configs=configs)
neko259
Small method name change
r442 neboard_extension = make_extension()
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52
def markdown_extended(markup):
neko259
Removed tag popularity ratings, they are too slow. Added API to get tag...
r651 return markdown.markdown(markup, [neboard_extension, 'nl2br'],
neko259
Escaping HTML in posts.
r654 safe_mode='escape')
neko259
Added a new format panel to the text form
r438
formatters = [
QuotePattern,
SpoilerPattern,
ItalicPattern,
BoldPattern,
CommentPattern,
StrikeThroughPattern,
neko259
Added proper formatting when several lines are selected
r440 CodePattern,
neko259
Added a new format panel to the text form
r438 ]