Commits

Luke Plant committed a7668c0

Return tag when extracting headings

Comments (0)

Files changed (2)

semanticeditor/tests.py

 
 PC = PresentationClass
 
-class TestExtract(TestCase):
+class TestExtractStructure(TestCase):
     def test_extract_headings(self):
         self.assertEqual(extract_headings("""
 <h1>Heading <b>with </b><i>embedded <em>stuff</em> in</i> it</h1> Hmm<p>A paragraph</p>
 <h5>level 5</h5>
 <h6>level 6</h6>
 <h1>Heading two</h1>
-"""), [(1, "Heading with embedded stuff in it"),
-       (2, "A sub heading"),
-       (3, "level 3"),
-       (4, "level 4"),
-       (5, "level 5"),
-       (6, "level 6"),
-       (1, "Heading two"),
+"""), [(1, "Heading with embedded stuff in it", "H1"),
+       (2, "A sub heading", "H2"),
+       (3, "level 3", "H3"),
+       (4, "level 4", "H4"),
+       (5, "level 5", "H5"),
+       (6, "level 6", "H6"),
+       (1, "Heading two", "H1"),
        ])
 
     def test_extract_headings_missing(self):

semanticeditor/utils/presentation.py

 
 def extract_headings(content):
     """
-    Extracts H1, H2, etc headings, and returns a list of tuples
-    containing (level, name)
+    Extracts H1, H2, etc headings, and other block level elements and
+    returns a list of tuples containing (level, name, tag)
     """
     # Parse
     tree = parse(content)
     nodes = [n for n in tree.getiterator() if n.tag in headingdef]
-    headings = [(int(h.tag[1]), flatten(h)) for h in nodes]
+    headings = [(int(h.tag[1]), flatten(h), h.tag.upper()) for h in nodes]
 
     # Check ordering
     if len(headings) > 0 and headings[0][0] > 1:
     # and they should have unique names
     lastnum = 0
     names = {}
-    for num, name in headings:
+    for num, name, tag in headings:
         if num > lastnum + 1:
             raise IncorrectHeadings('Heading "%(name)s" is level H%(foundnum)d,'
                                     ' but it should be level H%(rightnum)d or less' %