1
|
|
|
from unittest import TestCase |
2
|
|
|
|
3
|
|
|
from panflute import convert_text |
4
|
|
|
|
5
|
|
|
import pandoc_latex_absolute_image |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class AbsoluteImageTest(TestCase): |
9
|
|
|
def verify_conversion( |
10
|
|
|
self, |
11
|
|
|
text, |
12
|
|
|
expected, |
13
|
|
|
transform, |
14
|
|
|
input_format="markdown", |
15
|
|
|
output_format="latex", |
16
|
|
|
standalone=False, # noqa: FBT002 |
17
|
|
|
) -> None: |
18
|
|
|
""" |
19
|
|
|
Verify the conversion. |
20
|
|
|
|
21
|
|
|
Parameters |
22
|
|
|
---------- |
23
|
|
|
text |
24
|
|
|
input text |
25
|
|
|
expected |
26
|
|
|
expected text |
27
|
|
|
transform |
28
|
|
|
filter function |
29
|
|
|
input_format |
30
|
|
|
input format |
31
|
|
|
output_format |
32
|
|
|
output format |
33
|
|
|
standalone |
34
|
|
|
is the output format standalone ? |
35
|
|
|
""" |
36
|
|
|
doc = convert_text(text, input_format=input_format, standalone=True) |
37
|
|
|
doc.format = output_format |
38
|
|
|
doc = transform(doc) |
39
|
|
|
converted = convert_text( |
40
|
|
|
doc.content, |
41
|
|
|
input_format="panflute", |
42
|
|
|
output_format=output_format, |
43
|
|
|
extra_args=["--wrap=none"], |
44
|
|
|
standalone=standalone, |
45
|
|
|
) |
46
|
|
|
print("-----------------------------------") |
47
|
|
|
print(converted) |
48
|
|
|
print() |
49
|
|
|
print(expected) |
50
|
|
|
self.assertEqual(converted.strip(), expected.strip()) # noqa: PT009 |
51
|
|
|
|
52
|
|
|
def test_image(self): |
53
|
|
|
self.verify_conversion( |
54
|
|
|
""" |
55
|
|
|
--- |
56
|
|
|
pandoc-latex-absolute-image: |
57
|
|
|
- classes: [left] |
58
|
|
|
image: Tux.pdf |
59
|
|
|
x-coord: 1cm |
60
|
|
|
y-coord: 1cm |
61
|
|
|
width: 1cm |
62
|
|
|
- classes: [reset] |
63
|
|
|
reset: true |
64
|
|
|
--- |
65
|
|
|
|
66
|
|
|
::: left |
67
|
|
|
Image at left position |
68
|
|
|
::: |
69
|
|
|
|
70
|
|
|
\\newpage |
71
|
|
|
|
72
|
|
|
::: reset |
73
|
|
|
No image |
74
|
|
|
::: |
75
|
|
|
""", |
76
|
|
|
""" |
77
|
|
|
\\renewcommand\\PandocLaTeXAbsoluteImage{% |
78
|
|
|
\\ifodd\\value{page}% |
79
|
|
|
\\begin{tikzpicture}[ |
80
|
|
|
overlay, % Do our drawing on an overlay instead of inline |
81
|
|
|
remember picture, % Allow us to share coordinates with other drawings |
82
|
|
|
shift=(current page.north west), % Set the top (north) left (west) as the origin |
83
|
|
|
yscale=-1, % Switch the y-axis to increase down the page |
84
|
|
|
inner sep=0, % Remove inner separator |
85
|
|
|
] |
86
|
|
|
\\node[] at (1cm, 1cm) |
87
|
|
|
{\\includegraphics[width=1cm]{Tux.pdf}}; |
88
|
|
|
\\end{tikzpicture} |
89
|
|
|
\\else |
90
|
|
|
\\begin{tikzpicture}[ |
91
|
|
|
overlay, % Do our drawing on an overlay instead of inline |
92
|
|
|
remember picture, % Allow us to share coordinates with other drawings |
93
|
|
|
shift=(current page.north west), % Set the top (north) left (west) as the origin |
94
|
|
|
yscale=-1, % Switch the y-axis to increase down the page |
95
|
|
|
inner sep=0, % Remove inner separator |
96
|
|
|
] |
97
|
|
|
\\node[] at (1cm, 1cm) |
98
|
|
|
{\\includegraphics[width=1cm]{Tux.pdf}}; |
99
|
|
|
\\end{tikzpicture} |
100
|
|
|
\\fi |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
Image at left position |
104
|
|
|
|
105
|
|
|
\\newpage |
106
|
|
|
|
107
|
|
|
\\renewcommand\\PandocLaTeXAbsoluteImage{% |
108
|
|
|
\\ifodd\\value{page}% |
109
|
|
|
|
110
|
|
|
\\else |
111
|
|
|
|
112
|
|
|
\\fi |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
No image |
116
|
|
|
""", |
117
|
|
|
pandoc_latex_absolute_image.main, |
118
|
|
|
) |
119
|
|
|
|