Commits

ms2ger committed 51fba0e Merge

Merged in zcorpan/anolis/use-ul-for-toc-in-w3c-compat-mode (pull request #10)

Use <ul> for the toc in w3c_compat since csswg's style sheet expects it

Comments (0)

Files changed (4)

anolislib/processes/toc.py

     toc = None
 
     def __init__(self, ElementTree, **kwargs):
-        self.toc = etree.Element("ol", {"class": "toc"})
         self.buildToc(ElementTree, **kwargs)
         self.addToc(ElementTree, **kwargs)
 
     def buildToc(self, ElementTree, min_depth=2, max_depth=6, w3c_compat=False,
                  w3c_compat_class_toc=False, **kwargs):
+        # Element to use for the toc
+        list_tag = "ol"
+        if w3c_compat or w3c_compat_class_toc:
+            list_tag = "ul"
+        
+        self.toc = etree.Element(list_tag, {"class": "toc"})
+
         # Build the outline of the document
         outline_creator = outliner.Outliner(ElementTree, **kwargs)
         outline = outline_creator.build(**kwargs)
                     while i < corrected_depth:
                         try:
                             # If the final li has no children, or the last
-                            # children isn't an ol element
+                            # children isn't a list_tag element
                             if len(toc_section[-1]) == 0 or \
-                               toc_section[-1][-1].tag != "ol":
-                                toc_section[-1].append(etree.Element("ol"))
+                               toc_section[-1][-1].tag != list_tag:
+                                toc_section[-1].append(etree.Element(list_tag))
                                 utils.indentNode(toc_section[-1][-1],
                                                  (i + 1) * 2, **kwargs)
                                 if w3c_compat or w3c_compat_class_toc:
                                     toc_section[-1][-1].set("class", "toc")
                         except IndexError:
-                            # If the current ol has no li in it
+                            # If the current list_tag has no li in it
                             toc_section.append(etree.Element("li"))
                             utils.indentNode(toc_section[0], (i + 1) * 2 - 1,
                                              **kwargs)
-                            toc_section[0].append(etree.Element("ol"))
+                            toc_section[0].append(etree.Element(list_tag))
                             utils.indentNode(toc_section[0][0], (i + 1) * 2,
                                              **kwargs)
                             if w3c_compat or w3c_compat_class_toc:
                                 toc_section[0][0].set("class", "toc")
-                        # TOC Section is now the final child (ol) of the final
+                        # TOC Section is now the final child (list_tag) of the final
                         # item (li) in the previous section
                         assert toc_section[-1].tag == "li"
-                        assert toc_section[-1][-1].tag == "ol"
+                        assert toc_section[-1][-1].tag == list_tag
                         toc_section = toc_section[-1][-1]
                         i += 1
                     # Add the current item to the TOC

tests/toc-w3c-compat-class-toc.html

+<!DOCTYPE html><meta charset=utf-8><h1>Foo</h1>
+
+<!--begin-toc-->
+<ul class=toc>
+ <li><a href=#bar><span class=secno>1 </span>Bar</a>
+  <ul class=toc>
+   <li><a href=#baz><span class=secno>1.1 </span>Baz</a>
+    <ul class=toc>
+     <li><a href=#quux><span class=secno>1.1.1 </span>Quux</a></ul></ul></ul>
+<!--end-toc-->
+<h2 id=bar><span class=secno>1 </span>Bar</h2>
+<h3 id=baz><span class=secno>1.1 </span>Baz</h3>
+<h4 id=quux><span class=secno>1.1.1 </span>Quux</h4>

tests/toc-w3c-compat-class-toc.options

+{
+  "w3c_compat_class_toc": true
+}

tests/toc-w3c-compat-class-toc.src.html

+<!doctype html>
+<h1>Foo</h1>
+<!--toc-->
+<h2>Bar</h2>
+<h3>Baz</h3>
+<h4>Quux</h4>