diff --git a/doorstop/core/publishers/html.py b/doorstop/core/publishers/html.py index b0a1b77d..1138ba34 100644 --- a/doorstop/core/publishers/html.py +++ b/doorstop/core/publishers/html.py @@ -355,12 +355,20 @@ def table_of_contents(self, linkify=None, obj=None): for item in iter_items(toc_doc): # Check if item has the attribute heading. if item.heading: - lines = item.text.splitlines() - heading = lines[0] if lines else "" + if item.header: + heading = "{h}".format(h=item.header) + else: + lines = item.text.splitlines() + heading = lines[0] if lines else "" + # This is for non-heading items. elif item.header: heading = "{h}".format(h=item.header) else: - heading = item.uid + lines = item.text.splitlines() + heading = lines[0] if lines else "" + # For normative items, the UID is of interest, so append it. + if item.normative: + heading = heading + " (" + str(item.uid) + ")" if settings.PUBLISH_HEADING_LEVELS: level = format_level(item.level) lbl = "{lev} {h}".format(lev=level, h=heading) diff --git a/doorstop/core/publishers/markdown.py b/doorstop/core/publishers/markdown.py index 3642158c..b2cf49c4 100644 --- a/doorstop/core/publishers/markdown.py +++ b/doorstop/core/publishers/markdown.py @@ -168,13 +168,19 @@ def table_of_contents(self, linkify=None, obj=None): # Check if item has the attribute heading. if item.heading: - lines = item.text.splitlines() - heading = lines[0] if lines else "" + if item.header: + heading = "{h}".format(h=item.header) + else: + lines = item.text.splitlines() + heading = lines[0] if lines else "" elif item.header: heading = "{h}".format(h=item.header) else: - heading = item.uid - + lines = item.text.splitlines() + heading = lines[0] if lines else "" + # For normative items, the UID is of interest, so append it. + if item.normative: + heading = heading + " (" + str(item.uid) + ")" if settings.PUBLISH_HEADING_LEVELS: level = format_level(item.level) lbl = "{lev} {h}".format(lev=level, h=heading) @@ -233,9 +239,11 @@ def _generate_heading_from_item(self, item, to_html=False): if settings.ENABLE_HEADERS: if item.header: if to_html: - uid = "{h} {u}".format(h=item.header, u=item.uid) + uid = "{h} ({u})".format( + h=item.header, u=item.uid + ) else: - uid = "{h} _{u}_".format(h=item.header, u=item.uid) + uid = "{h} _({u})_".format(h=item.header, u=item.uid) else: uid = "{u}".format(u=item.uid) diff --git a/doorstop/core/publishers/tests/test_publisher_html.py b/doorstop/core/publishers/tests/test_publisher_html.py index 6a5d8655..58a389f0 100644 --- a/doorstop/core/publishers/tests/test_publisher_html.py +++ b/doorstop/core/publishers/tests/test_publisher_html.py @@ -315,12 +315,16 @@ def test_toc_no_links_or_heading_levels(self): """Verify the table of contents is generated with heading levels""" expected = [ {"depth": 0, "text": "Table of Contents", "uid": "toc"}, - {"depth": 3, "text": "1.2.3 REQ001", "uid": ""}, - {"depth": 2, "text": "1.4 REQ003", "uid": ""}, - {"depth": 2, "text": "1.5 REQ006", "uid": ""}, - {"depth": 2, "text": "1.6 REQ004", "uid": ""}, - {"depth": 2, "text": "2.1 Plantuml", "uid": ""}, - {"depth": 2, "text": "2.1 REQ2-001", "uid": ""}, + { + "depth": 3, + "text": "1.2.3 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod (REQ001)", + "uid": "", + }, + {"depth": 2, "text": "1.4 Unicode: -40° ±1% (REQ003)", "uid": ""}, + {"depth": 2, "text": "1.5 Hello, world! (REQ006)", "uid": ""}, + {"depth": 2, "text": "1.6 Hello, world! (REQ004)", "uid": ""}, + {"depth": 2, "text": "2.1 Plantuml (REQ002)", "uid": ""}, + {"depth": 2, "text": "2.1 Hello, world! (REQ2-001)", "uid": ""}, ] html_publisher = publisher.check(".html", self.document) toc = html_publisher.table_of_contents(linkify=None, obj=self.document) @@ -331,12 +335,16 @@ def test_toc_no_links(self): """Verify the table of contents is generated without heading levels""" expected = [ {"depth": 0, "text": "Table of Contents", "uid": "toc"}, - {"depth": 3, "text": UID("REQ001"), "uid": ""}, - {"depth": 2, "text": UID("REQ003"), "uid": ""}, - {"depth": 2, "text": UID("REQ006"), "uid": ""}, - {"depth": 2, "text": UID("REQ004"), "uid": ""}, - {"depth": 2, "text": "Plantuml", "uid": ""}, - {"depth": 2, "text": UID("REQ2-001"), "uid": ""}, + { + "depth": 3, + "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod (REQ001)", + "uid": "", + }, + {"depth": 2, "text": "Unicode: -40° ±1% (REQ003)", "uid": ""}, + {"depth": 2, "text": "Hello, world! (REQ006)", "uid": ""}, + {"depth": 2, "text": "Hello, world! (REQ004)", "uid": ""}, + {"depth": 2, "text": "Plantuml (REQ002)", "uid": ""}, + {"depth": 2, "text": "Hello, world! (REQ2-001)", "uid": ""}, ] html_publisher = publisher.check(".html", self.document) @@ -347,12 +355,24 @@ def test_toc(self): """Verify the table of contents is generated with an ID for the heading""" expected = [ {"depth": 0, "text": "Table of Contents", "uid": "toc"}, - {"depth": 3, "text": "1.2.3 REQ001", "uid": UID("REQ001")}, - {"depth": 2, "text": "1.4 REQ003", "uid": UID("REQ003")}, - {"depth": 2, "text": "1.5 REQ006", "uid": UID("REQ006")}, - {"depth": 2, "text": "1.6 REQ004", "uid": UID("REQ004")}, - {"depth": 2, "text": "2.1 Plantuml", "uid": UID("REQ002")}, - {"depth": 2, "text": "2.1 REQ2-001", "uid": UID("REQ2-001")}, + { + "depth": 3, + "text": "1.2.3 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod (REQ001)", + "uid": UID("REQ001"), + }, + { + "depth": 2, + "text": "1.4 Unicode: -40° ±1% (REQ003)", + "uid": UID("REQ003"), + }, + {"depth": 2, "text": "1.5 Hello, world! (REQ006)", "uid": UID("REQ006")}, + {"depth": 2, "text": "1.6 Hello, world! (REQ004)", "uid": UID("REQ004")}, + {"depth": 2, "text": "2.1 Plantuml (REQ002)", "uid": UID("REQ002")}, + { + "depth": 2, + "text": "2.1 Hello, world! (REQ2-001)", + "uid": UID("REQ2-001"), + }, ] html_publisher = publisher.check(".html", self.document) toc = html_publisher.table_of_contents(linkify=True, obj=self.document) diff --git a/doorstop/core/publishers/tests/test_publisher_markdown.py b/doorstop/core/publishers/tests/test_publisher_markdown.py index 2a4e396a..e10bcead 100644 --- a/doorstop/core/publishers/tests/test_publisher_markdown.py +++ b/doorstop/core/publishers/tests/test_publisher_markdown.py @@ -225,12 +225,12 @@ def test_toc_no_links_or_heading_levels(self): """Verify the table of contents is generated with heading levels""" expected = """### Table of Contents - * 1.2.3 REQ001 - * 1.4 REQ003 - * 1.5 REQ006 - * 1.6 REQ004 - * 2.1 Plantuml - * 2.1 REQ2-001\n""" + * 1.2.3 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod (REQ001) + * 1.4 Unicode: -40° ±1% (REQ003) + * 1.5 Hello, world! (REQ006) + * 1.6 Hello, world! (REQ004) + * 2.1 Plantuml (REQ002) + * 2.1 Hello, world! (REQ2-001)\n""" md_publisher = publisher.check(".md", self.document) toc = md_publisher.table_of_contents(linkify=None, obj=self.document) self.assertEqual(expected, toc) @@ -240,12 +240,13 @@ def test_toc_no_links(self): """Verify the table of contents is generated without heading levels""" expected = """### Table of Contents - * REQ001 - * REQ003 - * REQ006 - * REQ004 - * Plantuml - * REQ2-001\n""" + * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod (REQ001) + * Unicode: -40° ±1% (REQ003) + * Hello, world! (REQ006) + * Hello, world! (REQ004) + * Plantuml (REQ002) + * Hello, world! (REQ2-001) +""" md_publisher = publisher.check(".md", self.document) toc = md_publisher.table_of_contents(linkify=None, obj=self.document) self.assertEqual(expected, toc) @@ -254,12 +255,12 @@ def test_toc(self): """Verify the table of contents is generated with an ID for the heading""" expected = """### Table of Contents - * [1.2.3 REQ001](#123-req001-req001) - * [1.4 REQ003](#14-req003-req003) - * [1.5 REQ006](#15-req006-req006) - * [1.6 REQ004](#16-req004-req004) - * [2.1 Plantuml](#21-plantuml-req002-req002) - * [2.1 REQ2-001](#21-req2-001-req2-001)\n""" + * [1.2.3 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod (REQ001)](#123-req001-req001) + * [1.4 Unicode: -40° ±1% (REQ003)](#14-req003-req003) + * [1.5 Hello, world! (REQ006)](#15-req006-req006) + * [1.6 Hello, world! (REQ004)](#16-req004-req004) + * [2.1 Plantuml (REQ002)](#21-plantuml-req002-req002) + * [2.1 Hello, world! (REQ2-001)](#21-req2-001-req2-001)\n""" self.maxDiff = None md_publisher = publisher.check(".md", self.document) toc = md_publisher.table_of_contents(linkify=True, obj=self.document) diff --git a/doorstop/core/template.py b/doorstop/core/template.py index 0da6681c..fe00293b 100644 --- a/doorstop/core/template.py +++ b/doorstop/core/template.py @@ -108,7 +108,8 @@ def get_template(obj, path, ext, template): log.info( "Copying %s to %s", each.template, - os.path.join(os.path.dirname(path), "template"), + template, + # os.path.join(os.path.dirname(path), "template"), ) common.copy_dir_contents(each.template, template_dir) else: diff --git a/doorstop/core/tests/files/published.html b/doorstop/core/tests/files/published.html index f58b7ab3..33a8394e 100644 --- a/doorstop/core/tests/files/published.html +++ b/doorstop/core/tests/files/published.html @@ -36,18 +36,60 @@ Contents -