changeset 408:a2ed337652e7

core: Add Jouvence formatter for Fountain pages.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 12 Jan 2017 08:44:02 -0800
parents c4b673db5190
children 7981f2140c14
files wikked/wiki.py
diffstat 1 files changed, 32 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 = """<style>
+body {
+    background-color: #666;
+}
+.jouvence-doc {
+    box-shadow: #111 0px 0.5em 2em;
+}
+</style>
+"""
+        head_css += '<style>%s</style>' % 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).