markdown_convert 1.2.12__py3-none-any.whl → 1.2.32__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.
@@ -0,0 +1,11 @@
1
+ """
2
+ This file is used to import all the functions from the modules and make them
3
+ available to the user.
4
+ Author: @julynx
5
+ """
6
+
7
+ from .modules.convert import convert, live_convert, convert_text
8
+ from .__main__ import main
9
+
10
+ __version__ = "1.2.15"
11
+ __all__ = ["convert", "live_convert", "convert_text", "main"]
@@ -0,0 +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 (
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
+ markdown_path = arg["markdown_file_path"]
36
+ validate_markdown_path(markdown_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(markdown_path, output_path)
65
+ except KeyError:
66
+ output_path = get_output_path(markdown_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 '{markdown_path}'...\n")
72
+ if mode in ("once", "debug"):
73
+ convert(markdown_path, css_path, output_path, dump_html=mode == "debug")
74
+ else:
75
+ live_convert(markdown_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 */