]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
A few more md -> html improvements
authorWayne Davison <wayne@opencoder.net>
Mon, 15 Jun 2020 01:28:30 +0000 (18:28 -0700)
committerWayne Davison <wayne@opencoder.net>
Mon, 15 Jun 2020 01:28:30 +0000 (18:28 -0700)
md2man
packaging/md2html

diff --git a/md2man b/md2man
index 8736dd1c079b0a7453e25c9f3b9e957b2c11e0d5..7ee63f53dc03dec39b4c0fbf7e6f36b103e02e4a 100755 (executable)
--- a/md2man
+++ b/md2man
@@ -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):
index 6c944458a8273fa86fa45248cff3c7af63a7d56d..a1613aa75bd761c7d86733b58e9bad0090322024 100755 (executable)
@@ -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)