markdown_convert 1.2.13__tar.gz → 1.2.14__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.13 → markdown_convert-1.2.14}/PKG-INFO +1 -1
- markdown_convert-1.2.14/markdown_convert/__main__.py +96 -0
- {markdown_convert-1.2.13 → markdown_convert-1.2.14}/pyproject.toml +7 -1
- {markdown_convert-1.2.13 → markdown_convert-1.2.14}/.gitignore +0 -0
- {markdown_convert-1.2.13 → markdown_convert-1.2.14}/LICENSE +0 -0
- {markdown_convert-1.2.13 → markdown_convert-1.2.14}/README.md +0 -0
- {markdown_convert-1.2.13 → markdown_convert-1.2.14}/markdown_convert/code.css +0 -0
- {markdown_convert-1.2.13 → markdown_convert-1.2.14}/markdown_convert/default.css +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.14
|
|
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>
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
CLI interface to convert markdown files to pdf.
|
|
5
|
+
Author: @julynx
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
from sys import exit as sys_exit
|
|
10
|
+
|
|
11
|
+
from argsdict import args
|
|
12
|
+
from .modules.constants import RED, OPTIONS, OPTIONS_MODES
|
|
13
|
+
from .modules.convert import convert, live_convert
|
|
14
|
+
from .modules.resources import get_css_path, get_output_path, get_usage
|
|
15
|
+
from .modules.utils import color
|
|
16
|
+
from .modules.validate import (validate_css_path, validate_markdown_path,
|
|
17
|
+
validate_output_path)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def main():
|
|
21
|
+
"""
|
|
22
|
+
Convert a markdown file to a pdf file.
|
|
23
|
+
"""
|
|
24
|
+
try:
|
|
25
|
+
# Load and validate arguments
|
|
26
|
+
arg = args(["markdown_file_path"])
|
|
27
|
+
for key in set(arg.keys()) - set(OPTIONS):
|
|
28
|
+
raise IndexError(f"Invalid option: '{key}'")
|
|
29
|
+
|
|
30
|
+
# Get the markdown path
|
|
31
|
+
try:
|
|
32
|
+
md_path = arg["markdown_file_path"]
|
|
33
|
+
validate_markdown_path(md_path)
|
|
34
|
+
except KeyError as key_err:
|
|
35
|
+
raise IndexError("Missing 'markdown_file_path' argument.") \
|
|
36
|
+
from key_err
|
|
37
|
+
except Exception as exc:
|
|
38
|
+
raise IndexError(f"Invalid 'markdown_file_path' argument: {exc}") \
|
|
39
|
+
from exc
|
|
40
|
+
|
|
41
|
+
# Get the mode
|
|
42
|
+
try:
|
|
43
|
+
mode = arg["--mode"]
|
|
44
|
+
if mode not in OPTIONS_MODES:
|
|
45
|
+
raise ValueError(f"Invalid mode: '{mode}'")
|
|
46
|
+
except KeyError:
|
|
47
|
+
mode = "once"
|
|
48
|
+
|
|
49
|
+
# Get the CSS path
|
|
50
|
+
try:
|
|
51
|
+
css_path = arg["--css"]
|
|
52
|
+
validate_css_path(css_path)
|
|
53
|
+
except KeyError:
|
|
54
|
+
css_path = get_css_path()
|
|
55
|
+
except Exception as exc:
|
|
56
|
+
raise IndexError(f"Invalid 'css_file_path' argument: {exc}") \
|
|
57
|
+
from exc
|
|
58
|
+
|
|
59
|
+
# Get the output path
|
|
60
|
+
output_path = None
|
|
61
|
+
try:
|
|
62
|
+
output_path = arg["--out"]
|
|
63
|
+
validate_output_path(output_path)
|
|
64
|
+
output_path = get_output_path(md_path, output_path)
|
|
65
|
+
except KeyError:
|
|
66
|
+
output_path = get_output_path(md_path, None)
|
|
67
|
+
except Exception as exc:
|
|
68
|
+
raise IndexError(f"Invalid 'output_path' argument: {exc}") \
|
|
69
|
+
from exc
|
|
70
|
+
|
|
71
|
+
# Compile the markdown file
|
|
72
|
+
print(f'\nGenerating PDF file from \'{md_path}\'...\n')
|
|
73
|
+
if mode == "once":
|
|
74
|
+
convert(md_path, css_path, output_path)
|
|
75
|
+
else:
|
|
76
|
+
live_convert(md_path, css_path, output_path)
|
|
77
|
+
|
|
78
|
+
sys_exit(0)
|
|
79
|
+
|
|
80
|
+
except Exception as err:
|
|
81
|
+
|
|
82
|
+
asked_for_help = "--help" in arg or "-h" in arg
|
|
83
|
+
show_usage = (isinstance(err, (IndexError, ValueError))
|
|
84
|
+
or asked_for_help)
|
|
85
|
+
|
|
86
|
+
if show_usage:
|
|
87
|
+
print(get_usage())
|
|
88
|
+
|
|
89
|
+
if not asked_for_help:
|
|
90
|
+
print(color(RED, f"ERROR: {err}\n"))
|
|
91
|
+
|
|
92
|
+
sys_exit(1)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if __name__ == '__main__':
|
|
96
|
+
main()
|
|
@@ -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.14"
|
|
8
8
|
description = "Convert Markdown files to PDF from your command line."
|
|
9
9
|
authors = [
|
|
10
10
|
{ name = "Julio Cabria", email = "juliocabria@tutanota.com" },
|
|
@@ -32,9 +32,15 @@ markdown-convert = "markdown_convert.__main__:main"
|
|
|
32
32
|
|
|
33
33
|
[tool.hatch.build.targets.sdist]
|
|
34
34
|
include = [
|
|
35
|
+
"markdown_convert/__main__.py",
|
|
35
36
|
"markdown_convert/default.css",
|
|
36
37
|
"markdown_convert/code.css",
|
|
37
38
|
]
|
|
38
39
|
|
|
39
40
|
[tool.hatch.build.targets.wheel]
|
|
40
41
|
packages = ["markdown_convert"]
|
|
42
|
+
include = [
|
|
43
|
+
"markdown_convert/__main__.py",
|
|
44
|
+
"markdown_convert/default.css",
|
|
45
|
+
"markdown_convert/code.css",
|
|
46
|
+
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|