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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
from pathlib import Path
import pytest
from markdown_it import MarkdownIt
from markdown_it.utils import read_fixture_file
FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures")
@pytest.mark.parametrize(
"line,title,input,expected",
read_fixture_file(FIXTURE_PATH.joinpath("linkify.md")),
)
def test_linkify(line, title, input, expected):
md = MarkdownIt().enable("linkify")
md.options["linkify"] = True
text = md.render(input)
assert text.rstrip() == expected.rstrip()
# if not install linkify-it-py
md.linkify = None
with pytest.raises(ModuleNotFoundError):
md.render(input)
@pytest.mark.parametrize(
"line,title,input,expected",
read_fixture_file(FIXTURE_PATH.joinpath("smartquotes.md")),
)
def test_smartquotes(line, title, input, expected):
md = MarkdownIt().enable("replacements").enable("smartquotes")
md.options["typographer"] = True
text = md.render(input)
assert text.rstrip() == expected.rstrip()
@pytest.mark.parametrize(
"line,title,input,expected",
read_fixture_file(FIXTURE_PATH.joinpath("typographer.md")),
)
def test_typographer(line, title, input, expected):
md = MarkdownIt().enable("replacements")
md.options["typographer"] = True
text = md.render(input)
assert text.rstrip() == expected.rstrip()
@pytest.mark.parametrize(
"line,title,input,expected", read_fixture_file(FIXTURE_PATH.joinpath("tables.md"))
)
def test_table(line, title, input, expected):
md = MarkdownIt().enable("table")
text = md.render(input)
try:
assert text.rstrip() == expected.rstrip()
except AssertionError:
print(text)
raise
@pytest.mark.parametrize(
"line,title,input,expected",
read_fixture_file(FIXTURE_PATH.joinpath("commonmark_extras.md")),
)
def test_commonmark_extras(line, title, input, expected):
md = MarkdownIt("commonmark")
md.options["langPrefix"] = ""
text = md.render(input)
if text.rstrip() != expected.rstrip():
print(text)
assert text.rstrip() == expected.rstrip()
@pytest.mark.parametrize(
"line,title,input,expected",
read_fixture_file(FIXTURE_PATH.joinpath("normalize.md")),
)
def test_normalize_url(line, title, input, expected):
md = MarkdownIt("commonmark")
text = md.render(input)
assert text.rstrip() == expected.rstrip()
@pytest.mark.parametrize(
"line,title,input,expected", read_fixture_file(FIXTURE_PATH.joinpath("fatal.md"))
)
def test_fatal(line, title, input, expected):
md = MarkdownIt("commonmark").enable("replacements")
md.options["typographer"] = True
text = md.render(input)
if text.rstrip() != expected.rstrip():
print(text)
assert text.rstrip() == expected.rstrip()
@pytest.mark.parametrize(
"line,title,input,expected",
read_fixture_file(FIXTURE_PATH.joinpath("strikethrough.md")),
)
def test_strikethrough(line, title, input, expected):
md = MarkdownIt().enable("strikethrough")
text = md.render(input)
assert text.rstrip() == expected.rstrip()
@pytest.mark.parametrize(
"line,title,input,expected",
read_fixture_file(FIXTURE_PATH.joinpath("disable_code_block.md")),
)
def test_disable_code_block(line, title, input, expected):
md = MarkdownIt().enable("table").disable("code")
text = md.render(input)
print(text.rstrip())
assert text.rstrip() == expected.rstrip()
@pytest.mark.parametrize(
"line,title,input,expected",
read_fixture_file(FIXTURE_PATH.joinpath("issue-fixes.md")),
)
def test_issue_fixes(line, title, input, expected):
md = MarkdownIt()
text = md.render(input)
print(text)
assert text.rstrip() == expected.rstrip()
|