From 5584447865e1bc316eb2c7ff04dfffe9b4b464b7 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Mon, 18 May 2015 20:24:59 -0700 Subject: Initial import --- .gitignore | 3 ++ modifiedmarkdown/__init__.py | 0 modifiedmarkdown/mdown.py | 76 ++++++++++++++++++++++++++++++++++++++++++++ setup.py | 33 +++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 .gitignore create mode 100644 modifiedmarkdown/__init__.py create mode 100644 modifiedmarkdown/mdown.py create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0b116e4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/*.egg-info +*.pyc +.DS_Store diff --git a/modifiedmarkdown/__init__.py b/modifiedmarkdown/__init__.py new file mode 100644 index 0000000..e69de29 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 @@ +""" + MoinMoin - Parser for Markdown + + Syntax: + + To use in a code block: + + {{{{#!markdown + + }}}} + + To use for an entire page: + + #format markdown + + + @copyright: 2009 by Jason Fruit (JasonFruit at g mail dot com) + @license: GNU GPL, see http://www.gnu.org/licenses/gpl for details + +""" + + +from markdown import util +from markdown import Markdown +from markdown.extensions import Extension +from markdown.inlinepatterns import Pattern + + +class ToDoPattern(Pattern): + + def __init__(self): + Pattern.__init__(self, "^\[([xX ])\]") + self.counter = 0 + + def handleMatch(self, m): + node = util.etree.Element("input") + + node.attrib["type"] = "checkbox" + node.attrib["id"] = "md_cbx_{0}".format(self.counter) + self.counter += 1 + node.attrib["value"] = m.group(3).strip() + + if m.group(2).upper() == "X": + node.attrib["checked"] = "checked" + + return node + + +class ToDoExtension(Extension): + + def extendMarkdown(self, md, md_globals): + md.inlinePatterns.add('todo', ToDoPattern(), "_begin") + + + +Dependencies = ['user'] + +class Parser: + """ + A thin wrapper around a Python implementation + (http://www.freewisdom.org/projects/python-markdown/) of John + Gruber's Markdown (http://daringfireball.net/projects/markdown/) + to make it suitable for use with MoinMoin. + """ + def __init__(self, raw, request, **kw): + self.raw = raw + self.request = request + + def format(self, formatter): + todo = ToDoExtension(configs={}) + output_html = Markdown(extensions=[todo]).convert(self.raw) + + try: + self.request.write(formatter.rawHTML(output_html)) + except: + 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 @@ +from setuptools import setup, find_packages + +setup( + name="CruteMoinModifiedMarkdown", + version="1.0", + description="", + author="Michael Crute ", + license="MIT", + packages=find_packages(), + entry_points={ +# "moin.plugins.action": [ +# ], +# "moin.plugins.converter": [ +# ], +# "moin.plugins.events": [ +# ], +# "moin.plugins.filter": [ +# ], +# "moin.plugins.formatter": [ +# ], +# "moin.plugins.macro": [ +# ], + "moin.plugins.parser": [ + "mdown = modifiedmarkdown.mdown:Parser", + ], +# "moin.plugins.theme": [ +# ], +# "moin.plugins.userprefs": [ +# ], +# "moin.plugins.xmlrpc": [ +# ], + } +) -- cgit v1.2.3