doc: add generic frontend to rst2man and rst2html

This will allow us to easily register new roles and directives.
This commit is contained in:
Martin Geisler 2010-04-22 09:57:04 +02:00
parent 5fb4657cce
commit ce3c2717e9
6 changed files with 51 additions and 34 deletions

View File

@ -6,7 +6,6 @@ PREFIX=/usr/local
MANDIR=$(PREFIX)/share/man
INSTALL=install -c -m 644
PYTHON=python
RST2HTML=$(shell which rst2html 2> /dev/null || echo rst2html.py)
export LANGUAGE=C
export LC_ALL=C
@ -25,11 +24,11 @@ hg.1.gendoc.txt: $(GENDOC)
mv $@.tmp $@
%: %.txt common.txt
$(PYTHON) rst2man.py --halt warning \
$(PYTHON) runrst manpage --halt warning \
--strip-elements-with-class htmlonly $*.txt $*
%.html: %.txt common.txt
$(RST2HTML) --halt warning \
$(PYTHON) runrst html --halt warning \
--link-stylesheet --stylesheet-path style.css $*.txt $*.html
MANIFEST: man html

7
doc/rst2man.py → doc/manpage.py Executable file → Normal file
View File

@ -1099,11 +1099,4 @@ class Translator(nodes.NodeVisitor):
raise NotImplementedError('visiting unimplemented node type: %s'
% node.__class__.__name__)
# The following part is taken from the Docutils rst2man.py script:
if __name__ == "__main__":
from docutils.core import publish_cmdline, default_description
description = ("Generates plain unix manual documents. " +
default_description)
publish_cmdline(writer=Writer(), description=description)
# vim: set fileencoding=utf-8 et ts=4 ai :

26
doc/runrst Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env python
#
# runrst - register custom roles and run correct writer
#
# Copyright 2010 Matt Mackall <mpm@selenic.com> and others
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
"""usage: %s WRITER args...
where WRITER is the name of a Docutils writer such as 'html' or 'manpage'
"""
import sys
from docutils.core import publish_cmdline
if __name__ == "__main__":
if len(sys.argv) < 2:
sys.stderr.write(__doc__ % sys.argv[0])
sys.exit(1)
writer = sys.argv[1]
del sys.argv[1]
publish_cmdline(writer_name=writer)

View File

@ -120,12 +120,12 @@ def has_lsprof():
def has_git():
return matchoutput('git --version 2>&1', r'^git version')
def has_rst2html():
for name in ('rst2html', 'rst2html.py'):
name = name + ' --version 2>&1'
if matchoutput(name, r'^rst2html(?:\.py)? \(Docutils'):
return True
return False
def has_docutils():
try:
from docutils.core import publish_cmdline
return True
except ImportError:
return False
def has_svn():
return matchoutput('svn --version 2>&1', r'^svn, version') and \
@ -198,7 +198,7 @@ checks = {
"outer-repo": (has_outer_repo, "outer repo"),
"p4": (has_p4, "Perforce server and client"),
"pygments": (has_pygments, "Pygments source highlighting library"),
"rst2html": (has_rst2html, "Docutils rst2html tool"),
"docutils": (has_docutils, "Docutils text processing library"),
"svn": (has_svn, "subversion client and admin tools"),
"svn-bindings": (has_svn_bindings, "subversion python bindings"),
"symlink": (has_symlink, "symbolic links"),

View File

@ -1,7 +1,6 @@
#!/bin/sh
"$TESTDIR/hghave" rst2html || exit 80
RST2HTML=`which rst2html 2> /dev/null || which rst2html.py`
"$TESTDIR/hghave" docutils || exit 80
HGENCODING=UTF-8
export HGENCODING
@ -14,8 +13,8 @@ for PO in C $TESTDIR/../i18n/*.po; do
echo "" >> gendoc-$LOCALE.txt
LC_ALL=$LOCALE python $TESTDIR/../doc/gendoc.py >> gendoc-$LOCALE.txt || exit
# We run rst2html over the file without adding "--halt warning" to
# make it report all errors instead of stopping on the first one.
echo "checking for parse errors with rst2html"
$RST2HTML gendoc-$LOCALE.txt /dev/null
# We call runrst without adding "--halt warning" to make it report
# all errors instead of stopping on the first one.
echo "checking for parse errors"
python $TESTDIR/../doc/runrst html gendoc-$LOCALE.txt /dev/null
done

View File

@ -1,33 +1,33 @@
% extracting documentation from C
checking for parse errors with rst2html
checking for parse errors
% extracting documentation from da
checking for parse errors with rst2html
checking for parse errors
% extracting documentation from de
checking for parse errors with rst2html
checking for parse errors
% extracting documentation from el
checking for parse errors with rst2html
checking for parse errors
% extracting documentation from fr
checking for parse errors with rst2html
checking for parse errors
% extracting documentation from it
checking for parse errors with rst2html
checking for parse errors
% extracting documentation from ja
checking for parse errors with rst2html
checking for parse errors
% extracting documentation from pt_BR
checking for parse errors with rst2html
checking for parse errors
% extracting documentation from sv
checking for parse errors with rst2html
checking for parse errors
% extracting documentation from zh_CN
checking for parse errors with rst2html
checking for parse errors
% extracting documentation from zh_TW
checking for parse errors with rst2html
checking for parse errors