markdown_convert 1.2.15__py3-none-any.whl → 1.2.17__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.
@@ -1,96 +1,95 @@
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()
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 (
17
+ validate_css_path,
18
+ validate_markdown_path,
19
+ validate_output_path,
20
+ )
21
+
22
+
23
+ def main():
24
+ """
25
+ Convert a markdown file to a pdf file.
26
+ """
27
+ try:
28
+ # Load and validate arguments
29
+ arg = args(["markdown_file_path"])
30
+ for key in set(arg.keys()) - set(OPTIONS):
31
+ raise IndexError(f"Invalid option: '{key}'")
32
+
33
+ # Get the markdown path
34
+ try:
35
+ md_path = arg["markdown_file_path"]
36
+ validate_markdown_path(md_path)
37
+ except KeyError as key_err:
38
+ raise IndexError("Missing 'markdown_file_path' argument.") from key_err
39
+ except Exception as exc:
40
+ raise IndexError(f"Invalid 'markdown_file_path' argument: {exc}") from exc
41
+
42
+ # Get the mode
43
+ try:
44
+ mode = arg["--mode"]
45
+ if mode not in OPTIONS_MODES:
46
+ raise ValueError(f"Invalid mode: '{mode}'")
47
+ except KeyError:
48
+ mode = "once"
49
+
50
+ # Get the CSS path
51
+ try:
52
+ css_path = arg["--css"]
53
+ validate_css_path(css_path)
54
+ except KeyError:
55
+ css_path = get_css_path()
56
+ except Exception as exc:
57
+ raise IndexError(f"Invalid 'css_file_path' argument: {exc}") 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}") from exc
69
+
70
+ # Compile the markdown file
71
+ print(f"\nGenerating PDF file from '{md_path}'...\n")
72
+ if mode in ("once", "debug"):
73
+ convert(md_path, css_path, output_path, dump_html=mode == "debug")
74
+ else:
75
+ live_convert(md_path, css_path, output_path)
76
+
77
+ sys_exit(0)
78
+
79
+ # pylint: disable=W0718
80
+ except Exception as err:
81
+
82
+ asked_for_help = "--help" in arg or "-h" in arg
83
+ show_usage = isinstance(err, (IndexError, ValueError)) or asked_for_help
84
+
85
+ if show_usage:
86
+ print(get_usage())
87
+
88
+ if not asked_for_help:
89
+ print(color(RED, f"ERROR: {err}\n"))
90
+
91
+ sys_exit(1)
92
+
93
+
94
+ if __name__ == "__main__":
95
+ main()
markdown_convert/code.css CHANGED
@@ -1,74 +1,74 @@
1
- pre { line-height: 125%; }
2
- td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
3
- span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
4
- td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
5
- span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
6
- .codehilite .hll { background-color: #ffffcc }
7
- .codehilite .c { color: #3D7B7B; font-style: italic } /* Comment */
8
- .codehilite .err { border: 1px solid #FF0000 } /* Error */
9
- .codehilite .k { color: #008000; font-weight: bold } /* Keyword */
10
- .codehilite .o { color: #666666 } /* Operator */
11
- .codehilite .ch { color: #3D7B7B; font-style: italic } /* Comment.Hashbang */
12
- .codehilite .cm { color: #3D7B7B; font-style: italic } /* Comment.Multiline */
13
- .codehilite .cp { color: #9C6500 } /* Comment.Preproc */
14
- .codehilite .cpf { color: #3D7B7B; font-style: italic } /* Comment.PreprocFile */
15
- .codehilite .c1 { color: #3D7B7B; font-style: italic } /* Comment.Single */
16
- .codehilite .cs { color: #3D7B7B; font-style: italic } /* Comment.Special */
17
- .codehilite .gd { color: #A00000 } /* Generic.Deleted */
18
- .codehilite .ge { font-style: italic } /* Generic.Emph */
19
- .codehilite .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
20
- .codehilite .gr { color: #E40000 } /* Generic.Error */
21
- .codehilite .gh { color: #000080; font-weight: bold } /* Generic.Heading */
22
- .codehilite .gi { color: #008400 } /* Generic.Inserted */
23
- .codehilite .go { color: #717171 } /* Generic.Output */
24
- .codehilite .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
25
- .codehilite .gs { font-weight: bold } /* Generic.Strong */
26
- .codehilite .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
27
- .codehilite .gt { color: #0044DD } /* Generic.Traceback */
28
- .codehilite .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
29
- .codehilite .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
30
- .codehilite .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
31
- .codehilite .kp { color: #008000 } /* Keyword.Pseudo */
32
- .codehilite .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
33
- .codehilite .kt { color: #B00040 } /* Keyword.Type */
34
- .codehilite .m { color: #666666 } /* Literal.Number */
35
- .codehilite .s { color: #BA2121 } /* Literal.String */
36
- .codehilite .na { color: #687822 } /* Name.Attribute */
37
- .codehilite .nb { color: #008000 } /* Name.Builtin */
38
- .codehilite .nc { color: #0000FF; font-weight: bold } /* Name.Class */
39
- .codehilite .no { color: #880000 } /* Name.Constant */
40
- .codehilite .nd { color: #AA22FF } /* Name.Decorator */
41
- .codehilite .ni { color: #717171; font-weight: bold } /* Name.Entity */
42
- .codehilite .ne { color: #CB3F38; font-weight: bold } /* Name.Exception */
43
- .codehilite .nf { color: #0000FF } /* Name.Function */
44
- .codehilite .nl { color: #767600 } /* Name.Label */
45
- .codehilite .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
46
- .codehilite .nt { color: #008000; font-weight: bold } /* Name.Tag */
47
- .codehilite .nv { color: #19177C } /* Name.Variable */
48
- .codehilite .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
49
- .codehilite .w { color: #bbbbbb } /* Text.Whitespace */
50
- .codehilite .mb { color: #666666 } /* Literal.Number.Bin */
51
- .codehilite .mf { color: #666666 } /* Literal.Number.Float */
52
- .codehilite .mh { color: #666666 } /* Literal.Number.Hex */
53
- .codehilite .mi { color: #666666 } /* Literal.Number.Integer */
54
- .codehilite .mo { color: #666666 } /* Literal.Number.Oct */
55
- .codehilite .sa { color: #BA2121 } /* Literal.String.Affix */
56
- .codehilite .sb { color: #BA2121 } /* Literal.String.Backtick */
57
- .codehilite .sc { color: #BA2121 } /* Literal.String.Char */
58
- .codehilite .dl { color: #BA2121 } /* Literal.String.Delimiter */
59
- .codehilite .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
60
- .codehilite .s2 { color: #BA2121 } /* Literal.String.Double */
61
- .codehilite .se { color: #AA5D1F; font-weight: bold } /* Literal.String.Escape */
62
- .codehilite .sh { color: #BA2121 } /* Literal.String.Heredoc */
63
- .codehilite .si { color: #A45A77; font-weight: bold } /* Literal.String.Interpol */
64
- .codehilite .sx { color: #008000 } /* Literal.String.Other */
65
- .codehilite .sr { color: #A45A77 } /* Literal.String.Regex */
66
- .codehilite .s1 { color: #BA2121 } /* Literal.String.Single */
67
- .codehilite .ss { color: #19177C } /* Literal.String.Symbol */
68
- .codehilite .bp { color: #008000 } /* Name.Builtin.Pseudo */
69
- .codehilite .fm { color: #0000FF } /* Name.Function.Magic */
70
- .codehilite .vc { color: #19177C } /* Name.Variable.Class */
71
- .codehilite .vg { color: #19177C } /* Name.Variable.Global */
72
- .codehilite .vi { color: #19177C } /* Name.Variable.Instance */
73
- .codehilite .vm { color: #19177C } /* Name.Variable.Magic */
1
+ pre { line-height: 125%; }
2
+ td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
3
+ span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
4
+ td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
5
+ span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
6
+ .codehilite .hll { background-color: #ffffcc }
7
+ .codehilite .c { color: #3D7B7B; font-style: italic } /* Comment */
8
+ .codehilite .err { border: 1px solid #FF0000 } /* Error */
9
+ .codehilite .k { color: #008000; font-weight: bold } /* Keyword */
10
+ .codehilite .o { color: #666666 } /* Operator */
11
+ .codehilite .ch { color: #3D7B7B; font-style: italic } /* Comment.Hashbang */
12
+ .codehilite .cm { color: #3D7B7B; font-style: italic } /* Comment.Multiline */
13
+ .codehilite .cp { color: #9C6500 } /* Comment.Preproc */
14
+ .codehilite .cpf { color: #3D7B7B; font-style: italic } /* Comment.PreprocFile */
15
+ .codehilite .c1 { color: #3D7B7B; font-style: italic } /* Comment.Single */
16
+ .codehilite .cs { color: #3D7B7B; font-style: italic } /* Comment.Special */
17
+ .codehilite .gd { color: #A00000 } /* Generic.Deleted */
18
+ .codehilite .ge { font-style: italic } /* Generic.Emph */
19
+ .codehilite .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
20
+ .codehilite .gr { color: #E40000 } /* Generic.Error */
21
+ .codehilite .gh { color: #000080; font-weight: bold } /* Generic.Heading */
22
+ .codehilite .gi { color: #008400 } /* Generic.Inserted */
23
+ .codehilite .go { color: #717171 } /* Generic.Output */
24
+ .codehilite .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
25
+ .codehilite .gs { font-weight: bold } /* Generic.Strong */
26
+ .codehilite .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
27
+ .codehilite .gt { color: #0044DD } /* Generic.Traceback */
28
+ .codehilite .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
29
+ .codehilite .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
30
+ .codehilite .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
31
+ .codehilite .kp { color: #008000 } /* Keyword.Pseudo */
32
+ .codehilite .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
33
+ .codehilite .kt { color: #B00040 } /* Keyword.Type */
34
+ .codehilite .m { color: #666666 } /* Literal.Number */
35
+ .codehilite .s { color: #BA2121 } /* Literal.String */
36
+ .codehilite .na { color: #687822 } /* Name.Attribute */
37
+ .codehilite .nb { color: #008000 } /* Name.Builtin */
38
+ .codehilite .nc { color: #0000FF; font-weight: bold } /* Name.Class */
39
+ .codehilite .no { color: #880000 } /* Name.Constant */
40
+ .codehilite .nd { color: #AA22FF } /* Name.Decorator */
41
+ .codehilite .ni { color: #717171; font-weight: bold } /* Name.Entity */
42
+ .codehilite .ne { color: #CB3F38; font-weight: bold } /* Name.Exception */
43
+ .codehilite .nf { color: #0000FF } /* Name.Function */
44
+ .codehilite .nl { color: #767600 } /* Name.Label */
45
+ .codehilite .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
46
+ .codehilite .nt { color: #008000; font-weight: bold } /* Name.Tag */
47
+ .codehilite .nv { color: #19177C } /* Name.Variable */
48
+ .codehilite .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
49
+ .codehilite .w { color: #bbbbbb } /* Text.Whitespace */
50
+ .codehilite .mb { color: #666666 } /* Literal.Number.Bin */
51
+ .codehilite .mf { color: #666666 } /* Literal.Number.Float */
52
+ .codehilite .mh { color: #666666 } /* Literal.Number.Hex */
53
+ .codehilite .mi { color: #666666 } /* Literal.Number.Integer */
54
+ .codehilite .mo { color: #666666 } /* Literal.Number.Oct */
55
+ .codehilite .sa { color: #BA2121 } /* Literal.String.Affix */
56
+ .codehilite .sb { color: #BA2121 } /* Literal.String.Backtick */
57
+ .codehilite .sc { color: #BA2121 } /* Literal.String.Char */
58
+ .codehilite .dl { color: #BA2121 } /* Literal.String.Delimiter */
59
+ .codehilite .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
60
+ .codehilite .s2 { color: #BA2121 } /* Literal.String.Double */
61
+ .codehilite .se { color: #AA5D1F; font-weight: bold } /* Literal.String.Escape */
62
+ .codehilite .sh { color: #BA2121 } /* Literal.String.Heredoc */
63
+ .codehilite .si { color: #A45A77; font-weight: bold } /* Literal.String.Interpol */
64
+ .codehilite .sx { color: #008000 } /* Literal.String.Other */
65
+ .codehilite .sr { color: #A45A77 } /* Literal.String.Regex */
66
+ .codehilite .s1 { color: #BA2121 } /* Literal.String.Single */
67
+ .codehilite .ss { color: #19177C } /* Literal.String.Symbol */
68
+ .codehilite .bp { color: #008000 } /* Name.Builtin.Pseudo */
69
+ .codehilite .fm { color: #0000FF } /* Name.Function.Magic */
70
+ .codehilite .vc { color: #19177C } /* Name.Variable.Class */
71
+ .codehilite .vg { color: #19177C } /* Name.Variable.Global */
72
+ .codehilite .vi { color: #19177C } /* Name.Variable.Instance */
73
+ .codehilite .vm { color: #19177C } /* Name.Variable.Magic */
74
74
  .codehilite .il { color: #666666 } /* Literal.Number.Integer.Long */