diff options
author | Fred Drake <fdrake@acm.org> | 1999-01-19 17:10:31 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 1999-01-19 17:10:31 (GMT) |
commit | f82e4ab61733c321b583e049700b10c5375d6781 (patch) | |
tree | 38ce093ec4a4c4bc2211f4f4faed636ac1360a2d /Doc/tools/sgmlconv | |
parent | 9bbdce594512087c44b884857480906893579c9d (diff) | |
download | cpython-f82e4ab61733c321b583e049700b10c5375d6781.zip cpython-f82e4ab61733c321b583e049700b10c5375d6781.tar.gz cpython-f82e4ab61733c321b583e049700b10c5375d6781.tar.bz2 |
format_attrs(): Attempt a bit more minimization for SGML output.
Diffstat (limited to 'Doc/tools/sgmlconv')
-rwxr-xr-x | Doc/tools/sgmlconv/esis2sgml.py | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/Doc/tools/sgmlconv/esis2sgml.py b/Doc/tools/sgmlconv/esis2sgml.py index d6f3eb9..07ca571 100755 --- a/Doc/tools/sgmlconv/esis2sgml.py +++ b/Doc/tools/sgmlconv/esis2sgml.py @@ -15,15 +15,33 @@ import string from xml.utils import escape -def format_attrs(attrs): +def format_attrs(attrs, xml=0): attrs = attrs.items() attrs.sort() s = '' for name, value in attrs: - s = '%s %s="%s"' % (s, name, escape(value)) + if xml: + s = '%s %s="%s"' % (s, name, escape(value)) + else: + # this is a little bogus, but should do for now + if name == value and isnmtoken(value): + s = "%s %s" % (s, value) + elif istoken(value): + s = "%s %s=%s" % (s, name, value) + else: + s = '%s %s="%s"' % (s, name, escape(value)) return s +_nmtoken_rx = re.compile("[a-z][-._a-z0-9]*", re.IGNORECASE) +def isnmtoken(s): + return _nmtoken_rx.match(s) is not None + +_token_rx = re.compile("[a-z0-9][-._a-z0-9]*", re.IGNORECASE) +def istoken(s): + return _token_rx.match(s) is not None + + def do_convert(ifp, ofp, xml=0): attrs = {} lastopened = None @@ -51,9 +69,9 @@ def do_convert(ifp, ofp, xml=0): ofp.write("<!--") continue if knownempty and xml: - ofp.write("<%s%s/>" % (data, format_attrs(attrs))) + ofp.write("<%s%s/>" % (data, format_attrs(attrs, xml))) else: - ofp.write("<%s%s>" % (data, format_attrs(attrs))) + ofp.write("<%s%s>" % (data, format_attrs(attrs, xml))) if knownempty and data not in knownempties: # accumulate knowledge! knownempties.append(data) |