-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
50 lines (44 loc) · 1.64 KB
/
Copy pathcli.py
File metadata and controls
50 lines (44 loc) · 1.64 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
47
48
49
50
import argparse
import sys
from .html import html
from .text import text
from .exceptions import HypermarkError
def main() -> None:
"""Main CLI entry point for compiling Markdown files via terminal commands."""
parser = argparse.ArgumentParser(
description="Hypermark - Fast and Modular Markdown to HTML/TTS-Text Compiler."
)
parser.add_argument("input", help="Path to the input Markdown (.md) file.")
parser.add_argument("output", help="Path to the output compiled file.")
parser.add_argument(
"--style", "-s",
default="default",
help="Stylesheet for HTML compilation (either 'default' or path to custom CSS). Default is 'default'."
)
parser.add_argument(
"--text", "-t",
action="store_true",
help="Compile directly to plain text optimized for TTS engines instead of HTML."
)
args = parser.parse_args()
try:
if args.text:
text(args.input, args.output)
print(f"Successfully compiled Markdown to Plain Text at: {args.output}")
else:
html(args.input, args.output, args.style)
print(f"Successfully compiled Markdown to HTML at: {args.output}")
except FileNotFoundError as e:
print(f"File Error: {e}", file=sys.stderr)
sys.exit(2)
except PermissionError as e:
print(f"Permission Error: {e}", file=sys.stderr)
sys.exit(3)
except HypermarkError as e:
print(f"Compiler Error: {e}", file=sys.stderr)
sys.exit(4)
except Exception as e:
print(f"Unexpected Error: {e}", file=sys.stderr)
sys.exit(5)
if __name__ == "__main__":
main()