How to use the mistune.renderers.HTMLRenderer function in mistune

To help you get started, we’ve selected a few mistune examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lepture / mistune / mistune / __init__.py View on Github external
:param escape: Boolean. If using html renderer, escape html.
    :param renderer: renderer instance or string of ``html`` and ``ast``.
    :param plugins: List of plugins, string or callable.

    This method is used when you want to re-use a Markdown instance::

        markdown = create_markdown(
            escape=False,
            renderer='html',
            plugins=['url', 'strikethrough', 'footnotes', 'table'],
        )
        # re-use markdown function
        markdown('.... your text ...')
    """
    if renderer is None or renderer == 'html':
        renderer = HTMLRenderer(escape=escape)
    elif renderer == 'ast':
        renderer = AstRenderer()

    if plugins:
        _plugins = []
        for p in plugins:
            if isinstance(p, str):
                _plugins.append(PLUGINS[p])
            else:
                _plugins.append(p)
        plugins = _plugins
    return Markdown(renderer, plugins=plugins)
github lepture / mistune / mistune / renderers.py View on Github external
def __init__(self, escape=True, allow_harmful_protocols=None):
        super(HTMLRenderer, self).__init__()
        self._escape = escape
        self._allow_harmful_protocols = allow_harmful_protocols
github lepture / mistune / mistune / toc.py View on Github external
import re
from mistune.scanner import escape_url
from mistune.renderers import HTMLRenderer

TAG = re.compile(r'<.*?>')
LINK = re.compile(r'')


class TocRenderer(HTMLRenderer):
    def __init__(self, toc_level=3, escape=True):
        super(TocRenderer, self).__init__(escape=escape)
        self._toc_level = 3
        self._tocs = []

    def heading(self, text, level):
        if level > self._toc_level:
            return super(TocRenderer, self).heading(text, level)

        k = gen_toc_id(text)
        self._tocs.append((k, text, level))

        tag = 'h' + str(level)
        html = '<' + tag + ' id="' + k + '">'
        return html + text + '\n'