1#!/usr/bin/env python3
2
3import argparse
4import markups
5import sys
6
7
8def export_file(args):
9    markup = markups.get_markup_for_file_name(args.input_file)
10    with open(args.input_file) as input:
11        text = input.read()
12    if not markup:
13        sys.exit('Markup not available.')
14    converted = markup.convert(text)
15
16    html = converted.get_whole_html(include_stylesheet=args.include_stylesheet,
17                                    fallback_title=args.fallback_title,
18                                    webenv=args.web_environment)
19
20    with open(args.output_file, 'w') as output:
21        output.write(html)
22
23
24if __name__ == '__main__':
25    parser = argparse.ArgumentParser()
26    parser.add_argument('--web-environment', help='export for web environment',
27                        action='store_true')
28    parser.add_argument('--include-stylesheet', help='embed the stylesheet into html',
29                        action='store_true')
30    parser.add_argument('--fallback-title', help='fallback title of the HTML document',
31                        metavar='TITLE')
32    parser.add_argument('input_file', help='input file')
33    parser.add_argument('output_file', help='output file')
34    args = parser.parse_args()
35    export_file(args)
36