-
Notifications
You must be signed in to change notification settings - Fork 8
/
markup2html.py
executable file
·47 lines (39 loc) · 1.21 KB
/
markup2html.py
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
#!/usr/bin/env python3
import argparse
import sys
import markups
def export_file(args: argparse.Namespace) -> None:
markup = markups.get_markup_for_file_name(args.input_file)
with open(args.input_file) as fp:
text = fp.read()
if not markup:
sys.exit("Markup not available.")
converted = markup.convert(text)
html = converted.get_whole_html(
include_stylesheet=args.include_stylesheet,
fallback_title=args.fallback_title,
webenv=args.web_environment,
)
with open(args.output_file, "w") as output:
output.write(html)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--web-environment",
help="export for web environment",
action="store_true",
)
parser.add_argument(
"--include-stylesheet",
help="embed the stylesheet into html",
action="store_true",
)
parser.add_argument(
"--fallback-title",
help="fallback title of the HTML document",
metavar="TITLE",
)
parser.add_argument("input_file", help="input file")
parser.add_argument("output_file", help="output file")
args = parser.parse_args()
export_file(args)