markdown_convert 1.2.17__py3-none-any.whl → 1.2.19__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- markdown_convert/default.css +30 -186
- markdown_convert/modules/constants.py +2 -2
- markdown_convert/modules/convert.py +87 -49
- {markdown_convert-1.2.17.dist-info → markdown_convert-1.2.19.dist-info}/METADATA +1 -1
- {markdown_convert-1.2.17.dist-info → markdown_convert-1.2.19.dist-info}/RECORD +8 -8
- {markdown_convert-1.2.17.dist-info → markdown_convert-1.2.19.dist-info}/WHEEL +0 -0
- {markdown_convert-1.2.17.dist-info → markdown_convert-1.2.19.dist-info}/entry_points.txt +0 -0
- {markdown_convert-1.2.17.dist-info → markdown_convert-1.2.19.dist-info}/licenses/LICENSE +0 -0
markdown_convert/default.css
CHANGED
|
@@ -1,171 +1,7 @@
|
|
|
1
|
-
/* Font imports */
|
|
2
|
-
/* -- Cantarell Web */
|
|
3
|
-
@font-face {
|
|
4
|
-
font-family: "Cantarell Web";
|
|
5
|
-
font-style: italic;
|
|
6
|
-
font-weight: 400;
|
|
7
|
-
font-display: swap;
|
|
8
|
-
src: url(https://fonts.gstatic.com/s/cantarell/v17/B50LF7ZDq37KMUvlO015iZJnNKuiLA.woff2) format("woff2");
|
|
9
|
-
unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF,
|
|
10
|
-
U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
@font-face {
|
|
14
|
-
font-family: "Cantarell Web";
|
|
15
|
-
font-style: italic;
|
|
16
|
-
font-weight: 400;
|
|
17
|
-
font-display: swap;
|
|
18
|
-
src: url(https://fonts.gstatic.com/s/cantarell/v17/B50LF7ZDq37KMUvlO015iZJpNKs.woff2) format("woff2");
|
|
19
|
-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
|
|
20
|
-
U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191,
|
|
21
|
-
U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
@font-face {
|
|
25
|
-
font-family: "Cantarell Web";
|
|
26
|
-
font-style: italic;
|
|
27
|
-
font-weight: 700;
|
|
28
|
-
font-display: swap;
|
|
29
|
-
src: url(https://fonts.gstatic.com/s/cantarell/v17/B50WF7ZDq37KMUvlO015iZrSEb6TDYsmgQ.woff2) format("woff2");
|
|
30
|
-
unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF,
|
|
31
|
-
U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
@font-face {
|
|
35
|
-
font-family: "Cantarell Web";
|
|
36
|
-
font-style: italic;
|
|
37
|
-
font-weight: 700;
|
|
38
|
-
font-display: swap;
|
|
39
|
-
src: url(https://fonts.gstatic.com/s/cantarell/v17/B50WF7ZDq37KMUvlO015iZrSEb6dDYs.woff2) format("woff2");
|
|
40
|
-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
|
|
41
|
-
U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191,
|
|
42
|
-
U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@font-face {
|
|
46
|
-
font-family: "Cantarell Web";
|
|
47
|
-
font-style: normal;
|
|
48
|
-
font-weight: 400;
|
|
49
|
-
font-display: swap;
|
|
50
|
-
src: url(https://fonts.gstatic.com/s/cantarell/v17/B50NF7ZDq37KMUvlO015gqJrLK8.woff2) format("woff2");
|
|
51
|
-
unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF,
|
|
52
|
-
U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
@font-face {
|
|
56
|
-
font-family: "Cantarell Web";
|
|
57
|
-
font-style: normal;
|
|
58
|
-
font-weight: 400;
|
|
59
|
-
font-display: swap;
|
|
60
|
-
src: url(https://fonts.gstatic.com/s/cantarell/v17/B50NF7ZDq37KMUvlO015jKJr.woff2) format("woff2");
|
|
61
|
-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
|
|
62
|
-
U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191,
|
|
63
|
-
U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
@font-face {
|
|
67
|
-
font-family: "Cantarell Web";
|
|
68
|
-
font-style: normal;
|
|
69
|
-
font-weight: 700;
|
|
70
|
-
font-display: swap;
|
|
71
|
-
src: url(https://fonts.gstatic.com/s/cantarell/v17/B50IF7ZDq37KMUvlO01xN4d-HY6fFY8.woff2) format("woff2");
|
|
72
|
-
unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF,
|
|
73
|
-
U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
@font-face {
|
|
77
|
-
font-family: "Cantarell Web";
|
|
78
|
-
font-style: normal;
|
|
79
|
-
font-weight: 700;
|
|
80
|
-
font-display: swap;
|
|
81
|
-
src: url(https://fonts.gstatic.com/s/cantarell/v17/B50IF7ZDq37KMUvlO01xN4d-E46f.woff2) format("woff2");
|
|
82
|
-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
|
|
83
|
-
U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191,
|
|
84
|
-
U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/* -- JetBrains Mono */
|
|
88
|
-
@font-face {
|
|
89
|
-
font-family: "JetBrains Mono";
|
|
90
|
-
src: url("https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff2/JetBrainsMono-Bold-Italic.woff2") format("woff2"),
|
|
91
|
-
url("https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff/JetBrainsMono-Bold-Italic.woff") format("woff");
|
|
92
|
-
font-weight: 700;
|
|
93
|
-
font-style: italic;
|
|
94
|
-
font-display: swap;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
@font-face {
|
|
98
|
-
font-family: "JetBrains Mono";
|
|
99
|
-
src: url("https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff2/JetBrainsMono-Bold.woff2") format("woff2"),
|
|
100
|
-
url("https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff/JetBrainsMono-Bold.woff") format("woff");
|
|
101
|
-
font-weight: 700;
|
|
102
|
-
font-style: normal;
|
|
103
|
-
font-display: swap;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
@font-face {
|
|
107
|
-
font-family: "JetBrains Mono";
|
|
108
|
-
src: url("https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff2/JetBrainsMono-ExtraBold-Italic.woff2") format("woff2"),
|
|
109
|
-
url("https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff/JetBrainsMono-ExtraBold-Italic.woff") format("woff");
|
|
110
|
-
font-weight: 800;
|
|
111
|
-
font-style: italic;
|
|
112
|
-
font-display: swap;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
@font-face {
|
|
116
|
-
font-family: "JetBrains Mono";
|
|
117
|
-
src: url("https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff2/JetBrainsMono-ExtraBold.woff2") format("woff2"),
|
|
118
|
-
url("https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff/JetBrainsMono-ExtraBold.woff") format("woff");
|
|
119
|
-
font-weight: 800;
|
|
120
|
-
font-style: normal;
|
|
121
|
-
font-display: swap;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
@font-face {
|
|
125
|
-
font-family: "JetBrains Mono";
|
|
126
|
-
src: url("https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff2/JetBrainsMono-Italic.woff2") format("woff2"),
|
|
127
|
-
url("https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff/JetBrainsMono-Italic.woff") format("woff");
|
|
128
|
-
font-weight: 400;
|
|
129
|
-
font-style: italic;
|
|
130
|
-
font-display: swap;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
@font-face {
|
|
134
|
-
font-family: "JetBrains Mono";
|
|
135
|
-
src: url("https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff2/JetBrainsMono-Medium-Italic.woff2") format("woff2"),
|
|
136
|
-
url("https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff/JetBrainsMono-Medium-Italic.woff") format("woff");
|
|
137
|
-
font-weight: 500;
|
|
138
|
-
font-style: italic;
|
|
139
|
-
font-display: swap;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
@font-face {
|
|
143
|
-
font-family: "JetBrains Mono";
|
|
144
|
-
src: url("https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff2/JetBrainsMono-Medium.woff2") format("woff2"),
|
|
145
|
-
url("https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff/JetBrainsMono-Medium.woff") format("woff");
|
|
146
|
-
font-weight: 500;
|
|
147
|
-
font-style: normal;
|
|
148
|
-
font-display: swap;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
@font-face {
|
|
152
|
-
font-family: "JetBrains Mono";
|
|
153
|
-
src: url("https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff2/JetBrainsMono-Regular.woff2") format("woff2"),
|
|
154
|
-
url("https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff/JetBrainsMono-Regular.woff") format("woff");
|
|
155
|
-
font-weight: 400;
|
|
156
|
-
font-style: normal;
|
|
157
|
-
font-display: swap;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/* Print media css */
|
|
161
|
-
@page {
|
|
162
|
-
size: A4;
|
|
163
|
-
margin: 2.54cm;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
1
|
:root {
|
|
167
2
|
/* -- Standard margins */
|
|
168
|
-
--top-margin:
|
|
3
|
+
--top-margin: 0.5em;
|
|
4
|
+
--bottom-margin: 0.5em;
|
|
169
5
|
--left-margin: 1.5em;
|
|
170
6
|
|
|
171
7
|
/* -- Small margins */
|
|
@@ -173,18 +9,18 @@
|
|
|
173
9
|
|
|
174
10
|
/* -- Big margins */
|
|
175
11
|
--left-margin-big: 2em;
|
|
176
|
-
--bottom-margin-big: 0.5em;
|
|
177
12
|
}
|
|
178
13
|
|
|
179
14
|
/* Document */
|
|
180
15
|
html {
|
|
181
|
-
font-size:
|
|
16
|
+
font-size: 12px;
|
|
182
17
|
}
|
|
183
18
|
|
|
184
19
|
body {
|
|
185
20
|
margin: 0;
|
|
186
21
|
padding: 0;
|
|
187
|
-
font-family: "
|
|
22
|
+
font-family: "Segoe UI", "Ubuntu", "DejaVu Sans", "Liberation Sans", "Arial",
|
|
23
|
+
"sans-serif";
|
|
188
24
|
color: #333;
|
|
189
25
|
}
|
|
190
26
|
|
|
@@ -195,12 +31,12 @@ h3,
|
|
|
195
31
|
h4,
|
|
196
32
|
h5 {
|
|
197
33
|
color: #333;
|
|
198
|
-
font-weight:
|
|
34
|
+
font-weight: 600;
|
|
199
35
|
}
|
|
200
36
|
|
|
201
37
|
h1 {
|
|
202
38
|
margin-top: 0;
|
|
203
|
-
margin-bottom: var(--bottom-margin
|
|
39
|
+
margin-bottom: var(--bottom-margin);
|
|
204
40
|
}
|
|
205
41
|
|
|
206
42
|
h2,
|
|
@@ -213,27 +49,27 @@ p {
|
|
|
213
49
|
}
|
|
214
50
|
|
|
215
51
|
h1 {
|
|
216
|
-
font-size:
|
|
52
|
+
font-size: 2.4rem;
|
|
217
53
|
}
|
|
218
54
|
|
|
219
55
|
h2 {
|
|
220
|
-
font-size:
|
|
56
|
+
font-size: 2rem;
|
|
221
57
|
}
|
|
222
58
|
|
|
223
59
|
h3 {
|
|
224
|
-
font-size:
|
|
60
|
+
font-size: 1.6rem;
|
|
225
61
|
}
|
|
226
62
|
|
|
227
63
|
h4 {
|
|
228
|
-
font-size: 1.
|
|
64
|
+
font-size: 1.4rem;
|
|
229
65
|
}
|
|
230
66
|
|
|
231
67
|
h5 {
|
|
232
|
-
font-size: 1.
|
|
68
|
+
font-size: 1.2rem;
|
|
233
69
|
}
|
|
234
70
|
|
|
235
71
|
p {
|
|
236
|
-
font-size:
|
|
72
|
+
font-size: 1rem;
|
|
237
73
|
}
|
|
238
74
|
|
|
239
75
|
/* Links */
|
|
@@ -246,7 +82,7 @@ a {
|
|
|
246
82
|
/* Lists */
|
|
247
83
|
ul,
|
|
248
84
|
ol {
|
|
249
|
-
font-size:
|
|
85
|
+
font-size: 1rem;
|
|
250
86
|
padding: 0;
|
|
251
87
|
margin-top: var(--top-margin);
|
|
252
88
|
margin-right: 0;
|
|
@@ -262,7 +98,7 @@ ul ul {
|
|
|
262
98
|
}
|
|
263
99
|
|
|
264
100
|
li {
|
|
265
|
-
margin-top:
|
|
101
|
+
margin-top: var(--top-margin);
|
|
266
102
|
}
|
|
267
103
|
|
|
268
104
|
/* Code blocks */
|
|
@@ -272,7 +108,8 @@ pre {
|
|
|
272
108
|
}
|
|
273
109
|
|
|
274
110
|
code {
|
|
275
|
-
font-family: "JetBrains Mono", "
|
|
111
|
+
font-family: "JetBrains Mono", "Consolas", "Ubuntu Mono", "DejaVu Sans Mono",
|
|
112
|
+
"Liberation Mono", "Courier New", monospace;
|
|
276
113
|
font-size: 1rem;
|
|
277
114
|
background-color: #eee;
|
|
278
115
|
padding-left: 0.4em;
|
|
@@ -294,13 +131,12 @@ h5 code {
|
|
|
294
131
|
blockquote {
|
|
295
132
|
margin-top: var(--top-margin);
|
|
296
133
|
margin-left: var(--left-margin);
|
|
297
|
-
max-width: 30em;
|
|
298
134
|
border-left: 4px solid #ccc;
|
|
299
135
|
padding-left: 0.5em;
|
|
300
136
|
color: #666;
|
|
301
137
|
}
|
|
302
138
|
|
|
303
|
-
blockquote>blockquote {
|
|
139
|
+
blockquote > blockquote {
|
|
304
140
|
margin-left: var(--left-margin-small);
|
|
305
141
|
}
|
|
306
142
|
|
|
@@ -312,7 +148,7 @@ img {
|
|
|
312
148
|
}
|
|
313
149
|
|
|
314
150
|
/* -- Figure footer */
|
|
315
|
-
p>img+em {
|
|
151
|
+
p > img + em {
|
|
316
152
|
text-align: center;
|
|
317
153
|
font-size: 1rem;
|
|
318
154
|
font-style: italic;
|
|
@@ -324,6 +160,7 @@ p>img+em {
|
|
|
324
160
|
/* Tables */
|
|
325
161
|
table {
|
|
326
162
|
font-size: 1rem;
|
|
163
|
+
font-family: inherit;
|
|
327
164
|
border-collapse: collapse;
|
|
328
165
|
margin-top: var(--top-margin);
|
|
329
166
|
text-align: left;
|
|
@@ -355,11 +192,13 @@ col {
|
|
|
355
192
|
page-break-after: always;
|
|
356
193
|
}
|
|
357
194
|
|
|
358
|
-
.pagebreak
|
|
195
|
+
.pagebreak + * {
|
|
359
196
|
margin-top: 0;
|
|
360
197
|
}
|
|
361
198
|
|
|
362
|
-
|
|
199
|
+
section,
|
|
200
|
+
ol,
|
|
201
|
+
ul,
|
|
363
202
|
table,
|
|
364
203
|
blockquote,
|
|
365
204
|
code,
|
|
@@ -376,4 +215,9 @@ h5 {
|
|
|
376
215
|
math[display="block"] {
|
|
377
216
|
margin-top: 1em;
|
|
378
217
|
margin-bottom: 1em;
|
|
379
|
-
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
math {
|
|
221
|
+
text-rendering: optimizeLegibility;
|
|
222
|
+
font-family: "Latin Modern Math", "Cambria Math", serif;
|
|
223
|
+
}
|
|
@@ -4,6 +4,7 @@ Author: @julynx
|
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
6
|
import os
|
|
7
|
+
import re
|
|
7
8
|
import time
|
|
8
9
|
from datetime import datetime
|
|
9
10
|
from pathlib import Path
|
|
@@ -11,60 +12,92 @@ from pathlib import Path
|
|
|
11
12
|
import markdown2
|
|
12
13
|
from playwright.sync_api import sync_playwright
|
|
13
14
|
|
|
14
|
-
from .resources import get_css_path, get_code_css_path, get_output_path
|
|
15
|
-
from .utils import drop_duplicates
|
|
16
15
|
from .constants import MD_EXTENSIONS
|
|
16
|
+
from .resources import get_code_css_path, get_css_path, get_output_path
|
|
17
|
+
from .utils import drop_duplicates
|
|
17
18
|
|
|
18
19
|
|
|
19
|
-
def _generate_pdf_with_playwright(
|
|
20
|
+
def _generate_pdf_with_playwright(
|
|
21
|
+
html_content,
|
|
22
|
+
output_path,
|
|
23
|
+
*,
|
|
24
|
+
css_content=None,
|
|
25
|
+
base_dir=None,
|
|
26
|
+
dump_html=False,
|
|
27
|
+
):
|
|
20
28
|
"""
|
|
21
29
|
Generate a PDF from HTML content using Playwright.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
html_content (str): HTML content to convert.
|
|
33
|
+
output_path (str): Path to save the PDF file.
|
|
34
|
+
css_content (str, optional): CSS content to inject.
|
|
35
|
+
base_dir (Path, optional): Base directory for resolving relative paths in HTML.
|
|
36
|
+
dump_html (bool, optional): Whether to dump the HTML content to a file.
|
|
22
37
|
"""
|
|
23
38
|
with sync_playwright() as p:
|
|
24
39
|
browser = p.chromium.launch(headless=True)
|
|
25
40
|
page = browser.new_page()
|
|
26
|
-
page.set_content(html_content)
|
|
27
|
-
# Wait for any potential resources to load
|
|
28
|
-
page.wait_for_load_state("networkidle")
|
|
29
|
-
|
|
30
|
-
pdf_params = {
|
|
31
|
-
"format": "A4",
|
|
32
|
-
"print_background": True,
|
|
33
|
-
"margin": {
|
|
34
|
-
"top": "20mm",
|
|
35
|
-
"bottom": "20mm",
|
|
36
|
-
"left": "20mm",
|
|
37
|
-
"right": "20mm",
|
|
38
|
-
},
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if output_path:
|
|
42
|
-
page.pdf(path=output_path, **pdf_params)
|
|
43
|
-
browser.close()
|
|
44
|
-
return None
|
|
45
41
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
# Handle loading based on presence of base_dir
|
|
43
|
+
temp_html = None
|
|
44
|
+
try:
|
|
45
|
+
if base_dir:
|
|
46
|
+
temp_html = base_dir / f".temp_{os.getpid()}.html"
|
|
47
|
+
temp_html.write_text(html_content, encoding="utf-8")
|
|
48
|
+
page.goto(temp_html.as_uri(), wait_until="networkidle")
|
|
49
|
+
else:
|
|
50
|
+
page.set_content(html_content, wait_until="networkidle")
|
|
51
|
+
|
|
52
|
+
if css_content:
|
|
53
|
+
page.add_style_tag(content=css_content)
|
|
54
|
+
|
|
55
|
+
pdf_params = {
|
|
56
|
+
"format": "A4",
|
|
57
|
+
"print_background": True,
|
|
58
|
+
"margin": {"top": "20mm", "bottom": "20mm", "left": "20mm", "right": "20mm"},
|
|
59
|
+
"path": output_path,
|
|
60
|
+
} # Playwright ignores None paths
|
|
61
|
+
|
|
62
|
+
pdf_bytes = page.pdf(**pdf_params)
|
|
63
|
+
return None if output_path else pdf_bytes
|
|
64
|
+
|
|
65
|
+
finally:
|
|
66
|
+
browser.close()
|
|
67
|
+
if temp_html and temp_html.exists() and not dump_html:
|
|
68
|
+
temp_html.unlink()
|
|
49
69
|
|
|
50
70
|
|
|
51
|
-
def
|
|
71
|
+
def _get_css_content(css_sources):
|
|
52
72
|
"""
|
|
53
|
-
|
|
73
|
+
Get the CSS content from a list of CSS file paths.
|
|
54
74
|
|
|
55
75
|
Args:
|
|
56
|
-
html (str): HTML content.
|
|
57
76
|
css_sources (list): List of CSS file paths.
|
|
58
|
-
|
|
59
77
|
Returns:
|
|
60
|
-
|
|
78
|
+
str: Combined CSS content.
|
|
61
79
|
"""
|
|
62
80
|
css_buffer = ""
|
|
63
81
|
for css_file in css_sources:
|
|
64
82
|
css_buffer += Path(css_file).read_text(encoding="utf-8") + "\n"
|
|
83
|
+
return css_buffer
|
|
65
84
|
|
|
66
|
-
|
|
67
|
-
|
|
85
|
+
|
|
86
|
+
def _create_sections(html):
|
|
87
|
+
"""
|
|
88
|
+
Creates h2 sections, from the first h2 to the next h2, wrapping them in <section> tags
|
|
89
|
+
using regular expressions.
|
|
90
|
+
Args:
|
|
91
|
+
html (str): HTML content.
|
|
92
|
+
Returns:
|
|
93
|
+
HTML content with sections wrapped in <section> tags.
|
|
94
|
+
"""
|
|
95
|
+
pattern = re.compile(r"(<h2.*?>.*?</h2>)(.*?)(?=(<h2.*?>|$))", re.DOTALL)
|
|
96
|
+
|
|
97
|
+
def wrap_section(match):
|
|
98
|
+
return f"<section>\n{match.group(1)}\n{match.group(2)}\n</section>\n"
|
|
99
|
+
|
|
100
|
+
return pattern.sub(wrap_section, html)
|
|
68
101
|
|
|
69
102
|
|
|
70
103
|
def convert(
|
|
@@ -100,13 +133,15 @@ def convert(
|
|
|
100
133
|
|
|
101
134
|
try:
|
|
102
135
|
html = markdown2.markdown_path(md_path, extras=MD_EXTENSIONS)
|
|
103
|
-
html =
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
136
|
+
html = _create_sections(html)
|
|
137
|
+
|
|
138
|
+
_generate_pdf_with_playwright(
|
|
139
|
+
html,
|
|
140
|
+
output_path,
|
|
141
|
+
css_content=_get_css_content(css_sources),
|
|
142
|
+
base_dir=Path(md_path).resolve().parent,
|
|
143
|
+
dump_html=dump_html,
|
|
144
|
+
)
|
|
110
145
|
|
|
111
146
|
except Exception as exc:
|
|
112
147
|
raise RuntimeError(exc) from exc
|
|
@@ -129,7 +164,11 @@ def live_convert(md_path, css_path=None, output_path=None, *, extend_default_css
|
|
|
129
164
|
output_path = get_output_path(md_path, None)
|
|
130
165
|
|
|
131
166
|
live_converter = LiveConverter(
|
|
132
|
-
md_path,
|
|
167
|
+
md_path,
|
|
168
|
+
css_path,
|
|
169
|
+
output_path,
|
|
170
|
+
extend_default_css=extend_default_css,
|
|
171
|
+
loud=True,
|
|
133
172
|
)
|
|
134
173
|
live_converter.observe()
|
|
135
174
|
|
|
@@ -159,9 +198,13 @@ def convert_text(md_text, css_text=None, *, extend_default_css=True):
|
|
|
159
198
|
|
|
160
199
|
try:
|
|
161
200
|
html = markdown2.markdown(md_text, extras=MD_EXTENSIONS)
|
|
162
|
-
html =
|
|
201
|
+
html = _create_sections(html)
|
|
163
202
|
|
|
164
|
-
return _generate_pdf_with_playwright(
|
|
203
|
+
return _generate_pdf_with_playwright(
|
|
204
|
+
html,
|
|
205
|
+
None,
|
|
206
|
+
css_content=_get_css_content(css_sources),
|
|
207
|
+
)
|
|
165
208
|
|
|
166
209
|
except Exception as exc:
|
|
167
210
|
raise RuntimeError(exc) from exc
|
|
@@ -172,9 +215,7 @@ class LiveConverter:
|
|
|
172
215
|
Class to convert a markdown file to a pdf file and watch for changes.
|
|
173
216
|
"""
|
|
174
217
|
|
|
175
|
-
def __init__(
|
|
176
|
-
self, md_path, css_path, output_path, *, extend_default_css=True, loud=False
|
|
177
|
-
):
|
|
218
|
+
def __init__(self, md_path, css_path, output_path, *, extend_default_css=True, loud=False):
|
|
178
219
|
"""
|
|
179
220
|
Initialize the LiveConverter class.
|
|
180
221
|
|
|
@@ -234,10 +275,7 @@ class LiveConverter:
|
|
|
234
275
|
md_modified = self.get_last_modified_date(self.md_path)
|
|
235
276
|
css_modified = self.get_last_modified_date(self.css_path)
|
|
236
277
|
|
|
237
|
-
if
|
|
238
|
-
md_modified != self.md_last_modified
|
|
239
|
-
or css_modified != self.css_last_modified
|
|
240
|
-
):
|
|
278
|
+
if md_modified != self.md_last_modified or css_modified != self.css_last_modified:
|
|
241
279
|
|
|
242
280
|
self.write_pdf()
|
|
243
281
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: markdown_convert
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.19
|
|
4
4
|
Summary: Convert Markdown files to PDF from your command line.
|
|
5
5
|
Project-URL: homepage, https://github.com/Julynx/markdown_convert
|
|
6
6
|
Author-email: Julio Cabria <juliocabria@tutanota.com>
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
markdown_convert/__main__.py,sha256=zKgFcnxlXTRsR6AYhTdGEvQea2TVyLYeIxJSMksCMR0,2767
|
|
2
2
|
markdown_convert/code.css,sha256=Wt4FqFqJcpT-jwY3GN-o4ZRCCXU8DQj-9lqKdGiuoyw,4935
|
|
3
|
-
markdown_convert/default.css,sha256=
|
|
3
|
+
markdown_convert/default.css,sha256=sTIJmfRWOe8SVwlhzw9CSXD44TUtgfjKCHJjf6u2O8U,2877
|
|
4
4
|
markdown_convert/modules/__init__.py,sha256=PFPgiQhMXgyfjD8BkfLC_X8AR1jz-dCxfif2qmNofJs,65
|
|
5
|
-
markdown_convert/modules/constants.py,sha256=
|
|
6
|
-
markdown_convert/modules/convert.py,sha256=
|
|
5
|
+
markdown_convert/modules/constants.py,sha256=Yd7o0OGwliYcmBGrwoeckagc9E8p1l-zXQx_P4CuiK4,448
|
|
6
|
+
markdown_convert/modules/convert.py,sha256=cU-wATfsM5Y8WFklkw7NIa2KSrMpc50aZecO4rewua8,8346
|
|
7
7
|
markdown_convert/modules/resources.py,sha256=aMDbM7Oab8A3nRN1tc1uNkmz8JfUdLJR6rF3ZR0IElo,2384
|
|
8
8
|
markdown_convert/modules/utils.py,sha256=NX0WegM8e8MPKNNmweTujAWO8ZghdB8LSGDx20K2E44,655
|
|
9
9
|
markdown_convert/modules/validate.py,sha256=cerfQ5Qt8gBQbh-NZ57zLmDfg-Vnyo0zsEFb8RUzVCQ,1487
|
|
10
|
-
markdown_convert-1.2.
|
|
11
|
-
markdown_convert-1.2.
|
|
12
|
-
markdown_convert-1.2.
|
|
13
|
-
markdown_convert-1.2.
|
|
14
|
-
markdown_convert-1.2.
|
|
10
|
+
markdown_convert-1.2.19.dist-info/METADATA,sha256=1eUFWi99qEWcCrGq4Z_Wa4S67PXa9prHTHjGB7xPTus,2935
|
|
11
|
+
markdown_convert-1.2.19.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
12
|
+
markdown_convert-1.2.19.dist-info/entry_points.txt,sha256=RCmzC7C0sX-SpzIP2Cr34rhg3lMd7BRx-exaZPfK8bU,68
|
|
13
|
+
markdown_convert-1.2.19.dist-info/licenses/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
|
|
14
|
+
markdown_convert-1.2.19.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|