diff --git a/Doc/tools/sgmlconv/docfixer.py b/Doc/tools/sgmlconv/docfixer.py index f700134a1bd..5328a504e3a 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