From 865e9ff98e2a5f77bf01aad6d4d7e7ec5ca7c9bd Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Thu, 29 Jul 1999 22:23:19 +0000 Subject: Added a few more passes through the document fragment. Not actually very interesting. --- Doc/tools/sgmlconv/docfixer.py | 137 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 126 insertions(+), 11 deletions(-) diff --git a/Doc/tools/sgmlconv/docfixer.py b/Doc/tools/sgmlconv/docfixer.py index f700134..5328a50 100755 --- a/Doc/tools/sgmlconv/docfixer.py +++ b/Doc/tools/sgmlconv/docfixer.py @@ -22,6 +22,8 @@ class ConversionError(Exception): pass +PARA_ELEMENT = "para" + DEBUG_PARA_FIXER = 0 if DEBUG_PARA_FIXER: @@ -77,7 +79,17 @@ def find_all_elements(doc, gi): nodes.append(child) for node in child.getElementsByTagName(gi): nodes.append(node) - return nodes + return nodes + +def find_all_elements_from_set(doc, gi_set, nodes=None): + if nodes is None: + nodes = [] + if doc.nodeType == ELEMENT and doc.tagName in gi_set: + nodes.append(doc) + for child in doc.childNodes: + if child.nodeType == ELEMENT: + find_all_elements_from_set(child, gi_set, nodes) + return nodes def simplify(doc, fragment): @@ -108,7 +120,7 @@ def simplify(doc, fragment): docelem.insertBefore(text, docelem.firstChild) docelem.insertBefore(node, text) docelem.insertBefore(doc.createTextNode("\n"), docelem.firstChild) - while fragment.firstChild.nodeType == TEXT: + while fragment.firstChild and fragment.firstChild.nodeType == TEXT: fragment.removeChild(fragment.firstChild) @@ -291,8 +303,8 @@ def handle_appendix(doc, fragment): docelem.appendChild(doc.createTextNode("\n")) -def handle_labels(doc): - for label in find_all_elements(doc, "label"): +def handle_labels(doc, fragment): + for label in find_all_elements(fragment, "label"): id = label.getAttribute("id") if not id: continue @@ -303,6 +315,11 @@ def handle_labels(doc): parent.setAttribute("id", id) # now, remove