markdown_convert 1.2.22__tar.gz → 1.2.23__tar.gz
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-1.2.22 → markdown_convert-1.2.23}/PKG-INFO +1 -1
- {markdown_convert-1.2.22 → markdown_convert-1.2.23}/markdown_convert/__main__.py +7 -7
- {markdown_convert-1.2.22 → markdown_convert-1.2.23}/markdown_convert/modules/constants.py +1 -1
- {markdown_convert-1.2.22 → markdown_convert-1.2.23}/markdown_convert/modules/convert.py +40 -22
- {markdown_convert-1.2.22 → markdown_convert-1.2.23}/markdown_convert/modules/resources.py +14 -11
- {markdown_convert-1.2.22 → markdown_convert-1.2.23}/markdown_convert/modules/validate.py +5 -5
- {markdown_convert-1.2.22 → markdown_convert-1.2.23}/pyproject.toml +7 -1
- {markdown_convert-1.2.22 → markdown_convert-1.2.23}/.gitignore +0 -0
- {markdown_convert-1.2.22 → markdown_convert-1.2.23}/LICENSE +0 -0
- {markdown_convert-1.2.22 → markdown_convert-1.2.23}/README.md +0 -0
- {markdown_convert-1.2.22 → markdown_convert-1.2.23}/markdown_convert/__init__.py +0 -0
- {markdown_convert-1.2.22 → markdown_convert-1.2.23}/markdown_convert/code.css +0 -0
- {markdown_convert-1.2.22 → markdown_convert-1.2.23}/markdown_convert/default.css +0 -0
- {markdown_convert-1.2.22 → markdown_convert-1.2.23}/markdown_convert/modules/__init__.py +0 -0
- {markdown_convert-1.2.22 → markdown_convert-1.2.23}/markdown_convert/modules/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: markdown_convert
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.23
|
|
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>
|
|
@@ -32,8 +32,8 @@ def main():
|
|
|
32
32
|
|
|
33
33
|
# Get the markdown path
|
|
34
34
|
try:
|
|
35
|
-
|
|
36
|
-
validate_markdown_path(
|
|
35
|
+
markdown_path = arg["markdown_file_path"]
|
|
36
|
+
validate_markdown_path(markdown_path)
|
|
37
37
|
except KeyError as key_err:
|
|
38
38
|
raise IndexError("Missing 'markdown_file_path' argument.") from key_err
|
|
39
39
|
except Exception as exc:
|
|
@@ -61,18 +61,18 @@ def main():
|
|
|
61
61
|
try:
|
|
62
62
|
output_path = arg["--out"]
|
|
63
63
|
validate_output_path(output_path)
|
|
64
|
-
output_path = get_output_path(
|
|
64
|
+
output_path = get_output_path(markdown_path, output_path)
|
|
65
65
|
except KeyError:
|
|
66
|
-
output_path = get_output_path(
|
|
66
|
+
output_path = get_output_path(markdown_path, None)
|
|
67
67
|
except Exception as exc:
|
|
68
68
|
raise IndexError(f"Invalid 'output_path' argument: {exc}") from exc
|
|
69
69
|
|
|
70
70
|
# Compile the markdown file
|
|
71
|
-
print(f"\nGenerating PDF file from '{
|
|
71
|
+
print(f"\nGenerating PDF file from '{markdown_path}'...\n")
|
|
72
72
|
if mode in ("once", "debug"):
|
|
73
|
-
convert(
|
|
73
|
+
convert(markdown_path, css_path, output_path, dump_html=mode == "debug")
|
|
74
74
|
else:
|
|
75
|
-
live_convert(
|
|
75
|
+
live_convert(markdown_path, css_path, output_path)
|
|
76
76
|
|
|
77
77
|
sys_exit(0)
|
|
78
78
|
|
|
@@ -14,7 +14,7 @@ OPTIONS = ("markdown_file_path", "--mode", "--css", "--out", "-h", "--help")
|
|
|
14
14
|
|
|
15
15
|
OPTIONS_MODES = ("once", "live", "debug")
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
MARKDOWN_EXTENSIONS = {
|
|
18
18
|
"fenced-code-blocks": None,
|
|
19
19
|
"header-ids": True,
|
|
20
20
|
"breaks": {"on_newline": True},
|
|
@@ -12,7 +12,7 @@ from pathlib import Path
|
|
|
12
12
|
import markdown2
|
|
13
13
|
from playwright.sync_api import sync_playwright
|
|
14
14
|
|
|
15
|
-
from .constants import
|
|
15
|
+
from .constants import MARKDOWN_EXTENSIONS
|
|
16
16
|
from .resources import get_code_css_path, get_css_path, get_output_path
|
|
17
17
|
from .utils import drop_duplicates
|
|
18
18
|
|
|
@@ -35,8 +35,8 @@ def _generate_pdf_with_playwright(
|
|
|
35
35
|
base_dir (Path, optional): Base directory for resolving relative paths in HTML.
|
|
36
36
|
dump_html (bool, optional): Whether to dump the HTML content to a file.
|
|
37
37
|
"""
|
|
38
|
-
with sync_playwright() as
|
|
39
|
-
browser =
|
|
38
|
+
with sync_playwright() as playwright:
|
|
39
|
+
browser = playwright.chromium.launch(headless=True)
|
|
40
40
|
page = browser.new_page()
|
|
41
41
|
|
|
42
42
|
# Handle loading based on presence of base_dir
|
|
@@ -55,7 +55,12 @@ def _generate_pdf_with_playwright(
|
|
|
55
55
|
pdf_params = {
|
|
56
56
|
"format": "A4",
|
|
57
57
|
"print_background": True,
|
|
58
|
-
"margin": {
|
|
58
|
+
"margin": {
|
|
59
|
+
"top": "20mm",
|
|
60
|
+
"bottom": "20mm",
|
|
61
|
+
"left": "20mm",
|
|
62
|
+
"right": "20mm",
|
|
63
|
+
},
|
|
59
64
|
"path": output_path,
|
|
60
65
|
} # Playwright ignores None paths
|
|
61
66
|
|
|
@@ -101,7 +106,7 @@ def _create_sections(html):
|
|
|
101
106
|
|
|
102
107
|
|
|
103
108
|
def convert(
|
|
104
|
-
|
|
109
|
+
markdown_path,
|
|
105
110
|
css_path=None,
|
|
106
111
|
output_path=None,
|
|
107
112
|
*,
|
|
@@ -112,7 +117,7 @@ def convert(
|
|
|
112
117
|
Convert a markdown file to a pdf file.
|
|
113
118
|
|
|
114
119
|
Args:
|
|
115
|
-
|
|
120
|
+
markdown_path (str): Path to the markdown file.
|
|
116
121
|
css_path (str=None): Path to the CSS file.
|
|
117
122
|
output_path (str=None): Path to the output file.
|
|
118
123
|
extend_default_css (bool=True): Extend the default CSS file.
|
|
@@ -122,7 +127,7 @@ def convert(
|
|
|
122
127
|
css_path = get_css_path()
|
|
123
128
|
|
|
124
129
|
if output_path is None:
|
|
125
|
-
output_path = get_output_path(
|
|
130
|
+
output_path = get_output_path(markdown_path, None)
|
|
126
131
|
|
|
127
132
|
if extend_default_css:
|
|
128
133
|
css_sources = [get_code_css_path(), get_css_path(), css_path]
|
|
@@ -132,14 +137,14 @@ def convert(
|
|
|
132
137
|
css_sources = drop_duplicates(css_sources)
|
|
133
138
|
|
|
134
139
|
try:
|
|
135
|
-
html = markdown2.markdown_path(
|
|
140
|
+
html = markdown2.markdown_path(markdown_path, extras=MARKDOWN_EXTENSIONS)
|
|
136
141
|
html = _create_sections(html)
|
|
137
142
|
|
|
138
143
|
_generate_pdf_with_playwright(
|
|
139
144
|
html,
|
|
140
145
|
output_path,
|
|
141
146
|
css_content=_get_css_content(css_sources),
|
|
142
|
-
base_dir=Path(
|
|
147
|
+
base_dir=Path(markdown_path).resolve().parent,
|
|
143
148
|
dump_html=dump_html,
|
|
144
149
|
)
|
|
145
150
|
|
|
@@ -147,12 +152,14 @@ def convert(
|
|
|
147
152
|
raise RuntimeError(exc) from exc
|
|
148
153
|
|
|
149
154
|
|
|
150
|
-
def live_convert(
|
|
155
|
+
def live_convert(
|
|
156
|
+
markdown_path, css_path=None, output_path=None, *, extend_default_css=True
|
|
157
|
+
):
|
|
151
158
|
"""
|
|
152
159
|
Convert a markdown file to a pdf file and watch for changes.
|
|
153
160
|
|
|
154
161
|
Args:
|
|
155
|
-
|
|
162
|
+
markdown_path (str): Path to the markdown file.
|
|
156
163
|
css_path (str=None): Path to the CSS file.
|
|
157
164
|
output_path (str=None): Path to the output file.
|
|
158
165
|
extend_default_css (bool=True): Extend the default CSS file.
|
|
@@ -161,10 +168,10 @@ def live_convert(md_path, css_path=None, output_path=None, *, extend_default_css
|
|
|
161
168
|
css_path = get_css_path()
|
|
162
169
|
|
|
163
170
|
if output_path is None:
|
|
164
|
-
output_path = get_output_path(
|
|
171
|
+
output_path = get_output_path(markdown_path, None)
|
|
165
172
|
|
|
166
173
|
live_converter = LiveConverter(
|
|
167
|
-
|
|
174
|
+
markdown_path,
|
|
168
175
|
css_path,
|
|
169
176
|
output_path,
|
|
170
177
|
extend_default_css=extend_default_css,
|
|
@@ -173,12 +180,12 @@ def live_convert(md_path, css_path=None, output_path=None, *, extend_default_css
|
|
|
173
180
|
live_converter.observe()
|
|
174
181
|
|
|
175
182
|
|
|
176
|
-
def convert_text(
|
|
183
|
+
def convert_text(markdown_text, css_text=None, *, extend_default_css=True):
|
|
177
184
|
"""
|
|
178
185
|
Convert markdown text to a pdf file.
|
|
179
186
|
|
|
180
187
|
Args:
|
|
181
|
-
|
|
188
|
+
markdown_text (str): Markdown text.
|
|
182
189
|
css_text (str=None): CSS text.
|
|
183
190
|
extend_default_css (bool=True): Extend the default CSS file.
|
|
184
191
|
|
|
@@ -197,7 +204,7 @@ def convert_text(md_text, css_text=None, *, extend_default_css=True):
|
|
|
197
204
|
css_sources = [code_css, css_text]
|
|
198
205
|
|
|
199
206
|
try:
|
|
200
|
-
html = markdown2.markdown(
|
|
207
|
+
html = markdown2.markdown(markdown_text, extras=MARKDOWN_EXTENSIONS)
|
|
201
208
|
html = _create_sections(html)
|
|
202
209
|
|
|
203
210
|
return _generate_pdf_with_playwright(
|
|
@@ -215,17 +222,25 @@ class LiveConverter:
|
|
|
215
222
|
Class to convert a markdown file to a pdf file and watch for changes.
|
|
216
223
|
"""
|
|
217
224
|
|
|
218
|
-
def __init__(
|
|
225
|
+
def __init__(
|
|
226
|
+
self,
|
|
227
|
+
markdown_path,
|
|
228
|
+
css_path,
|
|
229
|
+
output_path,
|
|
230
|
+
*,
|
|
231
|
+
extend_default_css=True,
|
|
232
|
+
loud=False,
|
|
233
|
+
):
|
|
219
234
|
"""
|
|
220
235
|
Initialize the LiveConverter class.
|
|
221
236
|
|
|
222
237
|
Args:
|
|
223
|
-
|
|
238
|
+
markdown_path (str): Path to the markdown file.
|
|
224
239
|
css_path (str): Path to the CSS file.
|
|
225
240
|
output_path (str): Path to the output file.
|
|
226
241
|
extend_default_css (bool): Extend the default CSS file.
|
|
227
242
|
"""
|
|
228
|
-
self.md_path = Path(
|
|
243
|
+
self.md_path = Path(markdown_path).absolute()
|
|
229
244
|
self.css_path = Path(css_path).absolute()
|
|
230
245
|
self.output_path = output_path
|
|
231
246
|
self.extend_default_css = extend_default_css
|
|
@@ -272,14 +287,17 @@ class LiveConverter:
|
|
|
272
287
|
try:
|
|
273
288
|
while True:
|
|
274
289
|
|
|
275
|
-
|
|
290
|
+
markdown_modified = self.get_last_modified_date(self.md_path)
|
|
276
291
|
css_modified = self.get_last_modified_date(self.css_path)
|
|
277
292
|
|
|
278
|
-
if
|
|
293
|
+
if (
|
|
294
|
+
markdown_modified != self.md_last_modified
|
|
295
|
+
or css_modified != self.css_last_modified
|
|
296
|
+
):
|
|
279
297
|
|
|
280
298
|
self.write_pdf()
|
|
281
299
|
|
|
282
|
-
self.md_last_modified =
|
|
300
|
+
self.md_last_modified = markdown_modified
|
|
283
301
|
self.css_last_modified = css_modified
|
|
284
302
|
|
|
285
303
|
time.sleep(poll_interval)
|
|
@@ -17,28 +17,28 @@ from .constants import BLUE, CYAN, GREEN, YELLOW, OPTIONS, OPTIONS_MODES
|
|
|
17
17
|
from .utils import color
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
def get_output_path(
|
|
20
|
+
def get_output_path(markdown_path, output_dir=None):
|
|
21
21
|
"""
|
|
22
22
|
Get the output path for the pdf file.
|
|
23
23
|
|
|
24
24
|
Args:
|
|
25
|
-
|
|
25
|
+
markdown_path (str): The path to the markdown file.
|
|
26
26
|
output_dir (str): The output directory.
|
|
27
27
|
|
|
28
28
|
Returns:
|
|
29
29
|
str: The output path.
|
|
30
30
|
"""
|
|
31
|
-
|
|
31
|
+
markdown_path = Path(markdown_path)
|
|
32
32
|
|
|
33
33
|
if output_dir is None:
|
|
34
|
-
return
|
|
34
|
+
return markdown_path.parent / f"{markdown_path.stem}.pdf"
|
|
35
35
|
|
|
36
36
|
output_dir = Path(output_dir)
|
|
37
37
|
|
|
38
38
|
if output_dir.suffix == ".pdf":
|
|
39
39
|
return output_dir
|
|
40
40
|
|
|
41
|
-
return output_dir.parent / f"{Path(
|
|
41
|
+
return output_dir.parent / f"{Path(markdown_path).stem}.pdf"
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
def get_css_path():
|
|
@@ -76,11 +76,14 @@ def get_usage():
|
|
|
76
76
|
f"{color(GREEN, 'markdown-convert')} "
|
|
77
77
|
f"[{color(YELLOW, OPTIONS[0])}] [{color(BLUE, 'options')}]"
|
|
78
78
|
)
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
option_one = (
|
|
80
|
+
f"{color(BLUE, OPTIONS[1])}{color(CYAN, '=')}"
|
|
81
|
+
f"{color(CYAN, '|'.join(OPTIONS_MODES))}"
|
|
82
|
+
)
|
|
83
|
+
option_two = (
|
|
81
84
|
f"{color(BLUE, OPTIONS[2])}{color(CYAN, '=')}[{color(CYAN, 'css_file_path')}]"
|
|
82
85
|
)
|
|
83
|
-
|
|
86
|
+
option_three = f"{color(BLUE, OPTIONS[3])}{color(CYAN, '=')}[{color(CYAN, 'output_file_path')}]"
|
|
84
87
|
|
|
85
88
|
usage = (
|
|
86
89
|
"\n"
|
|
@@ -88,11 +91,11 @@ def get_usage():
|
|
|
88
91
|
f" {commd}\n"
|
|
89
92
|
"\n"
|
|
90
93
|
"Options:\n"
|
|
91
|
-
f" {
|
|
94
|
+
f" {option_one}\n"
|
|
92
95
|
" Convert the markdown file once (default) or live.\n"
|
|
93
|
-
f" {
|
|
96
|
+
f" {option_two}\n"
|
|
94
97
|
" Use a custom CSS file.\n"
|
|
95
|
-
f" {
|
|
98
|
+
f" {option_three}\n"
|
|
96
99
|
" Specify the output file path.\n"
|
|
97
100
|
)
|
|
98
101
|
return usage
|
|
@@ -6,21 +6,21 @@ Author: @julynx
|
|
|
6
6
|
from pathlib import Path
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
def validate_markdown_path(
|
|
9
|
+
def validate_markdown_path(markdown_path):
|
|
10
10
|
"""
|
|
11
11
|
Validate the markdown file path.
|
|
12
12
|
|
|
13
13
|
Args:
|
|
14
|
-
|
|
14
|
+
markdown_path (str): The path to the markdown file.
|
|
15
15
|
|
|
16
16
|
Raises:
|
|
17
17
|
FileNotFoundError: If the file is not found.
|
|
18
18
|
ValueError: If the file is not a Markdown file.
|
|
19
19
|
"""
|
|
20
|
-
if not Path(
|
|
21
|
-
raise FileNotFoundError(f"File not found: '{
|
|
20
|
+
if not Path(markdown_path).is_file():
|
|
21
|
+
raise FileNotFoundError(f"File not found: '{markdown_path}'")
|
|
22
22
|
|
|
23
|
-
if not
|
|
23
|
+
if not markdown_path.endswith(".md"):
|
|
24
24
|
raise ValueError("File must be a Markdown file.")
|
|
25
25
|
|
|
26
26
|
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "markdown_convert"
|
|
7
|
-
version = "1.2.
|
|
7
|
+
version = "1.2.23"
|
|
8
8
|
description = "Convert Markdown files to PDF from your command line."
|
|
9
9
|
authors = [
|
|
10
10
|
{ name = "Julio Cabria", email = "juliocabria@tutanota.com" },
|
|
@@ -59,3 +59,9 @@ include = [
|
|
|
59
59
|
"markdown_convert/modules/utils.py",
|
|
60
60
|
"markdown_convert/modules/validate.py",
|
|
61
61
|
]
|
|
62
|
+
|
|
63
|
+
[dependency-groups]
|
|
64
|
+
dev = [
|
|
65
|
+
"black>=25.11.0",
|
|
66
|
+
"pylint>=3.3.9",
|
|
67
|
+
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|