1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
from mistune import create_markdown
from mistune.plugins.table import table_in_list, table_in_quote
from mistune.plugins.math import math_in_list, math_in_quote
from tests import BaseTestCase
def load_plugin(plugin_name):
md1 = create_markdown(escape=False, plugins=[plugin_name])
md2 = create_markdown(escape=False, plugins=[plugin_name, "speedup"])
class TestPlugin1(BaseTestCase):
parse = md1
class TestPlugin2(BaseTestCase):
parse = md2
TestPlugin1.load_fixtures(plugin_name + ".txt")
TestPlugin2.load_fixtures(plugin_name + ".txt")
globals()["TestPlugin1_" + plugin_name] = TestPlugin1
globals()["TestPlugin2_" + plugin_name] = TestPlugin2
load_plugin("url")
load_plugin("strikethrough")
load_plugin("mark")
load_plugin("insert")
load_plugin("superscript")
load_plugin("subscript")
load_plugin("task_lists")
load_plugin("table")
load_plugin("def_list")
load_plugin("footnotes")
load_plugin("abbr")
load_plugin("math")
load_plugin("ruby")
load_plugin("spoiler")
class TestExtraPlugins(BaseTestCase):
def test_table_in_list(self):
text = """- Cell | Cell\n ---- | ----\n 1 | 2\n"""
md1 = create_markdown(escape=False)
md2 = create_markdown(escape=False, plugins=["table", table_in_list])
self.assertNotIn("<table>", md1(text))
self.assertIn("<table>", md2(text))
def test_table_in_quote(self):
text = """> Cell | Cell\n> ---- | ----\n> 1 | 2\n"""
md1 = create_markdown(escape=False)
md2 = create_markdown(escape=False, plugins=["table", table_in_quote])
self.assertNotIn("<table>", md1(text))
self.assertIn("<table>", md2(text))
def test_math_in_list(self):
text = """- $$\n foo\n $$\n"""
md1 = create_markdown(escape=False)
md2 = create_markdown(escape=False, plugins=["math", math_in_list])
self.assertNotIn('class="math"', md1(text))
self.assertIn('class="math"', md2(text))
def test_math_in_quote(self):
text = """> $$\n> foo\n> $$\n"""
md1 = create_markdown(escape=False)
md2 = create_markdown(escape=False, plugins=["math", math_in_quote])
self.assertNotIn('class="math"', md1(text))
self.assertIn('class="math"', md2(text))
|