1 --- a/mwlib/treecleaner.py Tue Nov 18 14:23:14 2008 +0100
2 +++ b/mwlib/treecleaner.py Tue Nov 18 15:50:25 2008 +0100
3 @@ -179,6 +179,7 @@
4 'findDefinitionLists',
5 'restrictChildren',
6 'fixNesting', # pull DefinitionLists out of Paragraphs
7 + 'fixChapterNesting',
8 'removeEmptyTextNodes',
9 'removeChildlessNodes',
10 ]
11 @@ -797,3 +798,23 @@
12 for c in node.children:
13 self.removeCategoryLinks(c)
14
15 +
16 +
17 + def fixChapterNesting(self, node):
18 + """move all following siblings of a chapter up to the next chapter below the chapter"""
19 + if node.__class__ == Chapter and node.parent:
20 + siblings = node.getAllSiblings()
21 + siblings = siblings[siblings.index(node)+1:]
22 + for idx, sib in enumerate(siblings):
23 + if sib.__class__ == Chapter:
24 + siblings = siblings[:idx]
25 + break
26 + for sib in siblings:
27 + sib.parent.removeChild(sib)
28 + node.appendChild(sib)
29 + return
30 +
31 + for c in node.children:
32 + self.fixChapterNesting(c)
33 +
34 +