From: Wayne Davison Date: Sun, 14 Jun 2020 07:01:59 +0000 (-0700) Subject: Add handling of non-breaking space & double-dash. X-Git-Tag: v3.2.0pre2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b65b6db3048222137e4695c1aa8f86f61bcf313b;p=thirdparty%2Frsync.git Add handling of non-breaking space & double-dash. --- diff --git a/md2man b/md2man index c914cd96..8736dd1c 100755 --- a/md2man +++ b/md2man @@ -151,6 +151,7 @@ class HtmlToManPage(HTMLParser): at_first_tag_in_dd = False, dt_from = None, in_pre = False, + in_code = False, html_out = [ HTML_START % fi.title ], man_out = [ MAN_START % fi.man_headings ], txt = '', @@ -200,6 +201,7 @@ class HtmlToManPage(HTMLParser): st.in_pre = True st.man_out.append(st.p_macro + ".nf\n") elif tag == 'code' and not st.in_pre: + st.in_code = True st.txt += BOLD_FONT[0] elif tag == 'strong' or tag == 'b': st.txt += BOLD_FONT[0] @@ -266,7 +268,10 @@ class HtmlToManPage(HTMLParser): elif tag == 'pre': st.in_pre = False st.man_out.append(manify(txt) + "\n.fi\n") - elif (tag == 'code' and not st.in_pre) or tag == 'strong' or tag == 'b': + elif (tag == 'code' and not st.in_pre): + st.in_code = False + add_to_txt = NORM_FONT[0] + elif tag == 'strong' or tag == 'b': add_to_txt = NORM_FONT[0] elif tag == 'em' or tag == 'i': tag = 'u' # Change it into underline to be more like the man page @@ -299,6 +304,9 @@ class HtmlToManPage(HTMLParser): st = self.state if args.debug: self.output_debug('DATA', (data,)) + if st.in_code: + data = re.sub(r'\s', '\xa0', data) # nbsp in non-pre code + data = re.sub(r'\s--\s', '\xa0-- ', data) st.html_out.append(htmlify(data)) st.txt += data @@ -318,13 +326,15 @@ class HtmlToManPage(HTMLParser): def manify(txt): return re.sub(r"^(['.])", r'\&\1', txt.replace('\\', '\\\\') + .replace("\xa0", r'\ ') # non-breaking space + .replace('--', r'\-\-') # non-breaking double dash .replace(NORM_FONT[0], NORM_FONT[1]) .replace(BOLD_FONT[0], BOLD_FONT[1]) .replace(ULIN_FONT[0], ULIN_FONT[1]), flags=re.M) def htmlify(txt): - return txt.replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"') + return txt.replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("\xa0", ' ') def warn(*msg): diff --git a/packaging/md2html b/packaging/md2html index f0f61cdc..6c944458 100755 --- a/packaging/md2html +++ b/packaging/md2html @@ -52,8 +52,13 @@ def main(): with open(mdfn, 'r', encoding='utf-8') as fh: txt = fh.read() + txt = re.sub(r'\s--\s', '\xa0-- ', txt) + html = md_parser(txt) + html = re.sub(r'()([\s\S]*?)()', lambda m: m[1] + re.sub(r'\s', '\xa0', m[2]) + m[3], html) + html = html.replace("\xa0", ' ') + with open(htfn, 'w', encoding='utf-8') as fh: fh.write(HTML_START % title) fh.write(html)