How to use the mistune.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 / tests / test_misc.py View on Github external
def test_use_plugin(self):
        from mistune.plugins import plugin_url
        md = mistune.Markdown(mistune.HTMLRenderer())
        md.use(plugin_url)
github lepture / mistune / tests / test_misc.py View on Github external
def test_allow_harmful_protocols(self):
        renderer = mistune.HTMLRenderer(allow_harmful_protocols=True)
        md = mistune.Markdown(renderer)
        result = md('[h](javascript:alert)')
        expected = '<p><a>h</a></p>'
        self.assertEqual(result.strip(), expected)
github lepture / mistune / tests / test_footnote.py View on Github external
from mistune import Markdown, AstRenderer, HTMLRenderer
from mistune.plugins import plugin_footnote
from tests import fixtures
from unittest import TestCase


md = Markdown(renderer=HTMLRenderer(escape=False), plugins=[plugin_footnote])


class TestPluginFootnote(TestCase):
    def test_ast_renderer(self):
        md = Markdown(renderer=AstRenderer(), plugins=[plugin_footnote])
        data = fixtures.load_json('footnote.json')
        self.assertEqual(md(data['text']), data['tokens'])


def assert_method(self, name, text, html):
    result = md(text)
    self.assertEqual(result, html)


fixtures.load_cases(TestPluginFootnote, assert_method, 'footnote.txt')
github lepture / mistune / tests / test_misc.py View on Github external
def test_allow_data_protocols(self):
        renderer = mistune.HTMLRenderer(allow_harmful_protocols=['data:'])
        md = mistune.Markdown(renderer)
        result = md('[h](data:alert)')
        expected = '<p><a>h</a></p>'
        self.assertEqual(result.strip(), expected)
github lepture / mistune / tests / test_plugins.py View on Github external
def load_plugin(plugin_name, ast=False):
    _plugin = getattr(plugins, 'plugin_{}'.format(plugin_name))

    class TestPlugin(BaseTestCase):
        md = Markdown(
            renderer=HTMLRenderer(escape=False),
            plugins=[_plugin]
        )

    def test_ast_renderer(self):
        md = Markdown(renderer=AstRenderer(), plugins=[_plugin])
        data = fixtures.load_json(plugin_name + '.json')
        self.assertEqual(md(data['text']), data['tokens'])

    if ast:
        test_ast_renderer.__doc__ = 'Run {} ast renderer'.format(plugin_name)
        setattr(TestPlugin, 'test_ast_renderer', test_ast_renderer)

    TestPlugin.load_fixtures(plugin_name + '.txt')
    globals()['TestPlugin_' + plugin_name] = TestPlugin
github JmPotato / Pomash / Pomash / libs / markdown.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import re
import mistune

from pygments import highlight
from pygments.styles import get_style_by_name
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter

from .utils import trim
from .. import dark_mode, pygments_style_light, pygments_style_dark


class MyRenderer(mistune.HTMLRenderer):
    def emphasis(self, text):
        return '%s' % text

    def block_code(self, code, language=None):
        if language:
            try:
                lexer = get_lexer_by_name(language, stripall=True)
            except:
                return "<pre><code>%s</code></pre>" % code.strip()
        else:
            return "<pre><code>%s</code></pre>" % code.strip()

        try:
            get_style_by_name(trim(pygments_style_light))
            light_style = trim(pygments_style_light)
        except: