-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.py
More file actions
46 lines (38 loc) · 1.37 KB
/
Copy pathcli.py
File metadata and controls
46 lines (38 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
import argparse
from md2htmlify import MarkdownConverter # Import the updated class-based converter
def main():
"""
CLI script to convert Markdown text (provided as an argument or via stdin) to HTML.
Libraries are stored in ~/.lib by default, but can be overridden with --lib-dir.
"""
parser = argparse.ArgumentParser(description="Convert Markdown text to HTML.")
parser.add_argument(
"--markdown-text",
type=str,
required=True,
help="The Markdown text to convert. If not provided, the converter will read Markdown from stdin."
)
parser.add_argument(
"--lib-dir",
type=str,
default="",
required=False,
help="Path to the library directory. Defaults to ~/.lib if not specified."
)
parser.add_argument(
"--use-cdn",
action="store_true",
default=False,
help="Use CDN for dependencies (MathJax, Tailwind) instead of local libs."
)
args = parser.parse_args()
markdown_text = args.markdown_text
# Create converter instance
converter = MarkdownConverter(lib_dir=args.lib_dir)
# Convert the Markdown text to HTML
html_output = converter.convert_markdown_to_html(markdown_text, use_cdn=args.use_cdn)
# Print the resulting HTML to stdout
print(html_output)
if __name__ == "__main__":
main()