mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Modify to perform "---" to "—" conversion outside of
verbatim-like environments. The list of verbatim-like environments is a defined by a variable in main().
This commit is contained in:
parent
c41e1e5f5e
commit
c4811d8208
1 changed files with 16 additions and 7 deletions
|
@ -77,7 +77,7 @@ def istoken(s):
|
||||||
return _token_rx.match(s) is not None
|
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:
|
if xml:
|
||||||
autoclose = ()
|
autoclose = ()
|
||||||
attrs = {}
|
attrs = {}
|
||||||
|
@ -85,6 +85,7 @@ def do_convert(ifp, ofp, xml=0, autoclose=()):
|
||||||
knownempties = []
|
knownempties = []
|
||||||
knownempty = 0
|
knownempty = 0
|
||||||
lastempty = 0
|
lastempty = 0
|
||||||
|
inverbatim = 0
|
||||||
while 1:
|
while 1:
|
||||||
line = ifp.readline()
|
line = ifp.readline()
|
||||||
if not line:
|
if not line:
|
||||||
|
@ -96,7 +97,10 @@ def do_convert(ifp, ofp, xml=0, autoclose=()):
|
||||||
data = data[:-1]
|
data = data[:-1]
|
||||||
if type == "-":
|
if type == "-":
|
||||||
data = esistools.decode(data)
|
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:
|
if "\n" in data:
|
||||||
lastopened = None
|
lastopened = None
|
||||||
knownempty = 0
|
knownempty = 0
|
||||||
|
@ -117,6 +121,7 @@ def do_convert(ifp, ofp, xml=0, autoclose=()):
|
||||||
lastopened = data
|
lastopened = data
|
||||||
lastempty = knownempty
|
lastempty = knownempty
|
||||||
knownempty = 0
|
knownempty = 0
|
||||||
|
inverbatim = data in verbatims
|
||||||
elif type == ")":
|
elif type == ")":
|
||||||
if data == "COMMENT":
|
if data == "COMMENT":
|
||||||
ofp.write("-->")
|
ofp.write("-->")
|
||||||
|
@ -134,6 +139,7 @@ def do_convert(ifp, ofp, xml=0, autoclose=()):
|
||||||
ofp.write("</%s>" % data)
|
ofp.write("</%s>" % data)
|
||||||
lastopened = None
|
lastopened = None
|
||||||
lastempty = 0
|
lastempty = 0
|
||||||
|
inverbatim = 0
|
||||||
elif type == "A":
|
elif type == "A":
|
||||||
name, type, value = string.split(data, " ", 2)
|
name, type, value = string.split(data, " ", 2)
|
||||||
name = map_gi(name, _attr_map)
|
name = map_gi(name, _attr_map)
|
||||||
|
@ -156,12 +162,14 @@ def dump_empty_element_names(knownempties):
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
||||||
|
|
||||||
def sgml_convert(ifp, ofp, autoclose):
|
def sgml_convert(ifp, ofp, autoclose, verbatims):
|
||||||
return do_convert(ifp, ofp, xml=0, autoclose=autoclose)
|
return do_convert(ifp, ofp, xml=0,
|
||||||
|
autoclose=autoclose, verbatims=verbatims)
|
||||||
|
|
||||||
|
|
||||||
def xml_convert(ifp, ofp, autoclose):
|
def xml_convert(ifp, ofp, autoclose, verbatims):
|
||||||
return do_convert(ifp, ofp, xml=1, autoclose=autoclose)
|
return do_convert(ifp, ofp, xml=1,
|
||||||
|
autoclose=autoclose, verbatims=verbatims)
|
||||||
|
|
||||||
|
|
||||||
def update_gi_map(map, names, fromsgml=1):
|
def update_gi_map(map, names, fromsgml=1):
|
||||||
|
@ -184,6 +192,7 @@ def main():
|
||||||
elem_names = ''
|
elem_names = ''
|
||||||
attr_names = ''
|
attr_names = ''
|
||||||
value_names = ''
|
value_names = ''
|
||||||
|
verbatims = ('verbatim', 'interactive-session')
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "adesx",
|
opts, args = getopt.getopt(sys.argv[1:], "adesx",
|
||||||
["autoclose=", "declare", "sgml", "xml",
|
["autoclose=", "declare", "sgml", "xml",
|
||||||
"elements-map=", "attributes-map",
|
"elements-map=", "attributes-map",
|
||||||
|
@ -243,7 +252,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
if xml and xmldecl:
|
if xml and xmldecl:
|
||||||
opf.write('<?xml version="1.0" encoding="iso8859-1"?>\n')
|
opf.write('<?xml version="1.0" encoding="iso8859-1"?>\n')
|
||||||
convert(ifp, ofp, autoclose)
|
convert(ifp, ofp, autoclose, verbatims)
|
||||||
except IOError, (err, msg):
|
except IOError, (err, msg):
|
||||||
if err != errno.EPIPE:
|
if err != errno.EPIPE:
|
||||||
raise
|
raise
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue