3 # Copyright (C) 2020 Wayne Davison
5 # This program is freely redistributable.
7 import os, re, argparse
12 <link href="https://fonts.googleapis.com/css2?family=Roboto&family=Roboto+Mono&display=swap" rel="stylesheet">
19 font-family: 'Roboto', sans-serif;
22 font-family: 'Roboto Mono', monospace;
33 margin-block-start: 0em;
40 border-top: 1px solid grey;
43 background-color: #f6f8fa;
46 border: 1px solid #dfe2e5;
62 for mdfn in args.mdfiles:
63 if not mdfn.endswith('.md'):
64 print('Ignoring non-md input file:', mdfn)
66 title = re.sub(r'.*/', '', mdfn).replace('.md', '')
67 htfn = mdfn.replace('.md', '.html')
69 print("Parsing", mdfn, '->', htfn)
71 with open(mdfn, 'r', encoding='utf-8') as fh:
74 txt = re.sub(r'\s--\s', '\xa0-- ', txt)
78 html = re.sub(r'(?<!<pre>)(<code>)([\s\S]*?)(</code>)', lambda m: m[1] + re.sub(r'\s', '\xa0', m[2]) + m[3], html)
79 html = html.replace('--', '‑‑').replace("\xa0-", ' ‑').replace("\xa0", ' ')
80 html = re.sub(r'(\W)-', r'\1‑', html)
82 if os.path.lexists(htfn):
85 with open(htfn, 'w', encoding='utf-8') as fh:
86 fh.write(HTML_START % title)
91 if __name__ == '__main__':
92 parser = argparse.ArgumentParser(description='Output html for md pages.', add_help=False)
93 parser.add_argument("--help", "-h", action="help", help="Output this help message and exit.")
94 parser.add_argument("mdfiles", nargs='+', help="The .md files to turn into .html files.")
95 args = parser.parse_args()
99 # Our NEWS.md file has a gfm table in it.
100 md_parser = cmarkgfm.github_flavored_markdown_to_html
102 die("Failed to find cmarkgfm for python3.")