chiark / gitweb /
doxygen: work around a bug related to HTML <a name=""> anchors.
authorVladimír Vondruš <mosra@centrum.cz>
Fri, 22 Feb 2019 21:25:43 +0000 (22:25 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Sat, 23 Feb 2019 00:09:59 +0000 (01:09 +0100)
Consistency FTW. Yay.

doxygen/dox2html5.py
doxygen/test/contents_anchor_html_no_prefix_bug/Doxyfile [new file with mode: 0644]
doxygen/test/contents_anchor_html_no_prefix_bug/input.dox [new file with mode: 0644]
doxygen/test/contents_anchor_html_no_prefix_bug/some-long-page-name.html [new file with mode: 0644]
doxygen/test/test_contents.py

index 01b90fb9253e5a623c2adf0d2b8409471d6c306d..c9d47f41d7c9bb74d2e11ad95add03118a657bfa 100755 (executable)
@@ -1463,7 +1463,16 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET.
             out.parsed = out.parsed.rstrip() + '<br />'
 
         elif i.tag == 'anchor':
-            out.parsed += '<a name="{}"></a>'.format(extract_id_hash(state, i))
+            # Doxygen doesn't prefix HTML <a name=""> 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 += '<a name="{}"></a>'.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 (file)
index 0000000..7911fe9
--- /dev/null
@@ -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 (file)
index 0000000..11a1dee
--- /dev/null
@@ -0,0 +1,7 @@
+/** @page some-long-page-name A page
+
+<a name="anchor"></a>
+
+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 (file)
index 0000000..57cb63a
--- /dev/null
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8" />
+  <title>A page | My Project</title>
+  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i%7CSource+Code+Pro:400,400i,600" />
+  <link rel="stylesheet" href="m-dark+doxygen.compiled.css" />
+  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+</head>
+<body>
+<header><nav id="navigation">
+  <div class="m-container">
+    <div class="m-row">
+      <a href="index.html" id="m-navbar-brand" class="m-col-t-8 m-col-m-none m-left-m">My Project</a>
+    </div>
+  </div>
+</nav></header>
+<main><article>
+  <div class="m-container m-container-inflatable">
+    <div class="m-row">
+      <div class="m-col-l-10 m-push-l-1">
+        <h1>
+          A page
+        </h1>
+<p><a name="anchor"></a></p><p>Here&#x27;s a HTML anchor for which Doxygen doesn&#x27;t produce a prefix like for the normal <code>@anchor</code> because it&#x27;s buggy. But we have to parse it nevertheless!</p>
+      </div>
+    </div>
+  </div>
+</article></main>
+</body>
+</html>
index 4c5ae36e637bd350056ad86316f75632e51c9ad1..09af0ac7e2bb6ccafb1a6765d21cc8d5398abef7 100644 (file)
@@ -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)