Commits

Luke Plant committed dba87bf

Remove error for duplicate heading names and improve 'friendly' name when content is empty

Comments (0)

Files changed (2)

semanticeditor/tests.py

     def test_rejects_improper_headings(self):
         self.assertRaises(IncorrectHeadings, extract_structure, "<h1>Hello</h1><h3>Bad heading</h3>")
 
-    def test_rejects_duplicate_headings(self):
-        self.assertRaises(IncorrectHeadings, extract_structure, "<h1>Hello</h1><h2>Hello</h2>")
-
     def test_use_existing_sect_ids(self):
         html = "<h1 id='h1_10'>Hi</h1><h1>There</h1>"
         structure = get_structure(parse(html))

semanticeditor/utils/presentation.py

                                                     "heading, which was H%d." %
                                                     first_heading_level)
 
+                    if name == "":
+                        name = "?"
                     if name in heading_names:
-                        raise IncorrectHeadings('There are duplicate headings with the name'
-                                                ' "%s".' % name)
+                        name = _find_next_available_name(name, heading_names)
 
                     # Headings should decrease or monotonically increase
                     if len(heading_names) > 0 and level > last_heading_num + 1:
                 heading_names.add(name)
             else:
                 name = text[0:BLOCK_LEVEL_TRIM_LENGTH]
-                name = name + "..."
+                if name == '':
+                    name = '?'
+                else:
+                    name = name + "..."
                 if name in names:
                     name = _find_next_available_name(name, names)
                 names.add(name)