Commits

Geoffrey Sneddon committed 935b4a2

Fix bugs with header element handling (inc. infinite loop).

Comments (0)

Files changed (5)

anolislib/processes/toc.py

                 if section.header.tag == u"header":
                     i = 1
                     while i <= 6:
-                        header_text = section.header.find(u"h" + unicode(i))
+                        header_text = section.header.find(u".//h" + unicode(i))
                         if header_text is not None:
                             break
+                        i += 1
                     else:
                         header_text = None
                 else:

tests/basic/toc-header-element-descendant-h1.html

+<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
+
+<!--begin-toc-->
+<ol class=toc>
+ <li><a href=#bar><span class=secno>1 </span>Bar</a></ol>
+<!--end-toc-->
+<section>
+    <header id=bar>
+        <div>
+            <h1><span class=secno>1 </span>Bar</h1>
+        </div>
+    </header>
+</section>

tests/basic/toc-header-element-descendant-h1.src.html

+<!doctype html>
+<h1>Foo</h1>
+<!--toc-->
+<section>
+    <header>
+        <div>
+            <h1>Bar</h1>
+        </div>
+    </header>
+</section>

tests/basic/toc-header-element-h2.html

+<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
+
+<!--begin-toc-->
+<ol class=toc>
+ <li><a href=#bar><span class=secno>1 </span>Bar</a></ol>
+<!--end-toc-->
+<section>
+    <header id=bar>
+        <h2><span class=secno>1 </span>Bar</h2>
+    </header>
+</section>

tests/basic/toc-header-element-h2.src.html

+<!doctype html>
+<h1>Foo</h1>
+<!--toc-->
+<section>
+    <header>
+        <h2>Bar</h2>
+    </header>
+</section>