From: Vladimír Vondruš Date: Fri, 22 Feb 2019 21:25:43 +0000 (+0100) Subject: doxygen: work around a bug related to HTML anchors. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=fa79f99c4fe289e7b166db3e849e4c5f7d35393a;p=blog.git doxygen: work around a bug related to HTML anchors. Consistency FTW. Yay. --- diff --git a/doxygen/dox2html5.py b/doxygen/dox2html5.py index 01b90fb9..c9d47f41 100755 --- a/doxygen/dox2html5.py +++ b/doxygen/dox2html5.py @@ -1463,7 +1463,16 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET. out.parsed = out.parsed.rstrip() + '
' elif i.tag == 'anchor': - out.parsed += '
'.format(extract_id_hash(state, i)) + # Doxygen doesn't prefix HTML anchors the same way as + # for @anchor (WHO WOULD HAVE THOUGHT, RIGHT), it just fully omits + # the prefix. So allow that -- thus we can't just extract_id_hash() + id = i.attrib['id'] + if id[:2] == '_1': + id = id[2:] + else: + assert id.startswith(state.current_definition_url_base) + id = id[len(state.current_definition_url_base)+2:] + out.parsed += ''.format(id) elif i.tag == 'computeroutput': content = parse_inline_desc(state, i).strip() diff --git a/doxygen/test/contents_anchor_html_no_prefix_bug/Doxyfile b/doxygen/test/contents_anchor_html_no_prefix_bug/Doxyfile new file mode 100644 index 00000000..7911fe98 --- /dev/null +++ b/doxygen/test/contents_anchor_html_no_prefix_bug/Doxyfile @@ -0,0 +1,14 @@ +INPUT = input.dox +QUIET = YES +GENERATE_HTML = NO +GENERATE_LATEX = NO +GENERATE_XML = YES +XML_PROGRAMLISTING = NO + +##! M_PAGE_FINE_PRINT = +##! M_THEME_COLOR = +##! M_FAVICON = +##! M_LINKS_NAVBAR1 = +##! M_LINKS_NAVBAR2 = +##! M_SEARCH_DISABLED = YES + diff --git a/doxygen/test/contents_anchor_html_no_prefix_bug/input.dox b/doxygen/test/contents_anchor_html_no_prefix_bug/input.dox new file mode 100644 index 00000000..11a1deef --- /dev/null +++ b/doxygen/test/contents_anchor_html_no_prefix_bug/input.dox @@ -0,0 +1,7 @@ +/** @page some-long-page-name A page + + + +Here's a HTML anchor for which Doxygen doesn't produce a prefix like for the +normal `@anchor` because it's buggy. But we have to parse it nevertheless! +*/ diff --git a/doxygen/test/contents_anchor_html_no_prefix_bug/some-long-page-name.html b/doxygen/test/contents_anchor_html_no_prefix_bug/some-long-page-name.html new file mode 100644 index 00000000..57cb63aa --- /dev/null +++ b/doxygen/test/contents_anchor_html_no_prefix_bug/some-long-page-name.html @@ -0,0 +1,31 @@ + + + + + A page | My Project + + + + + +
+
+
+
+
+

+ A page +

+

Here's a HTML anchor for which Doxygen doesn't produce a prefix like for the normal @anchor because it's buggy. But we have to parse it nevertheless!

+
+
+
+
+ + diff --git a/doxygen/test/test_contents.py b/doxygen/test/test_contents.py index 4c5ae36e..09af0ac7 100644 --- a/doxygen/test/test_contents.py +++ b/doxygen/test/test_contents.py @@ -367,6 +367,14 @@ class AnchorInBothGroupAndNamespace(IntegrationTestCase): self.assertEqual(*self.actual_expected_contents('namespaceFoo.html')) self.assertEqual(*self.actual_expected_contents('group__fizzbuzz.html')) +class AnchorHtmlNoPrefixBug(IntegrationTestCase): + def __init__(self, *args, **kwargs): + super().__init__(__file__, 'anchor_html_no_prefix_bug', *args, **kwargs) + + def test(self): + self.run_dox2html5(wildcard='some-long-page-name.xml') + self.assertEqual(*self.actual_expected_contents('some-long-page-name.html')) + class UnexpectedSections(IntegrationTestCase): def __init__(self, *args, **kwargs): super().__init__(__file__, 'unexpected_sections', *args, **kwargs)