From 84fb972fb72c94f0a77e66ddef0a8cedb52cc6fb Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Thu, 11 Oct 2018 05:16:27 -0400 Subject: [PATCH] Documentation: Fix some markdown formatting bugs. --- Documentation/.gitignore | 1 + Documentation/clean.do | 3 +-- Documentation/md-to-man.do | 4 ++-- Documentation/md2man.py | 25 +++++++++++++++---------- Documentation/redo-ood.md | 4 ++-- Documentation/redo-stamp.md | 4 ++-- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Documentation/.gitignore b/Documentation/.gitignore index 16e7185..e89be4c 100644 --- a/Documentation/.gitignore +++ b/Documentation/.gitignore @@ -1,2 +1,3 @@ *.1 /md-to-man +*.html diff --git a/Documentation/clean.do b/Documentation/clean.do index 78c7bf7..698c784 100644 --- a/Documentation/clean.do +++ b/Documentation/clean.do @@ -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 diff --git a/Documentation/md-to-man.do b/Documentation/md-to-man.do index 2b08acf..e0fb727 100644 --- a/Documentation/md-to-man.do +++ b/Documentation/md-to-man.do @@ -1,6 +1,6 @@ redo-ifchange md2man.py -if ./md2man.py /dev/null; then - echo './md2man.py $2.md.tmp' +if ./md2man.py /dev/null /dev/null >/dev/null; then + echo './md2man.py $2.md.tmp $2.html' else echo "Warning: md2man.py missing modules; can't generate manpages." >&2 echo "Warning: try this: sudo easy_install markdown BeautifulSoup" >&2 diff --git a/Documentation/md2man.py b/Documentation/md2man.py index 54c1918..1be13b1 100755 --- a/Documentation/md2man.py +++ b/Documentation/md2man.py @@ -132,7 +132,7 @@ def _text(bitlist): elif typ in ['strong', 'code']: out += '\\fB%s\\fR' % text else: - raise ValueError('unexpected tag %r inside %r' % (typ, tag.name)) + raise ValueError('unexpected tag %r inside text' % (typ,)) out = out.strip() out = re.sub(re.compile(r'^\s+', re.M), '', out) return out @@ -175,6 +175,7 @@ def do_definition(tag): pre.append((typ,text)) _boldline(pre) w.write(_text(post)) + w.started = False def do_list(tag): @@ -187,8 +188,9 @@ def do_list(tag): else: w.start_bullet() for xi in i: - do(xi) - w.end_para() + if str(xi).strip(): + do(xi) + w.end_para() w.end_bullet() @@ -215,7 +217,7 @@ def do(tag): macro('.RE') w.end_para() 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: # it's a definition list (which some versions of python-markdown # don't support, including the one in Debian-lenny, so we can't @@ -238,11 +240,13 @@ DATE='' AUTHOR='' lines = [] -if len(sys.argv) > 1: - for n in sys.argv[1:]: - lines += open(n).read().decode('utf8').split('\n') -else: - lines += sys.stdin.read().decode('utf8').split('\n') +if len(sys.argv) != 3: + sys.stderr.write('usage: %s >outfile.1\n') + sys.exit(99) + +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) g = re.match(r'^%\s+(.*?)\((.*?)\)\s+(.*)$', lines[0]) @@ -266,9 +270,10 @@ if g: inp = '\n'.join(lines) if AUTHOR: - inp += ('\n# AUTHOR\n\n%s\n' % AUTHOR).replace('<', '\\<') + inp += ('\n# AUTHOR\n\n%s\n' % AUTHOR).replace('<', '<') html = markdown.markdown(inp) +open(htmlfile, 'w').write(html) soup = BeautifulSoup(html, convertEntities=BeautifulSoup.HTML_ENTITIES) macro('.TH', PROD.upper(), SECTION, DATE, VENDOR, GROUPNAME) diff --git a/Documentation/redo-ood.md b/Documentation/redo-ood.md index 823f651..b425378 100644 --- a/Documentation/redo-ood.md +++ b/Documentation/redo-ood.md @@ -33,8 +33,8 @@ The list is not filtered in any way; it contains *all* the target filenames from the entire project. Remember that the redo database may span more than just your project, so you might need to filter the list before using it. (A -useful heuristic might be to remove any line starting with -'../' since it often refers to a target you don't care +useful heuristic might be to remove any line starting +with '../' since it often refers to a target you don't care about.) If you want a list of all targets, not just out-of-date diff --git a/Documentation/redo-stamp.md b/Documentation/redo-stamp.md index 2cf7bc8..b723a96 100644 --- a/Documentation/redo-stamp.md +++ b/Documentation/redo-stamp.md @@ -8,7 +8,7 @@ redo-stamp - detect if the current target has meaningfully changed # SYNOPSIS -redo-stamp <\$3 +redo-stamp <$3 # DESCRIPTION @@ -33,7 +33,7 @@ are: - the actual target file contents: - redo-stamp <\$3 + redo-stamp <$3 - a list of filenames: