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 = '',
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]
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
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
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):
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'(<code>)([\s\S]*?)(</code>)', 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)