How to use the mistune.create_markdown 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_escape_html(self):
        md = mistune.create_markdown(escape=True)
        result = md('<div>1</div>')
        expected = '<p>&lt;div&gt;1&lt;/div&gt;</p>'
        self.assertEqual(result.strip(), expected)

        result = md('<em>1</em>')
        expected = '<p>&lt;em&gt;1&lt;/em&gt;</p>'
        self.assertEqual(result.strip(), expected)
github lepture / mistune / tests / test_toc.py View on Github external
def parse(text):
        md = create_markdown(
            escape=False,
            plugins=[DirectiveToc()]
        )
        html = md(text)
        return html
github lepture / mistune / tests / test_toc.py View on Github external
def test_extract_toc_items(self):
        md = create_markdown(
            renderer='ast',
            plugins=[DirectiveToc()]
        )
        self.assertEqual(extract_toc_items(md, ''), [])
        s = '# H1\n## H2\n# H1'
        result = extract_toc_items(md, s)
        expected = [
            ('toc_1', 'H1', 1),
            ('toc_2', 'H2', 2),
            ('toc_3', 'H1', 1),
        ]
        self.assertEqual(result, expected)
github lepture / mistune / tests / test_include.py View on Github external
def test_ast_include(self):
        md = create_markdown(
            renderer='ast',
            plugins=[DirectiveInclude()]
        )
        filepath = os.path.join(ROOT, 'include/foo.txt')
        s = '.. include:: hello.txt'
        tokens = md.parse(s, {'__file__': filepath})
        token = tokens[0]
        self.assertEqual(token['type'], 'include')
        self.assertEqual(token['text'], 'hello\n')
        self.assertEqual(token['relpath'], 'hello.txt')
github lepture / mistune / tests / test_include.py View on Github external
def test_include_missing_source(self):
        md = create_markdown(plugins=[DirectiveInclude()])
        s = '.. include:: foo.txt'
        html = md(s)
        self.assertIn('Missing source file', html)
github lepture / mistune / tests / test_misc.py View on Github external
def test_before_parse_hooks(self):
        def _add_name(md, s, state):
            state['name'] = 'test'
            return s, state

        md = mistune.create_markdown()
        md.before_parse_hooks.append(_add_name)
        state = {}
        md.parse('', state)
        self.assertEqual(state['name'], 'test')
github lepture / mistune / tests / test_misc.py View on Github external
def test_emphasis(self):
        md = mistune.create_markdown(escape=True)
        result = md('_em_ **strong**')
        expected = '<p><em>em</em> <strong>strong</strong></p>'
        self.assertEqual(result.strip(), expected)