##// END OF EJS Templates
Parse text with <p> tag. Use single newline after replying a post. Removed...
Parse text with <p> tag. Use single newline after replying a post. Removed striped form error message background

File last commit:

r744:3db85d22 2.0-dev
r744:3db85d22 2.0-dev
Show More
mdx_neboard.py
152 lines | 3.3 KiB | text/x-python | PythonLexer
neko259
Replace '--' with '—' character
r699 # coding=utf-8
neko259
Very alpha bbcode support (markdown removed)
r736 import re
import bbcode
neko259
Small code cleanups
r721
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
Small code cleanups
r721
neko259
Implemented RSS support. This fixes #11
r89 __author__ = 'neko259'
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52
neko259
Very alpha bbcode support (markdown removed)
r736 REFLINK_PATTERN = re.compile(r'\d+')
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
"""
neko259
Small code cleanups
r721 def __init__(self):
pass
neko259
Added a new format panel to the text form
r438 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
Very alpha bbcode support (markdown removed)
r736 class AutolinkPattern():
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52 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
Very alpha bbcode support (markdown removed)
r736 class QuotePattern(TextFormatter):
name = 'q'
preview_left = '<span class="multiquote">'
neko259
Added a new format panel to the text form
r438 preview_right = '</span>'
neko259
Very alpha bbcode support (markdown removed)
r736 format_left = '[quote]'
format_right = '[/quote]'
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52
neko259
Very alpha bbcode support (markdown removed)
r736 class SpoilerPattern(TextFormatter):
name = 'spoiler'
neko259
Added a new format panel to the text form
r438 preview_left = '<span class="spoiler">'
preview_right = '</span>'
neko259
Very alpha bbcode support (markdown removed)
r736 format_left = '[spoiler]'
format_right = '[/spoiler]'
neko259
Added a new format panel to the text form
r438
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
Very alpha bbcode support (markdown removed)
r736 class CommentPattern(TextFormatter):
neko259
Added a new format panel to the text form
r438 name = ''
preview_left = '<span class="comment">// '
preview_right = '</span>'
neko259
Very alpha bbcode support (markdown removed)
r736 format_left = '[comment]'
format_right = '[/comment]'
neko259
#12 Added spoilers and comments.
r56
neko259
Very alpha bbcode support (markdown removed)
r736 class StrikeThroughPattern(TextFormatter):
neko259
Added a new format panel to the text form
r438 name = 's'
preview_left = '<span class="strikethrough">'
preview_right = '</span>'
neko259
Very alpha bbcode support (markdown removed)
r736 format_left = '[s]'
format_right = '[/s]'
neko259
Added strikethrough text to the text parser
r330
neko259
Added a new format panel to the text form
r438 class ItalicPattern(TextFormatter):
name = 'i'
preview_left = '<i>'
preview_right = '</i>'
neko259
Very alpha bbcode support (markdown removed)
r736 format_left = '[i]'
format_right = '[/i]'
neko259
Added a new format panel to the text form
r438
class BoldPattern(TextFormatter):
name = 'b'
preview_left = '<b>'
preview_right = '</b>'
neko259
Very alpha bbcode support (markdown removed)
r736 format_left = '[b]'
format_right = '[/b]'
neko259
Added a new format panel to the text form
r438
neko259
Added proper formatting when several lines are selected
r440 class CodePattern(TextFormatter):
name = 'code'
preview_left = '<code>'
preview_right = '</code>'
neko259
Very alpha bbcode support (markdown removed)
r736 format_left = '[code]'
format_right = '[/code]'
neko259
Replace '--' with '—' character
r699
neko259
Very alpha bbcode support (markdown removed)
r736 def render_reflink(tag_name, value, options, parent, context):
if not REFLINK_PATTERN.match(value):
return u'>>%s' % value
neko259
Removed image tag from markdown. Refactored markdown extension code. This fixes #21
r100
neko259
Very alpha bbcode support (markdown removed)
r736 post_id = int(value)
neko259
Removed image tag from markdown. Refactored markdown extension code. This fixes #21
r100
neko259
Very alpha bbcode support (markdown removed)
r736 posts = boards.models.Post.objects.filter(id=post_id)
if posts.exists():
post = posts[0]
neko259
#12 Added markdown extension for reflinks, quotes and autolinks.
r52
neko259
Very alpha bbcode support (markdown removed)
r736 return u'<a href=%s>&gt;&gt;%s</a>' % (post.get_url(), post_id)
else:
return u'>>%s' % value
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
Very alpha bbcode support (markdown removed)
r736 def bbcode_extended(markup):
neko259
Parse text with <p> tag. Use single newline after replying a post. Removed...
r744 parser = bbcode.Parser(newline='</p><p>')
neko259
Very alpha bbcode support (markdown removed)
r736 parser.add_formatter('post', render_reflink, strip=True)
parser.add_simple_formatter('quote',
u'<span class="multiquote">%(value)s</span>')
parser.add_simple_formatter('comment',
u'<span class="comment">//%(value)s</span>')
parser.add_simple_formatter('spoiler',
u'<span class="spoiler">%(value)s</span>')
parser.add_simple_formatter('s',
u'<span class="strikethrough">%(value)s</span>')
parser.add_simple_formatter('code',
u'<pre><code>%(value)s</pre></code>')
neko259
Parse text with <p> tag. Use single newline after replying a post. Removed...
r744 return '<p>%s</p>' % parser.format(markup)
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 ]