diff options
author | Fred Drake <fdrake@acm.org> | 1999-05-18 17:34:51 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 1999-05-18 17:34:51 (GMT) |
commit | c4811d82089d74928099d161d0c5dbb8c066809e (patch) | |
tree | 3e44095637b5f693e9a9141125d3741a0308f365 /Doc/tools/sgmlconv | |
parent | c41e1e5f5e6a5970b0ab0efc26646682073c7266 (diff) | |
download | cpython-c4811d82089d74928099d161d0c5dbb8c066809e.zip cpython-c4811d82089d74928099d161d0c5dbb8c066809e.tar.gz cpython-c4811d82089d74928099d161d0c5dbb8c066809e.tar.bz2 |
Modify to perform "---" to "—" conversion outside of
verbatim-like environments. The list of verbatim-like environments is
a defined by a variable in main().
Diffstat (limited to 'Doc/tools/sgmlconv')
-rwxr-xr-x | Doc/tools/sgmlconv/esis2sgml.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/Doc/tools/sgmlconv/esis2sgml.py b/Doc/tools/sgmlconv/esis2sgml.py index aea9962..aabbe71 100755 --- a/Doc/tools/sgmlconv/esis2sgml.py +++ b/Doc/tools/sgmlconv/esis2sgml.py @@ -77,7 +77,7 @@ def istoken(s): return _token_rx.match(s) is not None -def do_convert(ifp, ofp, xml=0, autoclose=()): +def do_convert(ifp, ofp, xml=0, autoclose=(), verbatims=()): if xml: autoclose = () attrs = {} @@ -85,6 +85,7 @@ def do_convert(ifp, ofp, xml=0, autoclose=()): knownempties = [] knownempty = 0 lastempty = 0 + inverbatim = 0 while 1: line = ifp.readline() if not line: @@ -96,7 +97,10 @@ def do_convert(ifp, ofp, xml=0, autoclose=()): data = data[:-1] if type == "-": data = esistools.decode(data) - ofp.write(escape(data)) + data = escape(data) + if not inverbatim: + data = string.replace(data, "---", "—") + ofp.write(data) if "\n" in data: lastopened = None knownempty = 0 @@ -117,6 +121,7 @@ def do_convert(ifp, ofp, xml=0, autoclose=()): lastopened = data lastempty = knownempty knownempty = 0 + inverbatim = data in verbatims elif type == ")": if data == "COMMENT": ofp.write("-->") @@ -134,6 +139,7 @@ def do_convert(ifp, ofp, xml=0, autoclose=()): ofp.write("</%s>" % data) lastopened = None lastempty = 0 + inverbatim = 0 elif type == "A": name, type, value = string.split(data, " ", 2) name = map_gi(name, _attr_map) @@ -156,12 +162,14 @@ def dump_empty_element_names(knownempties): fp.close() -def sgml_convert(ifp, ofp, autoclose): - return do_convert(ifp, ofp, xml=0, autoclose=autoclose) +def sgml_convert(ifp, ofp, autoclose, verbatims): + return do_convert(ifp, ofp, xml=0, + autoclose=autoclose, verbatims=verbatims) -def xml_convert(ifp, ofp, autoclose): - return do_convert(ifp, ofp, xml=1, autoclose=autoclose) +def xml_convert(ifp, ofp, autoclose, verbatims): + return do_convert(ifp, ofp, xml=1, + autoclose=autoclose, verbatims=verbatims) def update_gi_map(map, names, fromsgml=1): @@ -184,6 +192,7 @@ def main(): elem_names = '' attr_names = '' value_names = '' + verbatims = ('verbatim', 'interactive-session') opts, args = getopt.getopt(sys.argv[1:], "adesx", ["autoclose=", "declare", "sgml", "xml", "elements-map=", "attributes-map", @@ -243,7 +252,7 @@ def main(): try: if xml and xmldecl: opf.write('<?xml version="1.0" encoding="iso8859-1"?>\n') - convert(ifp, ofp, autoclose) + convert(ifp, ofp, autoclose, verbatims) except IOError, (err, msg): if err != errno.EPIPE: raise |