From: Fred Drake Date: Wed, 20 Jan 1999 20:35:05 +0000 (+0000) Subject: convert(): Added parameter "autoclose", which should be a sequence of X-Git-Tag: v1.5.2b2~309 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=43278f01dc01b6cc2c0a2a66692de46e3a4fb400;p=python 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 . 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". --- diff --git a/Doc/tools/sgmlconv/esis2sgml.py b/Doc/tools/sgmlconv/esis2sgml.py index b8050c85cc..002967a246 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("" % data) elif data not in knownempties: - if lastopened == data: + if data in autoclose: + pass + elif lastopened == data: ofp.write("") else: ofp.write("" % 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('\n') - convert(ifp, ofp) + convert(ifp, ofp, autoclose) except IOError, (err, msg): if err != errno.EPIPE: raise