diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | modifiedmarkdown/__init__.py | 0 | ||||
-rw-r--r-- | modifiedmarkdown/mdown.py | 76 | ||||
-rw-r--r-- | setup.py | 33 |
4 files changed, 112 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0b116e4 --- /dev/null +++ b/.gitignore | |||
@@ -0,0 +1,3 @@ | |||
1 | /*.egg-info | ||
2 | *.pyc | ||
3 | .DS_Store | ||
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)) | ||
diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..fbc46a8 --- /dev/null +++ b/setup.py | |||
@@ -0,0 +1,33 @@ | |||
1 | from setuptools import setup, find_packages | ||
2 | |||
3 | setup( | ||
4 | name="CruteMoinModifiedMarkdown", | ||
5 | version="1.0", | ||
6 | description="", | ||
7 | author="Michael Crute <mcrute@gmail.com>", | ||
8 | license="MIT", | ||
9 | packages=find_packages(), | ||
10 | entry_points={ | ||
11 | # "moin.plugins.action": [ | ||
12 | # ], | ||
13 | # "moin.plugins.converter": [ | ||
14 | # ], | ||
15 | # "moin.plugins.events": [ | ||
16 | # ], | ||
17 | # "moin.plugins.filter": [ | ||
18 | # ], | ||
19 | # "moin.plugins.formatter": [ | ||
20 | # ], | ||
21 | # "moin.plugins.macro": [ | ||
22 | # ], | ||
23 | "moin.plugins.parser": [ | ||
24 | "mdown = modifiedmarkdown.mdown:Parser", | ||
25 | ], | ||
26 | # "moin.plugins.theme": [ | ||
27 | # ], | ||
28 | # "moin.plugins.userprefs": [ | ||
29 | # ], | ||
30 | # "moin.plugins.xmlrpc": [ | ||
31 | # ], | ||
32 | } | ||
33 | ) | ||