[Python-checkins] CVS: python/dist/src/Doc/tools/sgmlconv docfixer.py,1.31,1.32
Fred L. Drake
fdrake@users.sourceforge.net
Fri, 28 Sep 2001 10:14:37 -0700
Update of /cvsroot/python/python/dist/src/Doc/tools/sgmlconv
In directory usw-pr-cvs1:/tmp/cvs-serv12067/tools/sgmlconv
Modified Files:
docfixer.py
Log Message:
Convert to string methods.
For the real document element, make sure the prolog is migrated into
the document element so it isn't left stranded.
Make fixup_trailing_whitespace() whitespace do what was really intended.
Add the *desc environments used in the C API manual to the list of
things that can exist at the paragraph level so they don't get wrapped
in <para>...</para>.
Index: docfixer.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/tools/sgmlconv/docfixer.py,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** docfixer.py 2001/09/27 16:52:22 1.31
--- docfixer.py 2001/09/28 17:14:35 1.32
***************
*** 9,13 ****
import esistools
import re
- import string
import sys
import xml.dom
--- 9,12 ----
***************
*** 120,123 ****
--- 119,128 ----
if node is not None:
set_tagName(node, documentclass)
+ # Move everything that comes before this node into this node;
+ # this will be the document element.
+ nodelist = fragment.childNodes
+ point = node.firstChild
+ while not nodelist[0].isSameNode(node):
+ node.insertBefore(nodelist[0], point)
while 1:
node = extract_first_element(fragment, "input")
***************
*** 252,256 ****
last = description.childNodes[-1]
if last.nodeType == TEXT:
! last.data = string.rstrip(last.data) + "\n "
# 6.
# should have nothing but whitespace and signature lines in <descriptor>;
--- 257,261 ----
last = description.childNodes[-1]
if last.nodeType == TEXT:
! last.data = last.data.rstrip() + "\n "
# 6.
# should have nothing but whitespace and signature lines in <descriptor>;
***************
*** 311,315 ****
back.appendChild(doc.createTextNode("\n"))
while nodes and nodes[0].nodeType == TEXT \
! and not string.strip(nodes[0].data):
del nodes[0]
map(back.appendChild, nodes)
--- 316,320 ----
back.appendChild(doc.createTextNode("\n"))
while nodes and nodes[0].nodeType == TEXT \
! and not nodes[0].data.strip():
del nodes[0]
map(back.appendChild, nodes)
***************
*** 334,363 ****
children = parent.childNodes
if children[-1].nodeType == TEXT:
! children[-1].data = string.rstrip(children[-1].data)
! def fixup_trailing_whitespace(doc, wsmap):
! queue = [doc]
while queue:
node = queue[0]
del queue[0]
if wsmap.has_key(node.nodeName):
! ws = wsmap[node.tagName]
! children = node.childNodes
! children.reverse()
! if children[0].nodeType == TEXT:
! data = string.rstrip(children[0].data) + ws
! children[0].data = data
! children.reverse()
! # hack to get the title in place:
! if node.tagName == "title" \
! and node.parentNode.firstChild.nodeType == ELEMENT:
! node.parentNode.insertBefore(doc.createText("\n "),
! node.parentNode.firstChild)
for child in node.childNodes:
if child.nodeType == ELEMENT:
queue.append(child)
def normalize(doc):
for node in doc.childNodes:
--- 339,382 ----
children = parent.childNodes
if children[-1].nodeType == TEXT:
! children[-1].data = children[-1].data.rstrip()
! def fixup_trailing_whitespace(doc, fragment, wsmap):
! queue = [fragment]
! fixups = []
while queue:
node = queue[0]
del queue[0]
if wsmap.has_key(node.nodeName):
! fixups.append(node)
for child in node.childNodes:
if child.nodeType == ELEMENT:
queue.append(child)
+ # reverse the list to process from the inside out
+ fixups.reverse()
+ for node in fixups:
+ node.parentNode.normalize()
+ lastchild = node.lastChild
+ before, after = wsmap[node.tagName]
+ if lastchild.nodeType == TEXT:
+ data = lastchild.data.rstrip() + before
+ lastchild.data = data
+ norm = 0
+ if wsmap[node.tagName]:
+ nextnode = node.nextSibling
+ if nextnode and nextnode.nodeType == TEXT:
+ nextnode.data = after + nextnode.data.lstrip()
+ else:
+ wsnode = doc.createTextNode(after)
+ node.parentNode.insertBefore(wsnode, nextnode)
+ # hack to get the title in place:
+ if node.tagName == "title" \
+ and node.parentNode.firstChild.nodeType == ELEMENT:
+ node.parentNode.insertBefore(doc.createTextNode("\n "),
+ node.parentNode.firstChild)
+ node.parentNode.normalize()
+
def normalize(doc):
for node in doc.childNodes:
***************
*** 462,466 ****
first_data = children[1]
if first_data.data[:4] == " ---":
! first_data.data = string.lstrip(first_data.data[4:])
set_tagName(title, "short-synopsis")
if children[-1].nodeType == TEXT \
--- 481,485 ----
first_data = children[1]
if first_data.data[:4] == " ---":
! first_data.data = first_data.data[4:].lstrip()
set_tagName(title, "short-synopsis")
if children[-1].nodeType == TEXT \
***************
*** 505,510 ****
if nextnode.nodeType == TEXT:
data = nextnode.data
! if len(string.lstrip(data)) < (len(data) - 4):
! nextnode.data = "\n\n\n" + string.lstrip(data)
--- 524,530 ----
if nextnode.nodeType == TEXT:
data = nextnode.data
! s = data.lstrip()
! if len(s) < (len(data) - 4):
! nextnode.data = "\n\n\n" + s
***************
*** 547,551 ****
nodeType = child.nodeType
if nodeType == TEXT:
! if string.strip(child.data):
raise ConversionError("unexpected free data in <%s>: %r"
% (table.tagName, child.data))
--- 567,571 ----
nodeType = child.nodeType
if nodeType == TEXT:
! if child.data.strip():
raise ConversionError("unexpected free data in <%s>: %r"
% (table.tagName, child.data))
***************
*** 606,609 ****
--- 626,630 ----
"interpreter-session", "back-matter", "interactive-session",
"opcodedesc", "classdesc", "datadesc",
+ "cfuncdesc", "ctypedesc", "cvardesc",
"funcdesc", "methoddesc", "excdesc", "memberdesc", "membderdescni",
"funcdescni", "methoddescni", "excdescni",
***************
*** 663,667 ****
break
elif nodeType == TEXT:
! pos = string.find(child.data, "\n\n")
if pos == 0:
after = j
--- 684,688 ----
break
elif nodeType == TEXT:
! pos = child.data.find("\n\n")
if pos == 0:
after = j
***************
*** 679,685 ****
child = children[after - 1]
data = child.data
! if string.rstrip(data) != data:
have_last = 0
! child.splitText(len(string.rstrip(data)))
para = doc.createElement(PARA_ELEMENT)
prev = None
--- 700,706 ----
child = children[after - 1]
data = child.data
! if data.rstrip() != data:
have_last = 0
! child.splitText(len(data.rstrip()))
para = doc.createElement(PARA_ELEMENT)
prev = None
***************
*** 724,728 ****
if nodeType == TEXT:
data = child.data
! shortened = string.lstrip(data)
if shortened:
if data != shortened:
--- 745,749 ----
if nodeType == TEXT:
data = child.data
! shortened = data.lstrip()
if shortened:
if data != shortened:
***************
*** 796,800 ****
child = verbatim.childNodes[0]
if child.nodeType == TEXT \
! and string.lstrip(child.data)[:3] == ">>>":
set_tagName(verbatim, "interactive-session")
--- 817,821 ----
child = verbatim.childNodes[0]
if child.nodeType == TEXT \
! and child.data.lstrip().startswith(">>>"):
set_tagName(verbatim, "interactive-session")
***************
*** 974,986 ****
handle_labels(doc, fragment)
handle_appendix(doc, fragment)
! fixup_trailing_whitespace(doc, {
! "abstract": "\n",
! "title": "",
! "chapter": "\n\n",
! "section": "\n\n",
! "subsection": "\n\n",
! "subsubsection": "\n\n",
! "paragraph": "\n\n",
! "subparagraph": "\n\n",
})
cleanup_root_text(doc)
--- 995,1009 ----
handle_labels(doc, fragment)
handle_appendix(doc, fragment)
! fixup_trailing_whitespace(doc, fragment, {
! # element -> (before-end-tag, after-end-tag)
! "abstract": ("\n", "\n"),
! "title": ("", "\n"),
! "chapter": ("\n", "\n\n\n"),
! "section": ("\n", "\n\n\n"),
! "subsection": ("\n", "\n\n"),
! "subsubsection": ("\n", "\n\n"),
! "paragraph": ("\n", "\n\n"),
! "subparagraph": ("\n", "\n\n"),
! "enumeration": ("\n", "\n\n"),
})
cleanup_root_text(doc)