##// END OF EJS Templates
#12 Added markdown extension for reflinks, quotes and autolinks.
neko259 -
r52:1697154a default
parent child Browse files
Show More
@@ -0,0 +1,61 b''
1 import markdown
2 from markdown.inlinepatterns import Pattern
3 from markdown.util import etree
4
5 __author__ = 'vurdalak'
6
7
8 class AutolinkPattern(Pattern):
9 def handleMatch(self, m):
10 link_element = etree.Element('a')
11 href = m.group(2)
12 link_element.set('href', href)
13 link_element.text = href
14
15 return link_element
16
17
18 class QuotePattern(Pattern):
19 def handleMatch(self, m):
20 quote_element = etree.Element('span')
21 quote_element.set('class', 'quote')
22 quote_element.text = m.group(3)
23
24 return quote_element
25
26
27 class ReflinkPattern(Pattern):
28 def handleMatch(self, m):
29 ref_element = etree.Element('a')
30 post_id = m.group(4)
31 ref_element.set('href', '#' + str(post_id))
32 ref_element.text = '#' + post_id
33
34 return ref_element
35
36
37 class NeboardMarkdown(markdown.Extension):
38 AUTOLINK_PATTERN = r'(http://\S+)'
39 QUOTE_PATTERN = r'(>){1}(.+)'
40 REFLINK_PATTERN = r'((>){2}(\d+))'
41
42 def extendMarkdown(self, md, md_globals):
43 autolink = AutolinkPattern(self.AUTOLINK_PATTERN, md)
44 quote = QuotePattern(self.QUOTE_PATTERN, md)
45 reflink = ReflinkPattern(self.REFLINK_PATTERN, md)
46
47 md.inlinePatterns[u'autolink_ext'] = autolink
48 md.inlinePatterns[u'reflink'] = reflink
49 md.inlinePatterns[u'quote'] = quote
50
51 del(md.inlinePatterns[u'entity'])
52
53
54 def makeExtension(configs=None):
55 return NeboardMarkdown(configs=configs)
56
57 neboard_extension = makeExtension()
58
59
60 def markdown_extended(markup):
61 return markdown.markdown(markup, [neboard_extension])
@@ -5,6 +5,9 b' from django.db import models'
5 from django.utils import timezone
5 from django.utils import timezone
6 import time
6 import time
7 import math
7 import math
8 import markdown
9 from markdown.inlinepatterns import Pattern
10 from markdown.util import etree
8
11
9 from neboard import settings
12 from neboard import settings
10 from markupfield.fields import MarkupField
13 from markupfield.fields import MarkupField
@@ -94,7 +97,6 b' class PostManager(models.Manager):'
94
97
95 return int(math.ceil(len(threads) / float(settings.THREADS_PER_PAGE)))
98 return int(math.ceil(len(threads) / float(settings.THREADS_PER_PAGE)))
96
99
97
98 def _delete_old_threads(self):
100 def _delete_old_threads(self):
99 """
101 """
100 Preserves maximum thread count. If there are too many threads,
102 Preserves maximum thread count. If there are too many threads,
@@ -244,5 +246,4 b' class Admin(models.Model):'
244 password = models.CharField(max_length=100)
246 password = models.CharField(max_length=100)
245
247
246 def __unicode__(self):
248 def __unicode__(self):
247 return self.name + '/' + '*' * len(self.password)
249 return self.name + '/' + '*' * len(self.password) No newline at end of file
248
@@ -173,4 +173,10 b' blockquote {'
173
173
174 .dead_post {
174 .dead_post {
175 background-color: #442222;
175 background-color: #442222;
176 }
177
178 .quote {
179 color: greenyellow;
180 padding-left: 5px;
181 border-left: solid 2px greenyellow;
176 } No newline at end of file
182 }
@@ -1,5 +1,7 b''
1 # Django settings for neboard project.
1 # Django settings for neboard project.
2 import os
2 import os
3 import markdown
4 from boards.mdx_neboard import markdown_extended
3
5
4 DEBUG = True
6 DEBUG = True
5 TEMPLATE_DEBUG = DEBUG
7 TEMPLATE_DEBUG = DEBUG
@@ -177,3 +179,7 b' THEMES = ['
177 ('md', 'Mystic Dark'),
179 ('md', 'Mystic Dark'),
178 ('sw', 'Snow White') ]
180 ('sw', 'Snow White') ]
179 DEFAULT_THEME = 'md'
181 DEFAULT_THEME = 'md'
182
183 MARKUP_FIELD_TYPES = (
184 ('markdown', markdown_extended),
185 ) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now