test_admonition.AdmonitionTest.test_beamer_notes()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 20
rs 9.9
c 0
b 0
f 0
cc 1
nop 1
1
from unittest import TestCase
2
3
from panflute import convert_text, Para, Image, Figure
4
5
import pandoc_latex_admonition
6
7
8
class AdmonitionTest(TestCase):
9
    @classmethod
10
    def conversion(cls, markdown, fmt="markdown"):
11
        doc = convert_text(markdown, standalone=True)
12
        doc.format = fmt
13
        pandoc_latex_admonition.main(doc)
14
        return doc
15
16
    def test_codeblock_classes(self):
17
        doc = AdmonitionTest.conversion(
18
            """
19
---
20
pandoc-latex-admonition:
21
  - classes: ['class1', 'class2']
22
    color: red
23
    position: right
24
    linewidth: 5
25
    innermargin: -8
26
    margin: 10
27
---
28
~~~{.class1 .class2}
29
~~~
30
            """,
31
            "latex",
32
        )
33
        text = convert_text(
34
            doc,
35
            input_format="panflute",
36
            output_format="latex",
37
            extra_args=["--wrap=none"],
38
        )
39
        self.assertIn("\\begin{env-", text)
40
        self.assertIn(
41
            r"\tcolorbox[blanker,breakable,right=-8pt,borderline east={5pt}{10pt}{red}]",
42
            doc.get_metadata()["header-includes"][-1],
43
        )
44
45
    def test_codeblock_attributes(self):
46
        doc = AdmonitionTest.conversion(
47
            """
48
::: {latex-admonition-color=xyz latex-admonition-linewidth=xyz latex-admonition-margin=xyz latex-admonition-innermargin=xyz latex-admonition-localfootnotes=true} :::
49
:::::::::
50
            """,
51
            "latex",
52
        )
53
        text = convert_text(
54
            doc,
55
            input_format="panflute",
56
            output_format="latex",
57
            extra_args=["--wrap=none"],
58
        )
59
        self.assertIn("\\begin{env-", text)
60
        self.assertIn("\\end{env-", text)
61
        self.assertIn(
62
            r"\tcolorbox[blanker,breakable,left=5pt,borderline west={2pt}{-4pt}{black}]",
63
            doc.get_metadata()["header-includes"][-1],
64
        )
65
66
    def test_latex_images(self):
67
        doc = AdmonitionTest.conversion(
68
            """\
69
::: {latex-admonition-color=black} :::
70
71
![Title]()
72
73
Hello
74
:::::::::
75
            """.strip(),
76
            "latex",
77
        )
78
        text = convert_text(
79
            doc,
80
            input_format="panflute",
81
            output_format="latex",
82
            extra_args=["--wrap=none"],
83
        )
84
85
        self.assertIn("\\begin{env-", text)
86
        self.assertIn("\\end{env-", text)
87
        self.assertIn(
88
            r"\tcolorbox[blanker,breakable,left=5pt,borderline west={2pt}{-4pt}{black}]",
89
            doc.get_metadata()["header-includes"][-1],
90
        )
91
        self.assertIsInstance(doc.content[-1], Figure)
92
93
    def test_beamer_notes(self):
94
        doc = AdmonitionTest.conversion(
95
            """
96
::: {latex-admonition-color=black} :::
97
98
This a text[^note]
99
100
[^note]: This is a *note*
101
102
:::
103
            """,
104
            "beamer",
105
        )
106
        text = convert_text(
107
            doc,
108
            input_format="panflute",
109
            output_format="beamer",
110
            extra_args=["--wrap=none"],
111
        )
112
        self.assertIn("This a text\\footnote<.->[frame]{This is a \\emph{note}}", text)
113