A few more md -> html improvements

This commit is contained in:
Wayne Davison
2020-06-14 18:28:30 -07:00
parent 59cf9ff797
commit 660274bfb7
2 changed files with 8 additions and 2 deletions

4
md2man
View File

@@ -334,7 +334,9 @@ def manify(txt):
def htmlify(txt):
return txt.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("\xa0", '&nbsp;')
return re.sub(r'(\W)-', r'\1&#8209;',
txt.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;')
.replace('--', '&#8209;&#8209;').replace("\xa0-", '&nbsp;&#8209;').replace("\xa0", '&nbsp;'))
def warn(*msg):

View File

@@ -44,6 +44,9 @@ md_parser = None
def main():
for mdfn in args.mdfiles:
if not mdfn.endswith('.md'):
print('Ignoring non-md input file:', mdfn)
continue
title = re.sub(r'.*/', '', mdfn).replace('.md', '')
htfn = mdfn.replace('.md', '.html')
@@ -57,7 +60,8 @@ def main():
html = md_parser(txt)
html = re.sub(r'(<code>)([\s\S]*?)(</code>)', lambda m: m[1] + re.sub(r'\s', '\xa0', m[2]) + m[3], html)
html = html.replace("\xa0", '&nbsp;')
html = html.replace('--', '&#8209;&#8209;').replace("\xa0-", '&nbsp;&#8209;').replace("\xa0", '&nbsp;')
html = re.sub(r'(\W)-', r'\1&#8209;', html)
with open(htfn, 'w', encoding='utf-8') as fh:
fh.write(HTML_START % title)