markdown_convert 1.2.7__py3-none-any.whl → 1.2.11__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-1.2.7.dist-info → markdown_convert-1.2.11.dist-info}/METADATA +12 -17
- markdown_convert-1.2.11.dist-info/RECORD +7 -0
- {markdown_convert-1.2.7.dist-info → markdown_convert-1.2.11.dist-info}/WHEEL +1 -1
- markdown_convert-1.2.11.dist-info/entry_points.txt +2 -0
- markdown_convert/__init__.py +0 -8
- markdown_convert/__main__.py +0 -96
- markdown_convert/modules/__init__.py +0 -4
- markdown_convert/modules/constants.py +0 -24
- markdown_convert/modules/convert.py +0 -194
- markdown_convert/modules/resources.py +0 -85
- markdown_convert/modules/utils.py +0 -38
- markdown_convert/modules/validate.py +0 -61
- markdown_convert-1.2.7.dist-info/RECORD +0 -15
- markdown_convert-1.2.7.dist-info/entry_points.txt +0 -3
- {markdown_convert-1.2.7.dist-info → markdown_convert-1.2.11.dist-info/licenses}/LICENSE +0 -0
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: markdown_convert
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.11
|
|
4
4
|
Summary: Convert Markdown files to PDF from your command line.
|
|
5
|
+
Project-URL: homepage, https://github.com/Julynx/markdown_convert
|
|
6
|
+
Author-email: Julio Cabria <juliocabria@tutanota.com>
|
|
5
7
|
License: GPL-2.0-only
|
|
6
|
-
|
|
7
|
-
Author-email: juliocabria@tutanota.com
|
|
8
|
-
Requires-Python: >=3.9,<4.0
|
|
8
|
+
License-File: LICENSE
|
|
9
9
|
Classifier: License :: OSI Approved :: GNU General Public License v2 (GPLv2)
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
10
11
|
Classifier: Programming Language :: Python :: 3
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Requires-Dist:
|
|
17
|
-
Requires-Dist: markdown2 (>=2.4.13,<3.0.0)
|
|
18
|
-
Requires-Dist: pygments (>=2.17.2,<3.0.0)
|
|
19
|
-
Requires-Dist: setuptools (>=46.0.0)
|
|
20
|
-
Requires-Dist: weasyprint (>=62.3,<70.0)
|
|
21
|
-
Project-URL: Homepage, https://github.com/Julynx/markdown_convert
|
|
12
|
+
Requires-Python: <4.0,>=3.9
|
|
13
|
+
Requires-Dist: argsdict==1.0.0
|
|
14
|
+
Requires-Dist: markdown2<3,>=2.4.13
|
|
15
|
+
Requires-Dist: pygments<3,>=2.17.2
|
|
16
|
+
Requires-Dist: setuptools>=46.0.0
|
|
17
|
+
Requires-Dist: weasyprint<70.0,>=62.3
|
|
22
18
|
Description-Content-Type: text/markdown
|
|
23
19
|
|
|
24
20
|
# markdown-convert
|
|
@@ -83,4 +79,3 @@ live_convert('README.md', 'style.css', 'README.pdf')
|
|
|
83
79
|
### Integrations
|
|
84
80
|
|
|
85
81
|
Right click a Markdown file and `Convert to PDF` with the [markdown_convert_explorer](https://github.com/Julynx/markdown_convert_explorer) and [markdown_convert_nautilus](https://github.com/Julynx/markdown_convert_nautilus) extensions for Windows and Linux.
|
|
86
|
-
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
markdown_convert/code.css,sha256=ZQtsG8A0lgzA44m7qJ4HjbOX5y8eSWwsgMCj3R3WkwM,5008
|
|
2
|
+
markdown_convert/default.css,sha256=Ke6r5X7M6c5czCrjTK9FXCbNj_XfFEi7ArYxE2r_Ae0,9010
|
|
3
|
+
markdown_convert-1.2.11.dist-info/METADATA,sha256=7vN8PsWtlMetH4GpgVjKWWe3tV4QGOvUyVpYuQgT2kM,3155
|
|
4
|
+
markdown_convert-1.2.11.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
5
|
+
markdown_convert-1.2.11.dist-info/entry_points.txt,sha256=RCmzC7C0sX-SpzIP2Cr34rhg3lMd7BRx-exaZPfK8bU,68
|
|
6
|
+
markdown_convert-1.2.11.dist-info/licenses/LICENSE,sha256=GJsa-V1mEVHgVM6hDJGz11Tk3k0_7PsHTB-ylHb3Fns,18431
|
|
7
|
+
markdown_convert-1.2.11.dist-info/RECORD,,
|
markdown_convert/__init__.py
DELETED
markdown_convert/__main__.py
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
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,24 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
This module contains the constants used in the markdown_convert package.
|
|
3
|
-
Author: @julynx
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
RED = '31'
|
|
7
|
-
GREEN = '32'
|
|
8
|
-
YELLOW = '33'
|
|
9
|
-
BLUE = '34'
|
|
10
|
-
MAGENTA = '35'
|
|
11
|
-
CYAN = '36'
|
|
12
|
-
|
|
13
|
-
OPTIONS = ('markdown_file_path',
|
|
14
|
-
"--mode",
|
|
15
|
-
'--css',
|
|
16
|
-
"--out",
|
|
17
|
-
"-h", "--help")
|
|
18
|
-
|
|
19
|
-
OPTIONS_MODES = ('once', 'live')
|
|
20
|
-
|
|
21
|
-
MD_EXTENSIONS = ["fenced-code-blocks",
|
|
22
|
-
"header-ids",
|
|
23
|
-
"breaks",
|
|
24
|
-
"tables"]
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Module to convert a markdown file to a pdf file.
|
|
3
|
-
Author: @julynx
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
import os
|
|
7
|
-
import time
|
|
8
|
-
from datetime import datetime
|
|
9
|
-
from pathlib import Path
|
|
10
|
-
|
|
11
|
-
import markdown2
|
|
12
|
-
import weasyprint
|
|
13
|
-
|
|
14
|
-
from .resources import get_css_path, get_code_css_path, get_output_path
|
|
15
|
-
from .utils import drop_duplicates
|
|
16
|
-
from .constants import MD_EXTENSIONS
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def convert(md_path, css_path=None, output_path=None,
|
|
20
|
-
*, extend_default_css=True):
|
|
21
|
-
"""
|
|
22
|
-
Convert a markdown file to a pdf file.
|
|
23
|
-
|
|
24
|
-
Args:
|
|
25
|
-
md_path (str): Path to the markdown file.
|
|
26
|
-
css_path (str=None): Path to the CSS file.
|
|
27
|
-
output_path (str=None): Path to the output file.
|
|
28
|
-
extend_default_css (bool=True): Extend the default CSS file.
|
|
29
|
-
"""
|
|
30
|
-
if css_path is None:
|
|
31
|
-
css_path = get_css_path()
|
|
32
|
-
|
|
33
|
-
if output_path is None:
|
|
34
|
-
output_path = get_output_path(md_path, None)
|
|
35
|
-
|
|
36
|
-
if extend_default_css:
|
|
37
|
-
css_sources = [get_code_css_path(), get_css_path(), css_path]
|
|
38
|
-
else:
|
|
39
|
-
css_sources = [get_code_css_path(), css_path]
|
|
40
|
-
|
|
41
|
-
css_sources = drop_duplicates(css_sources)
|
|
42
|
-
|
|
43
|
-
try:
|
|
44
|
-
html = markdown2.markdown_path(md_path,
|
|
45
|
-
extras=MD_EXTENSIONS)
|
|
46
|
-
|
|
47
|
-
(weasyprint
|
|
48
|
-
.HTML(string=html, base_url='.')
|
|
49
|
-
.write_pdf(target=output_path,
|
|
50
|
-
stylesheets=list(css_sources)))
|
|
51
|
-
|
|
52
|
-
except Exception as exc:
|
|
53
|
-
raise RuntimeError(exc) from exc
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def live_convert(md_path, css_path=None, output_path=None,
|
|
57
|
-
*, extend_default_css=True):
|
|
58
|
-
"""
|
|
59
|
-
Convert a markdown file to a pdf file and watch for changes.
|
|
60
|
-
|
|
61
|
-
Args:
|
|
62
|
-
md_path (str): Path to the markdown file.
|
|
63
|
-
css_path (str=None): Path to the CSS file.
|
|
64
|
-
output_path (str=None): Path to the output file.
|
|
65
|
-
extend_default_css (bool=True): Extend the default CSS file.
|
|
66
|
-
"""
|
|
67
|
-
if css_path is None:
|
|
68
|
-
css_path = get_css_path()
|
|
69
|
-
|
|
70
|
-
if output_path is None:
|
|
71
|
-
output_path = get_output_path(md_path, None)
|
|
72
|
-
|
|
73
|
-
live_converter = LiveConverter(md_path, css_path, output_path,
|
|
74
|
-
extend_default_css=extend_default_css,
|
|
75
|
-
loud=True)
|
|
76
|
-
live_converter.observe()
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
def convert_text(md_text, css_text=None,
|
|
80
|
-
*, extend_default_css=True):
|
|
81
|
-
"""
|
|
82
|
-
Convert markdown text to a pdf file.
|
|
83
|
-
|
|
84
|
-
Args:
|
|
85
|
-
md_text (str): Markdown text.
|
|
86
|
-
css_text (str=None): CSS text.
|
|
87
|
-
extend_default_css (bool=True): Extend the default CSS file.
|
|
88
|
-
|
|
89
|
-
Returns:
|
|
90
|
-
PDF file as bytes.
|
|
91
|
-
"""
|
|
92
|
-
default_css = Path(get_css_path()).read_text(encoding='utf-8')
|
|
93
|
-
code_css = Path(get_code_css_path()).read_text(encoding='utf-8')
|
|
94
|
-
|
|
95
|
-
if css_text is None:
|
|
96
|
-
css_text = default_css
|
|
97
|
-
|
|
98
|
-
if extend_default_css:
|
|
99
|
-
css_sources = [code_css, default_css, css_text]
|
|
100
|
-
else:
|
|
101
|
-
css_sources = [code_css, css_text]
|
|
102
|
-
|
|
103
|
-
css_sources = [weasyprint.CSS(string=css)
|
|
104
|
-
for css in drop_duplicates(css_sources)]
|
|
105
|
-
|
|
106
|
-
try:
|
|
107
|
-
html = markdown2.markdown(md_text,
|
|
108
|
-
extras=MD_EXTENSIONS)
|
|
109
|
-
|
|
110
|
-
return (weasyprint
|
|
111
|
-
.HTML(string=html, base_url='.')
|
|
112
|
-
.write_pdf(stylesheets=css_sources))
|
|
113
|
-
|
|
114
|
-
except Exception as exc:
|
|
115
|
-
raise RuntimeError(exc) from exc
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
class LiveConverter():
|
|
119
|
-
"""
|
|
120
|
-
Class to convert a markdown file to a pdf file and watch for changes.
|
|
121
|
-
"""
|
|
122
|
-
|
|
123
|
-
def __init__(self, md_path, css_path, output_path,
|
|
124
|
-
*, extend_default_css=True,
|
|
125
|
-
loud=False):
|
|
126
|
-
"""
|
|
127
|
-
Initialize the LiveConverter class.
|
|
128
|
-
|
|
129
|
-
Args:
|
|
130
|
-
md_path (str): Path to the markdown file.
|
|
131
|
-
css_path (str): Path to the CSS file.
|
|
132
|
-
output_path (str): Path to the output file.
|
|
133
|
-
extend_default_css (bool): Extend the default CSS file.
|
|
134
|
-
"""
|
|
135
|
-
self.md_path = Path(md_path).absolute()
|
|
136
|
-
self.css_path = Path(css_path).absolute()
|
|
137
|
-
self.output_path = output_path
|
|
138
|
-
self.extend_default_css = extend_default_css
|
|
139
|
-
self.loud = loud
|
|
140
|
-
|
|
141
|
-
self.md_last_modified = None
|
|
142
|
-
self.css_last_modified = None
|
|
143
|
-
|
|
144
|
-
def get_last_modified_date(self, file_path):
|
|
145
|
-
"""
|
|
146
|
-
Get the last modified date of a file.
|
|
147
|
-
|
|
148
|
-
Args:
|
|
149
|
-
file_path (str): Path to the file.
|
|
150
|
-
|
|
151
|
-
Returns:
|
|
152
|
-
Last modified date of the file.
|
|
153
|
-
"""
|
|
154
|
-
return os.path.getmtime(file_path)
|
|
155
|
-
|
|
156
|
-
def write_pdf(self):
|
|
157
|
-
"""
|
|
158
|
-
Write the pdf file.
|
|
159
|
-
"""
|
|
160
|
-
convert(self.md_path, self.css_path, self.output_path,
|
|
161
|
-
extend_default_css=self.extend_default_css)
|
|
162
|
-
if self.loud:
|
|
163
|
-
print(f"- PDF file updated: {datetime.now()}", flush=True)
|
|
164
|
-
|
|
165
|
-
def observe(self, poll_interval=1):
|
|
166
|
-
"""
|
|
167
|
-
Observe the markdown and CSS files. Calls write_pdf() when a file is
|
|
168
|
-
modified.
|
|
169
|
-
"""
|
|
170
|
-
self.write_pdf()
|
|
171
|
-
|
|
172
|
-
self.md_last_modified = self.get_last_modified_date(self.md_path)
|
|
173
|
-
self.css_last_modified = self.get_last_modified_date(self.css_path)
|
|
174
|
-
|
|
175
|
-
try:
|
|
176
|
-
while True:
|
|
177
|
-
|
|
178
|
-
md_modified = self.get_last_modified_date(self.md_path)
|
|
179
|
-
css_modified = self.get_last_modified_date(self.css_path)
|
|
180
|
-
|
|
181
|
-
if md_modified != self.md_last_modified or \
|
|
182
|
-
css_modified != self.css_last_modified:
|
|
183
|
-
|
|
184
|
-
self.write_pdf()
|
|
185
|
-
|
|
186
|
-
self.md_last_modified = md_modified
|
|
187
|
-
self.css_last_modified = css_modified
|
|
188
|
-
|
|
189
|
-
time.sleep(poll_interval)
|
|
190
|
-
|
|
191
|
-
except KeyboardInterrupt:
|
|
192
|
-
if self.loud:
|
|
193
|
-
print("\nInterrupted by user.\n", flush=True)
|
|
194
|
-
return
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
This module contains functions that are used to get the output path, the CSS
|
|
3
|
-
path, and the usage message.
|
|
4
|
-
Author: @julynx
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from pathlib import Path
|
|
8
|
-
|
|
9
|
-
import pkg_resources
|
|
10
|
-
|
|
11
|
-
from .constants import BLUE, CYAN, GREEN, YELLOW, OPTIONS, OPTIONS_MODES
|
|
12
|
-
from .utils import color
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def get_output_path(md_path, output_dir=None):
|
|
16
|
-
"""
|
|
17
|
-
Get the output path for the pdf file.
|
|
18
|
-
|
|
19
|
-
Args:
|
|
20
|
-
md_path (str): The path to the markdown file.
|
|
21
|
-
output_dir (str): The output directory.
|
|
22
|
-
|
|
23
|
-
Returns:
|
|
24
|
-
str: The output path.
|
|
25
|
-
"""
|
|
26
|
-
md_path = Path(md_path)
|
|
27
|
-
|
|
28
|
-
if output_dir is None:
|
|
29
|
-
return md_path.parent / f"{md_path.stem}.pdf"
|
|
30
|
-
|
|
31
|
-
output_dir = Path(output_dir)
|
|
32
|
-
|
|
33
|
-
if output_dir.suffix == ".pdf":
|
|
34
|
-
return output_dir
|
|
35
|
-
|
|
36
|
-
return output_dir.parent / f"{Path(md_path).stem}.pdf"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def get_css_path():
|
|
40
|
-
"""
|
|
41
|
-
Get the path to the default CSS file.
|
|
42
|
-
|
|
43
|
-
Returns:
|
|
44
|
-
str: The path to the default CSS file.
|
|
45
|
-
"""
|
|
46
|
-
return pkg_resources.resource_filename('markdown_convert',
|
|
47
|
-
'default.css')
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def get_code_css_path():
|
|
51
|
-
"""
|
|
52
|
-
Get the path to the code CSS file.
|
|
53
|
-
|
|
54
|
-
Returns:
|
|
55
|
-
str: The path to the code CSS file.
|
|
56
|
-
"""
|
|
57
|
-
return pkg_resources.resource_filename('markdown_convert',
|
|
58
|
-
'code.css')
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def get_usage():
|
|
62
|
-
"""
|
|
63
|
-
Returns a message describing how to use the program.
|
|
64
|
-
|
|
65
|
-
Returns:
|
|
66
|
-
str: The usage message.
|
|
67
|
-
"""
|
|
68
|
-
commd = (f"{color(GREEN, 'markdown-convert')} "
|
|
69
|
-
f"[{color(YELLOW, OPTIONS[0])}] [{color(BLUE, 'options')}]")
|
|
70
|
-
opt_1 = f"{color(BLUE, OPTIONS[1])}{color(CYAN, '=')}{color(CYAN, '|'.join(OPTIONS_MODES))}"
|
|
71
|
-
opt_2 = f"{color(BLUE, OPTIONS[2])}{color(CYAN, '=')}[{color(CYAN, 'css_file_path')}]"
|
|
72
|
-
opt_3 = f"{color(BLUE, OPTIONS[3])}{color(CYAN, '=')}[{color(CYAN, 'output_file_path')}]"
|
|
73
|
-
|
|
74
|
-
usage = ("\n"
|
|
75
|
-
"Usage:\n"
|
|
76
|
-
f" {commd}\n"
|
|
77
|
-
"\n"
|
|
78
|
-
"Options:\n"
|
|
79
|
-
f" {opt_1}\n"
|
|
80
|
-
" Convert the markdown file once (default) or live.\n"
|
|
81
|
-
f" {opt_2}\n"
|
|
82
|
-
" Use a custom CSS file.\n"
|
|
83
|
-
f" {opt_3}\n"
|
|
84
|
-
" Specify the output file path.\n")
|
|
85
|
-
return usage
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Utility functions for string manipulation.
|
|
3
|
-
Author: @julynx
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
import platform
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def color(color_code, text):
|
|
10
|
-
"""
|
|
11
|
-
Colorize text.
|
|
12
|
-
|
|
13
|
-
Args:
|
|
14
|
-
text (str): The text to colorize.
|
|
15
|
-
color (str): The color code.
|
|
16
|
-
|
|
17
|
-
Returns:
|
|
18
|
-
str: The colorized text.
|
|
19
|
-
"""
|
|
20
|
-
|
|
21
|
-
# Disable if running on Windows
|
|
22
|
-
if platform.system() == "Windows":
|
|
23
|
-
return text
|
|
24
|
-
|
|
25
|
-
return f"\033[{color_code}m{text}\033[0m"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def drop_duplicates(lst):
|
|
29
|
-
"""
|
|
30
|
-
Drops duplicates from the given list.
|
|
31
|
-
|
|
32
|
-
Args:
|
|
33
|
-
lst: List to remove duplicates from.
|
|
34
|
-
|
|
35
|
-
Returns:
|
|
36
|
-
List without duplicates.
|
|
37
|
-
"""
|
|
38
|
-
return list(dict.fromkeys(lst))
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
This module contains functions to validate the input paths.
|
|
3
|
-
Author: @julynx
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def validate_markdown_path(md_path):
|
|
10
|
-
"""
|
|
11
|
-
Validate the markdown file path.
|
|
12
|
-
|
|
13
|
-
Args:
|
|
14
|
-
md_path (str): The path to the markdown file.
|
|
15
|
-
|
|
16
|
-
Raises:
|
|
17
|
-
FileNotFoundError: If the file is not found.
|
|
18
|
-
ValueError: If the file is not a Markdown file.
|
|
19
|
-
"""
|
|
20
|
-
if not Path(md_path).is_file():
|
|
21
|
-
raise FileNotFoundError(f"File not found: '{md_path}'")
|
|
22
|
-
|
|
23
|
-
if not md_path.endswith(".md"):
|
|
24
|
-
raise ValueError("File must be a Markdown file.")
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def validate_css_path(css_path):
|
|
28
|
-
"""
|
|
29
|
-
Validate the CSS file path.
|
|
30
|
-
|
|
31
|
-
Args:
|
|
32
|
-
css_path (str): The path to the CSS file.
|
|
33
|
-
|
|
34
|
-
Raises:
|
|
35
|
-
FileNotFoundError: If the file is not found.
|
|
36
|
-
ValueError: If the file is not a CSS file.
|
|
37
|
-
"""
|
|
38
|
-
if not Path(css_path).is_file():
|
|
39
|
-
raise FileNotFoundError(f"File not found: '{css_path}'")
|
|
40
|
-
|
|
41
|
-
if not css_path.endswith(".css"):
|
|
42
|
-
raise ValueError("File must be a CSS file.")
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def validate_output_path(output_dir):
|
|
46
|
-
"""
|
|
47
|
-
Validate the output directory path.
|
|
48
|
-
|
|
49
|
-
Args:
|
|
50
|
-
output_dir (str): The path to the output directory.
|
|
51
|
-
|
|
52
|
-
Raises:
|
|
53
|
-
FileNotFoundError: If the directory is not found.
|
|
54
|
-
"""
|
|
55
|
-
check_dir = Path(output_dir)
|
|
56
|
-
|
|
57
|
-
if output_dir.endswith(".pdf"):
|
|
58
|
-
check_dir = check_dir.parent
|
|
59
|
-
|
|
60
|
-
if not check_dir.is_dir():
|
|
61
|
-
raise FileNotFoundError(f"Directory not found: '{check_dir}'")
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
markdown_convert/__init__.py,sha256=2SJONchNVFwEFhEzbrWpspdblKL8mjEuoL6P8upEJo4,221
|
|
2
|
-
markdown_convert/__main__.py,sha256=5DOUdG24S4Oal68DLr-HHaK1NGGFlWXJs0Lvl72IrqM,2911
|
|
3
|
-
markdown_convert/code.css,sha256=ZQtsG8A0lgzA44m7qJ4HjbOX5y8eSWwsgMCj3R3WkwM,5008
|
|
4
|
-
markdown_convert/default.css,sha256=Ke6r5X7M6c5czCrjTK9FXCbNj_XfFEi7ArYxE2r_Ae0,9010
|
|
5
|
-
markdown_convert/modules/__init__.py,sha256=pWf-8UfjDRbkY5VdV8SOpEuIXpEW_X9o_k4j8mJnNkQ,69
|
|
6
|
-
markdown_convert/modules/constants.py,sha256=qNN0Li-1Yn719_NqNBlOs0oyLRtOXfI4cCowez41MSE,480
|
|
7
|
-
markdown_convert/modules/convert.py,sha256=yqvZW3ZkZP-9btjFsY2GVwkQw_Vqf251fKLN7c1nJh0,5905
|
|
8
|
-
markdown_convert/modules/resources.py,sha256=wlSZFz3m59Kx0t2rgB9Stw42T4kaPUKsQnZ0C4q9JOU,2343
|
|
9
|
-
markdown_convert/modules/utils.py,sha256=2bWwxxdnC7JYXvbSZvMnBTkdqasgcpjkRKfzVnQ_Y44,693
|
|
10
|
-
markdown_convert/modules/validate.py,sha256=HrDEObogR3QYkWVEYISS_il6-npWyKr_6-JRiDJK-94,1548
|
|
11
|
-
markdown_convert-1.2.7.dist-info/entry_points.txt,sha256=pIlZtfDV_ZjhRjEWcNIuLa1aZOiktJjHFwYuzKkL61A,67
|
|
12
|
-
markdown_convert-1.2.7.dist-info/LICENSE,sha256=GJsa-V1mEVHgVM6hDJGz11Tk3k0_7PsHTB-ylHb3Fns,18431
|
|
13
|
-
markdown_convert-1.2.7.dist-info/METADATA,sha256=ueGWQsetSm1b_l1EfHQkWVOuEmphylOSQKD2k2ORpss,3369
|
|
14
|
-
markdown_convert-1.2.7.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
15
|
-
markdown_convert-1.2.7.dist-info/RECORD,,
|
|
File without changes
|