Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 43278f0

Browse files
committed
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".
1 parent 0a5b8de commit 43278f0

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

Doc/tools/sgmlconv/esis2sgml.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ def istoken(s):
4747
return _token_rx.match(s) is not None
4848

4949

50-
def do_convert(ifp, ofp, xml=0):
50+
def do_convert(ifp, ofp, xml=0, autoclose=()):
51+
if xml:
52+
autoclose = ()
5153
attrs = {}
5254
lastopened = None
5355
knownempties = []
@@ -92,7 +94,9 @@ def do_convert(ifp, ofp, xml=0):
9294
if not lastempty:
9395
ofp.write("</%s>" % data)
9496
elif data not in knownempties:
95-
if lastopened == data:
97+
if data in autoclose:
98+
pass
99+
elif lastopened == data:
96100
ofp.write("</>")
97101
else:
98102
ofp.write("</%s>" % data)
@@ -115,28 +119,35 @@ def do_convert(ifp, ofp, xml=0):
115119
fp.close()
116120

117121

118-
def sgml_convert(ifp, ofp):
119-
return do_convert(ifp, ofp, xml=0)
122+
def sgml_convert(ifp, ofp, autoclose):
123+
return do_convert(ifp, ofp, xml=0, autoclose=autoclose)
120124

121125

122-
def xml_convert(ifp, ofp):
123-
return do_convert(ifp, ofp, xml=1)
126+
def xml_convert(ifp, ofp, autoclose):
127+
return do_convert(ifp, ofp, xml=1, autoclose=autoclose)
128+
129+
130+
AUTOCLOSE = ("para",)
124131

125132

126133
def main():
127134
import getopt
128135
import sys
129136
#
137+
autoclose = AUTOCLOSE
130138
convert = sgml_convert
131139
xml = 0
132140
xmldecl = 0
133-
opts, args = getopt.getopt(sys.argv[1:], "dx", ["declare", "xml"])
141+
opts, args = getopt.getopt(sys.argv[1:], "adx",
142+
["autoclose", "declare", "xml"])
134143
for opt, arg in opts:
135144
if opt in ("-d", "--declare"):
136145
xmldecl = 1
137146
elif opt in ("-x", "--xml"):
138147
xml = 1
139148
convert = xml_convert
149+
elif opt in ("-a", "--autoclose"):
150+
autoclose = string.split(arg, ",")
140151
if len(args) == 0:
141152
ifp = sys.stdin
142153
ofp = sys.stdout
@@ -153,7 +164,7 @@ def main():
153164
try:
154165
if xml and xmldecl:
155166
opf.write('<?xml version="1.0" encoding="iso8859-1"?>\n')
156-
convert(ifp, ofp)
167+
convert(ifp, ofp, autoclose)
157168
except IOError, (err, msg):
158169
if err != errno.EPIPE:
159170
raise

0 commit comments

Comments
 (0)