Show More
@@ -1,96 +1,96 b'' | |||||
1 | from django.core.urlresolvers import reverse |
|
1 | from django.core.urlresolvers import reverse | |
2 | import markdown |
|
2 | import markdown | |
3 | from markdown.inlinepatterns import Pattern |
|
3 | from markdown.inlinepatterns import Pattern | |
4 | from markdown.util import etree |
|
4 | from markdown.util import etree | |
5 | import boards |
|
5 | import boards | |
6 |
|
6 | |||
7 | __author__ = 'neko259' |
|
7 | __author__ = 'neko259' | |
8 |
|
8 | |||
9 |
|
9 | |||
10 | AUTOLINK_PATTERN = r'(https?://\S+)' |
|
10 | AUTOLINK_PATTERN = r'(https?://\S+)' | |
11 | QUOTE_PATTERN = r'^(?<!>)(>[^>]+)$' |
|
11 | QUOTE_PATTERN = r'^(?<!>)(>[^>].+)$' | |
12 | REFLINK_PATTERN = r'((>>)(\d+))' |
|
12 | REFLINK_PATTERN = r'((>>)(\d+))' | |
13 | SPOILER_PATTERN = r'%%(.+)%%' |
|
13 | SPOILER_PATTERN = r'%%(.+)%%' | |
14 | COMMENT_PATTERN = r'^(//(.+))' |
|
14 | COMMENT_PATTERN = r'^(//(.+))' | |
15 |
|
15 | |||
16 | class AutolinkPattern(Pattern): |
|
16 | class AutolinkPattern(Pattern): | |
17 | def handleMatch(self, m): |
|
17 | def handleMatch(self, m): | |
18 | link_element = etree.Element('a') |
|
18 | link_element = etree.Element('a') | |
19 | href = m.group(2) |
|
19 | href = m.group(2) | |
20 | link_element.set('href', href) |
|
20 | link_element.set('href', href) | |
21 | link_element.text = href |
|
21 | link_element.text = href | |
22 |
|
22 | |||
23 | return link_element |
|
23 | return link_element | |
24 |
|
24 | |||
25 |
|
25 | |||
26 | class QuotePattern(Pattern): |
|
26 | class QuotePattern(Pattern): | |
27 | def handleMatch(self, m): |
|
27 | def handleMatch(self, m): | |
28 | quote_element = etree.Element('span') |
|
28 | quote_element = etree.Element('span') | |
29 | quote_element.set('class', 'quote') |
|
29 | quote_element.set('class', 'quote') | |
30 | quote_element.text = m.group(2) |
|
30 | quote_element.text = m.group(2) | |
31 |
|
31 | |||
32 | return quote_element |
|
32 | return quote_element | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | class ReflinkPattern(Pattern): |
|
35 | class ReflinkPattern(Pattern): | |
36 | def handleMatch(self, m): |
|
36 | def handleMatch(self, m): | |
37 | ref_element = etree.Element('a') |
|
37 | ref_element = etree.Element('a') | |
38 | post_id = m.group(4) |
|
38 | post_id = m.group(4) | |
39 | ref_element.set('href', reverse(boards.views.jump_to_post, |
|
39 | ref_element.set('href', reverse(boards.views.jump_to_post, | |
40 | kwargs={'post_id': post_id})) |
|
40 | kwargs={'post_id': post_id})) | |
41 | ref_element.text = m.group(2) |
|
41 | ref_element.text = m.group(2) | |
42 |
|
42 | |||
43 | return ref_element |
|
43 | return ref_element | |
44 |
|
44 | |||
45 |
|
45 | |||
46 | class SpoilerPattern(Pattern): |
|
46 | class SpoilerPattern(Pattern): | |
47 | def handleMatch(self, m): |
|
47 | def handleMatch(self, m): | |
48 | quote_element = etree.Element('span') |
|
48 | quote_element = etree.Element('span') | |
49 | quote_element.set('class', 'spoiler') |
|
49 | quote_element.set('class', 'spoiler') | |
50 | quote_element.text = m.group(2) |
|
50 | quote_element.text = m.group(2) | |
51 |
|
51 | |||
52 | return quote_element |
|
52 | return quote_element | |
53 |
|
53 | |||
54 |
|
54 | |||
55 | class CommentPattern(Pattern): |
|
55 | class CommentPattern(Pattern): | |
56 | def handleMatch(self, m): |
|
56 | def handleMatch(self, m): | |
57 | quote_element = etree.Element('span') |
|
57 | quote_element = etree.Element('span') | |
58 | quote_element.set('class', 'comment') |
|
58 | quote_element.set('class', 'comment') | |
59 | quote_element.text = '//' + m.group(3) |
|
59 | quote_element.text = '//' + m.group(3) | |
60 |
|
60 | |||
61 | return quote_element |
|
61 | return quote_element | |
62 |
|
62 | |||
63 |
|
63 | |||
64 | class NeboardMarkdown(markdown.Extension): |
|
64 | class NeboardMarkdown(markdown.Extension): | |
65 | def extendMarkdown(self, md, md_globals): |
|
65 | def extendMarkdown(self, md, md_globals): | |
66 | self._add_neboard_patterns(md) |
|
66 | self._add_neboard_patterns(md) | |
67 | self._delete_patterns(md) |
|
67 | self._delete_patterns(md) | |
68 |
|
68 | |||
69 | def _delete_patterns(self, md): |
|
69 | def _delete_patterns(self, md): | |
70 | del md.parser.blockprocessors['quote'] |
|
70 | del md.parser.blockprocessors['quote'] | |
71 |
|
71 | |||
72 | del md.inlinePatterns['image_link'] |
|
72 | del md.inlinePatterns['image_link'] | |
73 | del md.inlinePatterns['image_reference'] |
|
73 | del md.inlinePatterns['image_reference'] | |
74 |
|
74 | |||
75 | def _add_neboard_patterns(self, md): |
|
75 | def _add_neboard_patterns(self, md): | |
76 | autolink = AutolinkPattern(AUTOLINK_PATTERN, md) |
|
76 | autolink = AutolinkPattern(AUTOLINK_PATTERN, md) | |
77 | quote = QuotePattern(QUOTE_PATTERN, md) |
|
77 | quote = QuotePattern(QUOTE_PATTERN, md) | |
78 | reflink = ReflinkPattern(REFLINK_PATTERN, md) |
|
78 | reflink = ReflinkPattern(REFLINK_PATTERN, md) | |
79 | spoiler = SpoilerPattern(SPOILER_PATTERN, md) |
|
79 | spoiler = SpoilerPattern(SPOILER_PATTERN, md) | |
80 | comment = CommentPattern(COMMENT_PATTERN, md) |
|
80 | comment = CommentPattern(COMMENT_PATTERN, md) | |
81 |
|
81 | |||
82 | md.inlinePatterns[u'autolink_ext'] = autolink |
|
82 | md.inlinePatterns[u'autolink_ext'] = autolink | |
83 | md.inlinePatterns[u'spoiler'] = spoiler |
|
83 | md.inlinePatterns[u'spoiler'] = spoiler | |
84 | md.inlinePatterns[u'comment'] = comment |
|
84 | md.inlinePatterns[u'comment'] = comment | |
85 | md.inlinePatterns[u'reflink'] = reflink |
|
85 | md.inlinePatterns[u'reflink'] = reflink | |
86 | md.inlinePatterns[u'quote'] = quote |
|
86 | md.inlinePatterns[u'quote'] = quote | |
87 |
|
87 | |||
88 |
|
88 | |||
89 | def makeExtension(configs=None): |
|
89 | def makeExtension(configs=None): | |
90 | return NeboardMarkdown(configs=configs) |
|
90 | return NeboardMarkdown(configs=configs) | |
91 |
|
91 | |||
92 | neboard_extension = makeExtension() |
|
92 | neboard_extension = makeExtension() | |
93 |
|
93 | |||
94 |
|
94 | |||
95 | def markdown_extended(markup): |
|
95 | def markdown_extended(markup): | |
96 | return markdown.markdown(markup, [neboard_extension], safe_mode=True) |
|
96 | return markdown.markdown(markup, [neboard_extension], safe_mode=True) |
@@ -1,21 +1,20 b'' | |||||
1 | = Features = |
|
1 | = Features = | |
2 | [DONE] Connecting tags to each other |
|
2 | [DONE] Connecting tags to each other | |
3 | [DONE] Connect posts to the replies (in messages), get rid of the JS reply map |
|
3 | [DONE] Connect posts to the replies (in messages), get rid of the JS reply map | |
4 |
|
4 | |||
5 | [NOT STARTED] Tree view (JS) |
|
5 | [NOT STARTED] Tree view (JS) | |
6 | [NOT STARTED] Adding tags to images filename |
|
6 | [NOT STARTED] Adding tags to images filename | |
7 | [NOT STARTED] Federative network for s2s communication |
|
7 | [NOT STARTED] Federative network for s2s communication | |
8 | [NOT STARTED] XMPP gate |
|
8 | [NOT STARTED] XMPP gate | |
9 | [NOT STARTED] Bitmessage gate |
|
9 | [NOT STARTED] Bitmessage gate | |
10 | [NOT STARTED] Notification engine |
|
10 | [NOT STARTED] Notification engine | |
11 | [NOT STARTED] Javascript disabling engine |
|
11 | [NOT STARTED] Javascript disabling engine | |
12 | [NOT STARTED] Thread autoupdate (JS + API) |
|
12 | [NOT STARTED] Thread autoupdate (JS + API) | |
13 | [NOT STARTED] Better django admin pages to simplify admin operations |
|
13 | [NOT STARTED] Better django admin pages to simplify admin operations | |
14 | [NOT STARTED] Regen script to update all posts |
|
14 | [NOT STARTED] Regen script to update all posts | |
15 | [NOT STARTED] Group tags by first letter in all tags list |
|
15 | [NOT STARTED] Group tags by first letter in all tags list | |
16 | [NOT STARTED] Show board speed in the lower panel (posts per day) |
|
16 | [NOT STARTED] Show board speed in the lower panel (posts per day) | |
17 |
|
17 | |||
18 | = Bugs = |
|
18 | = Bugs = | |
19 | [DONE] Fix bug with creating threads from tag view |
|
19 | [DONE] Fix bug with creating threads from tag view | |
20 |
|
20 | [DONE] Quote characters within quote causes quote parsing to fail | ||
21 | [NOT STARTED] Quote characters within quote causes quote parsing to fail |
|
General Comments 0
You need to be logged in to leave comments.
Login now