changeset 1061:8178671f9a04

formatters: Remove Hoedown formatter, split it off to a pluging. Its availability was spotty depending on the platform (because `misaka` doesn't have binaries available for even Windows, for instance). So it was split off to a plugin that the user can install if needed.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 13 Feb 2018 13:32:09 -0800
parents 3678cddf99f9
children 7f7f91275578
files docs/docs/99_reference/08_formatters.md piecrust/formatting/hoedownformatter.py piecrust/formatting/markdownformatter.py piecrust/plugins/builtin.py requirements.txt setup.py
diffstat 6 files changed, 14 insertions(+), 161 deletions(-) [+]
line wrap: on
line diff
--- a/docs/docs/99_reference/08_formatters.md	Tue Feb 13 11:12:29 2018 -0800
+++ b/docs/docs/99_reference/08_formatters.md	Tue Feb 13 13:32:09 2018 -0800
@@ -13,29 +13,29 @@
 
 ## Markdown
 
-Name: `markdown` or `pymarkdown`
+Name: `markdown`
 
 [Markdown][] is a lightweight markup language that makes it easy to write HTML.
 For a primer on its syntax, see the [original documentation][gruber].
 
-The default Markdown formatter in PieCrust is powered by [Hoedown][], which is
-fast and effective. However, is you want a more fully featured Markdown
-formatter and don't mind poorer performance, you can switch to `pymarkdown`,
-which uses [Python-Markdown][pymd].
-
-You can enable Markdown extensions in your website configuration:
+The default Markdown formatter in PieCrust is powered by
+[Python-Markdown][pymd], which works well and has a good number of available
+extensions. You can enable those Markdown extensions in your website
+configuration like this:
 
 ```
 markdown:
   extensions: name,name,name
 ```
 
-The available extension names can be found [here][ext1] for Hoedown, and
-[here][ext2] for Python-Markdown.
+The available extension names for Python-Markdown can be found [here][ext]. The
+name to use is the last piece in the list, so for example the "_Fenced Code
+Blocks_" extension would be enabled with `fenced_code`.
 
-In both cases, the name to use in the website configuration should be the short,
-vaguely friendly name listed on the referenced webpage -- like `tables`,
-`footnotes`, or `fenced_code`.
+> For a vast performance improvement, you can install the `PieCrust-Hoedown`
+> plugin which uses a native (_i.e._ written in C) implementation of Markdown.
+> It may not be available for your system however, which is why it doesn't ship
+> by default with PieCrust.
 
 
 ## Textile
@@ -49,10 +49,8 @@
 
 [markdown]: https://en.wikipedia.org/wiki/Markdown
 [gruber]: https://daringfireball.net/projects/markdown/syntax
-[hoedown]: https://github.com/hoedown/hoedown
 [pymd]: https://python-markdown.github.io/
-[ext1]: http://misaka.61924.nl/#extensions
-[ext2]: https://python-markdown.github.io/extensions/
+[ext]: https://python-markdown.github.io/extensions/
 [textile]: https://en.wikipedia.org/wiki/Textile_%28markup_language%29
 [tx]: https://txstyle.org/
 
--- a/piecrust/formatting/hoedownformatter.py	Tue Feb 13 11:12:29 2018 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,134 +0,0 @@
-import logging
-from piecrust.formatting.base import Formatter
-
-
-logger = logging.getLogger(__name__)
-
-
-class HoedownFormatter(Formatter):
-    FORMAT_NAMES = ['markdown', 'mdown', 'md']
-    OUTPUT_FORMAT = 'html'
-
-    def __init__(self):
-        super(HoedownFormatter, self).__init__()
-        self._formatter = None
-
-    def render(self, format_name, txt):
-        assert format_name in self.FORMAT_NAMES
-        self._ensureInitialized()
-        return self._formatter(txt)
-
-    def _ensureInitialized(self):
-        if self._formatter is not None:
-            return
-
-        import misaka
-
-        # Don't show warnings once for each worker when baking, so only
-        # show them for the first. If the variable is not set, we're not
-        # baking so do show them either way.
-        show_warnings = (self.app.config.get('baker/worker_id', 0) == 0)
-
-        config = self.app.config.get('hoedown')
-        if config is None:
-            config = self.app.config.get('markdown')
-        if config is None:
-            config = {}
-        elif not isinstance(config, dict):
-            raise Exception("The `hoedown` configuration setting must be "
-                            "a dictionary.")
-
-        extensions = config.get('extensions', [])
-        if isinstance(extensions, str):
-            extensions = [e.strip() for e in extensions.split(',')]
-        # Compatibility with PieCrust 1.x
-        if config.get('use_markdown_extra'):
-            extensions.append('extra')
-
-        render_flags = config.get('render_flags')
-        if render_flags is None:
-            render_flags = []
-
-        # Translate standard Markdown formatter extensions to Hoedown
-        # extension/render flags to make it easier to use Hoedown as a drop-in
-        # replacement.
-        exts = 0
-        rdrf = 0
-        other = 0
-        use_smartypants = False
-        for n in extensions:
-            # Special case for Smartypants.
-            if n.lower() in ['smarty', 'smartypants']:
-                use_smartypants = True
-                continue
-
-            # Try an extension?
-            e = getattr(misaka, 'EXT_' + n.upper(), None)
-            if e is not None:
-                exts |= e
-                continue
-
-            # Try a render flag?
-            f = getattr(misaka, 'HTML_' + n.upper(), None)
-            if f is not None:
-                rdrf |= f
-
-            # Other flag?
-            f = getattr(misaka, 'TABLE_' + n.upper(), None)
-            if f is not None:
-                other |= f
-
-            # Try translating from a Markdown extension name.
-            t = ext_translate.get(n)
-            if t is None:
-                if show_warnings:
-                    logger.warning("Unknown Hoedown Markdown extension or flag: "
-                                   "%s" % n)
-                continue
-            if not isinstance(t, list):
-                t = [t]
-            for i in t:
-                if i.startswith('EXT_'):
-                    exts |= getattr(misaka, i)
-                elif i.startswith('HTML_'):
-                    rdrf |= getattr(misaka, i)
-                elif show_warnings:
-                    logger.warning("Unknown Hoedown Markdown extension or flag:"
-                                   "%s" % n)
-            if n == 'extra' and show_warnings:
-                # Special warning for the 'extra' extension.
-                logger.warning(
-                    "The 'extra' extension doesn't have a full equivalent "
-                    "in Hoedown Markdown. Only 'fenced_code', 'footnotes' and "
-                    "'tables' extensions will be active. "
-                    "To remove this warning, replace 'extra' with those 3 "
-                    "specific extensions.")
-
-        # Enable a few things by default.
-        exts |= misaka.EXT_NO_INTRA_EMPHASIS
-
-        renderer = misaka.HtmlRenderer(flags=rdrf)
-        self._formatter = misaka.Markdown(renderer, extensions=(exts | other))
-
-        if use_smartypants:
-            self._formatter = _SmartypantsFormatter(self._formatter,
-                                                    misaka.smartypants)
-
-
-ext_translate = {
-        'fenced_code': 'EXT_FENCED_CODE',
-        'footnotes': 'EXT_FOOTNOTES',
-        'tables': 'EXT_TABLES',
-        'nl2br': 'HTML_HARD_WRAP',
-        'toc': 'HTML_TOC',
-        'extra': ['EXT_FENCED_CODE', 'EXT_FOOTNOTES', 'EXT_TABLES']
-        }
-
-
-class _SmartypantsFormatter:
-    def __init__(self, formatter, smartier):
-        self._fmt = formatter
-        self._sp = smartier
-
-    def __call__(self, txt):
-        return self._sp(self._fmt(txt))
--- a/piecrust/formatting/markdownformatter.py	Tue Feb 13 11:12:29 2018 -0800
+++ b/piecrust/formatting/markdownformatter.py	Tue Feb 13 13:32:09 2018 -0800
@@ -2,7 +2,7 @@
 
 
 class MarkdownFormatter(Formatter):
-    FORMAT_NAMES = ['pymarkdown']
+    FORMAT_NAMES = ['markdown', 'mdown', 'md']
     OUTPUT_FORMAT = 'html'
 
     def __init__(self):
--- a/piecrust/plugins/builtin.py	Tue Feb 13 11:12:29 2018 -0800
+++ b/piecrust/plugins/builtin.py	Tue Feb 13 13:32:09 2018 -0800
@@ -107,14 +107,12 @@
             PystacheTemplateEngine()]
 
     def getFormatters(self):
-        from piecrust.formatting.hoedownformatter import HoedownFormatter
         from piecrust.formatting.markdownformatter import MarkdownFormatter
         from piecrust.formatting.textileformatter import TextileFormatter
         from piecrust.formatting.smartypantsformatter import (
             SmartyPantsFormatter)
 
         return [
-            HoedownFormatter(),
             MarkdownFormatter(),
             SmartyPantsFormatter(),
             TextileFormatter()]
--- a/requirements.txt	Tue Feb 13 11:12:29 2018 -0800
+++ b/requirements.txt	Tue Feb 13 13:32:09 2018 -0800
@@ -1,27 +1,19 @@
-appdirs==1.4.3
-asn1crypto==0.22.0
-cffi==1.11.2
 colorama==0.3.3
 compressinja==0.0.2
-cryptography==1.8.1
 Flask==0.10.1
 Flask-IndieAuth==0.0.3.2
 Flask-Login==0.3.2
-idna==2.5
 Inukshuk==0.1.1
 itsdangerous==0.24
 Jinja2==2.9.6
 Markdown==2.6.2
 MarkupSafe==1.0
-misaka==2.1.0
-packaging==16.8
 paramiko==2.0.0
 Pillow==4.3.0
 py==1.4.33
 pyasn1==0.2.3
 pycparser==2.18
 Pygments==2.0.2
-pyparsing==2.2.0
 pystache==0.5.4
 python-dateutil==2.4.2
 PyYAML==3.11
--- a/setup.py	Tue Feb 13 11:12:29 2018 -0800
+++ b/setup.py	Tue Feb 13 13:32:09 2018 -0800
@@ -161,7 +161,6 @@
     'Jinja2>=2.9.6',
     'Markdown>=2.6.2',
     'MarkupSafe>=1.0',
-    'misaka>=2.1.0',
     'paramiko>=2.0.0',
     'Pillow>=4.3.0',
     'Pygments>=2.0.2',