Documentation: Fix some markdown formatting bugs.

This commit is contained in:
Avery Pennarun 2018-10-11 05:16:27 -04:00
commit 84fb972fb7
6 changed files with 23 additions and 18 deletions

View file

@ -1,2 +1,3 @@
*.1 *.1
/md-to-man /md-to-man
*.html

View file

@ -1,2 +1 @@
rm -f *~ .*~ *.1 t/*.1 md-to-man *.tmp t/*.tmp rm -f *~ .*~ *.1 t/*.1 md-to-man *.tmp t/*.tmp *.html */*.html

View file

@ -1,6 +1,6 @@
redo-ifchange md2man.py redo-ifchange md2man.py
if ./md2man.py </dev/null >/dev/null; then if ./md2man.py /dev/null /dev/null >/dev/null; then
echo './md2man.py $2.md.tmp' echo './md2man.py $2.md.tmp $2.html'
else else
echo "Warning: md2man.py missing modules; can't generate manpages." >&2 echo "Warning: md2man.py missing modules; can't generate manpages." >&2
echo "Warning: try this: sudo easy_install markdown BeautifulSoup" >&2 echo "Warning: try this: sudo easy_install markdown BeautifulSoup" >&2

View file

@ -132,7 +132,7 @@ def _text(bitlist):
elif typ in ['strong', 'code']: elif typ in ['strong', 'code']:
out += '\\fB%s\\fR' % text out += '\\fB%s\\fR' % text
else: else:
raise ValueError('unexpected tag %r inside %r' % (typ, tag.name)) raise ValueError('unexpected tag %r inside text' % (typ,))
out = out.strip() out = out.strip()
out = re.sub(re.compile(r'^\s+', re.M), '', out) out = re.sub(re.compile(r'^\s+', re.M), '', out)
return out return out
@ -175,6 +175,7 @@ def do_definition(tag):
pre.append((typ,text)) pre.append((typ,text))
_boldline(pre) _boldline(pre)
w.write(_text(post)) w.write(_text(post))
w.started = False
def do_list(tag): def do_list(tag):
@ -187,6 +188,7 @@ def do_list(tag):
else: else:
w.start_bullet() w.start_bullet()
for xi in i: for xi in i:
if str(xi).strip():
do(xi) do(xi)
w.end_para() w.end_para()
w.end_bullet() w.end_bullet()
@ -215,7 +217,7 @@ def do(tag):
macro('.RE') macro('.RE')
w.end_para() w.end_para()
elif name == 'p' or name == 'br': elif name == 'p' or name == 'br':
g = re.match(re.compile(r'([^\n]*)\n +: +(.*)', re.S), str(tag)) g = re.match(re.compile(r'([^\n]*)\n *: +(.*)', re.S), str(tag))
if g: if g:
# it's a definition list (which some versions of python-markdown # it's a definition list (which some versions of python-markdown
# don't support, including the one in Debian-lenny, so we can't # don't support, including the one in Debian-lenny, so we can't
@ -238,11 +240,13 @@ DATE=''
AUTHOR='' AUTHOR=''
lines = [] lines = []
if len(sys.argv) > 1: if len(sys.argv) != 3:
for n in sys.argv[1:]: sys.stderr.write('usage: %s <infile.md> <outfile.html> >outfile.1\n')
lines += open(n).read().decode('utf8').split('\n') sys.exit(99)
else:
lines += sys.stdin.read().decode('utf8').split('\n') infile = sys.argv[1]
htmlfile = sys.argv[2]
lines += open(infile).read().decode('utf8').split('\n')
# parse pandoc-style document headers (not part of markdown) # parse pandoc-style document headers (not part of markdown)
g = re.match(r'^%\s+(.*?)\((.*?)\)\s+(.*)$', lines[0]) g = re.match(r'^%\s+(.*?)\((.*?)\)\s+(.*)$', lines[0])
@ -266,9 +270,10 @@ if g:
inp = '\n'.join(lines) inp = '\n'.join(lines)
if AUTHOR: if AUTHOR:
inp += ('\n# AUTHOR\n\n%s\n' % AUTHOR).replace('<', '\\<') inp += ('\n# AUTHOR\n\n%s\n' % AUTHOR).replace('<', '&lt;')
html = markdown.markdown(inp) html = markdown.markdown(inp)
open(htmlfile, 'w').write(html)
soup = BeautifulSoup(html, convertEntities=BeautifulSoup.HTML_ENTITIES) soup = BeautifulSoup(html, convertEntities=BeautifulSoup.HTML_ENTITIES)
macro('.TH', PROD.upper(), SECTION, DATE, VENDOR, GROUPNAME) macro('.TH', PROD.upper(), SECTION, DATE, VENDOR, GROUPNAME)

View file

@ -33,8 +33,8 @@ The list is not filtered in any way; it contains *all* the
target filenames from the entire project. Remember that target filenames from the entire project. Remember that
the redo database may span more than just your project, so the redo database may span more than just your project, so
you might need to filter the list before using it. (A you might need to filter the list before using it. (A
useful heuristic might be to remove any line starting with useful heuristic might be to remove any line starting
'../' since it often refers to a target you don't care with '../' since it often refers to a target you don't care
about.) about.)
If you want a list of all targets, not just out-of-date If you want a list of all targets, not just out-of-date

View file

@ -8,7 +8,7 @@ redo-stamp - detect if the current target has meaningfully changed
# SYNOPSIS # SYNOPSIS
redo-stamp <\$3 redo-stamp <$3
# DESCRIPTION # DESCRIPTION
@ -33,7 +33,7 @@ are:
- the actual target file contents: - the actual target file contents:
redo-stamp <\$3 redo-stamp <$3
- a list of filenames: - a list of filenames: