# HG changeset patch # User Ludovic Chabant # Date 1484239442 28800 # Node ID a2ed337652e77b7c56071c693b4f24e917ea3e6b # Parent c4b673db5190ebfb3ca823c14e09fc099dd237f7 core: Add Jouvence formatter for Fountain pages. diff -r c4b673db5190 -r a2ed337652e7 wikked/wiki.py --- a/wikked/wiki.py Thu Jan 12 08:43:21 2017 -0800 +++ b/wikked/wiki.py Thu Jan 12 08:44:02 2017 -0800 @@ -85,6 +85,7 @@ ['tl', 'text', 'textile']) self.tryAddFormatter('creole', 'creole2html', ['cr', 'creole']) + self.tryAddFountainFormatter() def getSpecialFilenames(self): yield '.wikirc' @@ -102,6 +103,37 @@ except ImportError: pass + def tryAddFountainFormatter(self): + try: + from jouvence.parser import JouvenceParser + from jouvence.html import HtmlDocumentRenderer, get_css + except ImportError: + return + + import io + + def _jouvence_to_html(text): + parser = JouvenceParser() + document = parser.parseString(text) + rdr = HtmlDocumentRenderer(standalone=False) + with io.StringIO() as fp: + rdr.render_doc(document, fp) + return fp.getvalue() + + self.formatters[_jouvence_to_html] = ['fountain'] + + head_css = """ +""" + head_css += '' % get_css() + self.custom_heads = {'fountain': head_css} + def _loadConfig(self): # Merge the default settings with any settings provided by # the local config file(s).