diff options
author | Mike Crute <mcrute@gmail.com> | 2015-05-18 20:24:59 -0700 |
---|---|---|
committer | Mike Crute <mcrute@gmail.com> | 2015-05-18 20:24:59 -0700 |
commit | 5584447865e1bc316eb2c7ff04dfffe9b4b464b7 (patch) | |
tree | 624602fc01eab9fe27098e1da54a631e62d6f826 /modifiedmarkdown | |
download | moin_markdown_ext-master.tar.bz2 moin_markdown_ext-master.tar.xz moin_markdown_ext-master.zip |
Diffstat (limited to 'modifiedmarkdown')
-rw-r--r-- | modifiedmarkdown/__init__.py | 0 | ||||
-rw-r--r-- | modifiedmarkdown/mdown.py | 76 |
2 files changed, 76 insertions, 0 deletions
diff --git a/modifiedmarkdown/__init__.py b/modifiedmarkdown/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/modifiedmarkdown/__init__.py | |||
diff --git a/modifiedmarkdown/mdown.py b/modifiedmarkdown/mdown.py new file mode 100644 index 0000000..41ff6c5 --- /dev/null +++ b/modifiedmarkdown/mdown.py | |||
@@ -0,0 +1,76 @@ | |||
1 | """ | ||
2 | MoinMoin - Parser for Markdown | ||
3 | |||
4 | Syntax: | ||
5 | |||
6 | To use in a code block: | ||
7 | |||
8 | {{{{#!markdown | ||
9 | <add markdown text here> | ||
10 | }}}} | ||
11 | |||
12 | To use for an entire page: | ||
13 | |||
14 | #format markdown | ||
15 | <add markdown text here> | ||
16 | |||
17 | @copyright: 2009 by Jason Fruit (JasonFruit at g mail dot com) | ||
18 | @license: GNU GPL, see http://www.gnu.org/licenses/gpl for details | ||
19 | |||
20 | """ | ||
21 | |||
22 | |||
23 | from markdown import util | ||
24 | from markdown import Markdown | ||
25 | from markdown.extensions import Extension | ||
26 | from markdown.inlinepatterns import Pattern | ||
27 | |||
28 | |||
29 | class ToDoPattern(Pattern): | ||
30 | |||
31 | def __init__(self): | ||
32 | Pattern.__init__(self, "^\[([xX ])\]") | ||
33 | self.counter = 0 | ||
34 | |||
35 | def handleMatch(self, m): | ||
36 | node = util.etree.Element("input") | ||
37 | |||
38 | node.attrib["type"] = "checkbox" | ||
39 | node.attrib["id"] = "md_cbx_{0}".format(self.counter) | ||
40 | self.counter += 1 | ||
41 | node.attrib["value"] = m.group(3).strip() | ||
42 | |||
43 | if m.group(2).upper() == "X": | ||
44 | node.attrib["checked"] = "checked" | ||
45 | |||
46 | return node | ||
47 | |||
48 | |||
49 | class ToDoExtension(Extension): | ||
50 | |||
51 | def extendMarkdown(self, md, md_globals): | ||
52 | md.inlinePatterns.add('todo', ToDoPattern(), "_begin") | ||
53 | |||
54 | |||
55 | |||
56 | Dependencies = ['user'] | ||
57 | |||
58 | class Parser: | ||
59 | """ | ||
60 | A thin wrapper around a Python implementation | ||
61 | (http://www.freewisdom.org/projects/python-markdown/) of John | ||
62 | Gruber's Markdown (http://daringfireball.net/projects/markdown/) | ||
63 | to make it suitable for use with MoinMoin. | ||
64 | """ | ||
65 | def __init__(self, raw, request, **kw): | ||
66 | self.raw = raw | ||
67 | self.request = request | ||
68 | |||
69 | def format(self, formatter): | ||
70 | todo = ToDoExtension(configs={}) | ||
71 | output_html = Markdown(extensions=[todo]).convert(self.raw) | ||
72 | |||
73 | try: | ||
74 | self.request.write(formatter.rawHTML(output_html)) | ||
75 | except: | ||
76 | self.request.write(formatter.escapedText(output_html)) | ||