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
|
import io
from os import path
import pytest
from nikola.plugins.compile.markdown import CompileMarkdown
from .helper import FakeSite
@pytest.mark.parametrize(
"input_str, expected_output",
[
pytest.param("", "", id="empty"),
pytest.param(
"[podcast]https://archive.org/download/Rebeldes_Stereotipos/rs20120609_1.mp3[/podcast]",
'<p><audio controls=""><source src="https://archive.org/download/Rebeldes_Stereotipos/rs20120609_1.mp3" type="audio/mpeg"></source></audio></p>',
id="mdx podcast",
),
pytest.param(
"~~striked out text~~",
"<p><del>striked out text</del></p>",
id="strikethrough",
),
pytest.param(
"""\
#!python
from this
""",
"""\
<table class="codehilitetable"><tr><td class="linenos">\
<div class="linenodiv"><pre><span class="normal">1</span></pre></div>\
</td><td class="code"><pre class="code literal-block"><span></span>\
<code><span class="kn">from</span> <span class="nn">this</span>
</code></pre>
</td></tr></table>
""",
id="hilite",
),
],
)
def test_compiling_markdown(
compiler, input_path, output_path, input_str, expected_output
):
output = markdown_compile(compiler, input_path, output_path, input_str)
assert output.strip() == expected_output.strip()
@pytest.fixture(scope="module")
def site():
return FakeSite()
@pytest.fixture(scope="module")
def compiler(site):
compiler = CompileMarkdown()
compiler.set_site(site)
return compiler
@pytest.fixture
def input_path(tmpdir):
return path.join(str(tmpdir), "input.markdown")
@pytest.fixture
def output_path(tmpdir):
return path.join(str(tmpdir), "output.html")
def markdown_compile(compiler, input_path, output_path, text):
with io.open(input_path, "w+", encoding="utf8") as input_file:
input_file.write(text)
compiler.compile(input_path, output_path, lang="en")
with io.open(output_path, "r", encoding="utf8") as output_path:
return output_path.read()
|