diff options
author | Fred Drake <fdrake@acm.org> | 1999-01-20 20:35:05 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 1999-01-20 20:35:05 (GMT) |
commit | 43278f01dc01b6cc2c0a2a66692de46e3a4fb400 (patch) | |
tree | 16360cfe6fab3bfb43c6f020ef09c8c42020d703 /Doc | |
parent | 0a5b8de5e2e948398e76d937e15e0518945fc49b (diff) | |
download | cpython-43278f01dc01b6cc2c0a2a66692de46e3a4fb400.zip cpython-43278f01dc01b6cc2c0a2a66692de46e3a4fb400.tar.gz cpython-43278f01dc01b6cc2c0a2a66692de46e3a4fb400.tar.bz2 |
convert(): Added parameter "autoclose", which should be a sequence of
general identifiers for which closing tags will be omitted
when SGML is generated. This can be used to tell the markup
generator to drop stuff like </para>. Note that it needs to
be possible for the closing tag to *always* be omitted for it
to be included in "autoclose".
main(): Added command-line option "-a" / "--autoclose" to set the
list of general identifiers passed to the convert() function
as the "autoclose" parameter. The list may only be specified
once (not additive) and GIs should be comma-separated. The
default list includes only "para".
Diffstat (limited to 'Doc')
-rwxr-xr-x | Doc/tools/sgmlconv/esis2sgml.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/Doc/tools/sgmlconv/esis2sgml.py b/Doc/tools/sgmlconv/esis2sgml.py index b8050c8..002967a 100755 --- a/Doc/tools/sgmlconv/esis2sgml.py +++ b/Doc/tools/sgmlconv/esis2sgml.py @@ -47,7 +47,9 @@ def istoken(s): return _token_rx.match(s) is not None -def do_convert(ifp, ofp, xml=0): +def do_convert(ifp, ofp, xml=0, autoclose=()): + if xml: + autoclose = () attrs = {} lastopened = None knownempties = [] @@ -92,7 +94,9 @@ def do_convert(ifp, ofp, xml=0): if not lastempty: ofp.write("</%s>" % data) elif data not in knownempties: - if lastopened == data: + if data in autoclose: + pass + elif lastopened == data: ofp.write("</>") else: ofp.write("</%s>" % data) @@ -115,28 +119,35 @@ def do_convert(ifp, ofp, xml=0): fp.close() -def sgml_convert(ifp, ofp): - return do_convert(ifp, ofp, xml=0) +def sgml_convert(ifp, ofp, autoclose): + return do_convert(ifp, ofp, xml=0, autoclose=autoclose) -def xml_convert(ifp, ofp): - return do_convert(ifp, ofp, xml=1) +def xml_convert(ifp, ofp, autoclose): + return do_convert(ifp, ofp, xml=1, autoclose=autoclose) + + +AUTOCLOSE = ("para",) def main(): import getopt import sys # + autoclose = AUTOCLOSE convert = sgml_convert xml = 0 xmldecl = 0 - opts, args = getopt.getopt(sys.argv[1:], "dx", ["declare", "xml"]) + opts, args = getopt.getopt(sys.argv[1:], "adx", + ["autoclose", "declare", "xml"]) for opt, arg in opts: if opt in ("-d", "--declare"): xmldecl = 1 elif opt in ("-x", "--xml"): xml = 1 convert = xml_convert + elif opt in ("-a", "--autoclose"): + autoclose = string.split(arg, ",") if len(args) == 0: ifp = sys.stdin ofp = sys.stdout @@ -153,7 +164,7 @@ def main(): try: if xml and xmldecl: opf.write('<?xml version="1.0" encoding="iso8859-1"?>\n') - convert(ifp, ofp) + convert(ifp, ofp, autoclose) except IOError, (err, msg): if err != errno.EPIPE: raise |