Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_escape_html(self):
md = mistune.create_markdown(escape=True)
result = md('<div>1</div>')
expected = '<p><div>1</div></p>'
self.assertEqual(result.strip(), expected)
result = md('<em>1</em>')
expected = '<p><em>1</em></p>'
self.assertEqual(result.strip(), expected)
def parse(text):
md = create_markdown(
escape=False,
plugins=[DirectiveToc()]
)
html = md(text)
return html
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)
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')
def test_include_missing_source(self):
md = create_markdown(plugins=[DirectiveInclude()])
s = '.. include:: foo.txt'
html = md(s)
self.assertIn('Missing source file', html)
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')
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)