chiark / gitweb /
doxygen: fix case where pages are subpages of index.
authorVladimír Vondruš <mosra@centrum.cz>
Mon, 29 Jan 2018 22:46:10 +0000 (23:46 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Sat, 3 Feb 2018 09:51:55 +0000 (10:51 +0100)
Avoid the assertion, include the index page in the page tree and link to
index.html instead of indexpage.html.

doxygen/dox2html5.py
doxygen/test/page_subpage_of_index/Doxyfile [new file with mode: 0644]
doxygen/test/page_subpage_of_index/input.dox [new file with mode: 0644]
doxygen/test/page_subpage_of_index/page.html [new file with mode: 0644]
doxygen/test/page_subpage_of_index/pages.html [new file with mode: 0644]
doxygen/test/test_page.py

index ef5d93acd1b21197fd573bae588e0154651bb3f5..81e6d2a760c466524938a5ebbded62138a3ecd86 100755 (executable)
@@ -1346,7 +1346,8 @@ def extract_metadata(state: State, xml):
     # Compound name is page filename, so we have to use title there. The same
     # is for groups.
     compound.name = html.escape(compounddef.find('title').text if compound.kind in ['page', 'group'] and compounddef.findtext('title') else compounddef.find('compoundname').text)
-    compound.url = compound.id + '.html'
+    # Compound URL is ID, except for index page
+    compound.url = (compounddef.find('compoundname').text if compound.kind == 'page' else compound.id) + '.html'
     compound.brief = parse_desc(state, compounddef.find('briefdescription'))
     # Groups are explicitly created so they *have details*, other things need
     # to have at least some documentation
@@ -2120,9 +2121,9 @@ def parse_index_xml(state: State, xml):
                 top_level_files += [entry]
             else:
                 assert compound.kind == 'page'
-                # Ignore index page in page listing
-                if entry.id == 'indexpage': continue
-                top_level_pages += [entry]
+                # Ignore index page in page listing, add it later only if it
+                # has children
+                if entry.id != 'indexpage': top_level_pages += [entry]
 
         # Otherwise put it into orphan map
         else:
@@ -2172,6 +2173,10 @@ def parse_index_xml(state: State, xml):
     for parent, children in orphans.items():
         if parent in entries: entries[parent].children += children
 
+    # Add the index page if it has children
+    if 'indexpage' in entries and entries['indexpage'].children:
+        parsed.index.pages = [entries['indexpage']] + parsed.index.pages
+
     return parsed
 
 def parse_doxyfile(state: State, doxyfile, config = None):
diff --git a/doxygen/test/page_subpage_of_index/Doxyfile b/doxygen/test/page_subpage_of_index/Doxyfile
new file mode 100644 (file)
index 0000000..d572a12
--- /dev/null
@@ -0,0 +1,11 @@
+INPUT                   = input.dox
+QUIET                   = YES
+GENERATE_HTML           = NO
+GENERATE_LATEX          = NO
+GENERATE_XML            = YES
+
+M_PAGE_FINE_PRINT       =
+M_THEME_COLOR           =
+M_LINKS_NAVBAR1         =
+M_LINKS_NAVBAR2         =
+M_SEARCH_DISABLED       = YES
diff --git a/doxygen/test/page_subpage_of_index/input.dox b/doxygen/test/page_subpage_of_index/input.dox
new file mode 100644 (file)
index 0000000..8d43268
--- /dev/null
@@ -0,0 +1,9 @@
+/** @mainpage
+
+- @subpage page
+*/
+
+/** @page page A page
+
+A page
+*/
diff --git a/doxygen/test/page_subpage_of_index/page.html b/doxygen/test/page_subpage_of_index/page.html
new file mode 100644 (file)
index 0000000..ed4c137
--- /dev/null
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8" />
+  <title>My Project &raquo; 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-9 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>
+          <span class="m-breadcrumb"><a href="index.html">My Project</a> &raquo;</span>
+          A page
+        </h1>
+<p>A page</p>
+      </div>
+    </div>
+  </div>
+</article></main>
+</body>
+</html>
diff --git a/doxygen/test/page_subpage_of_index/pages.html b/doxygen/test/page_subpage_of_index/pages.html
new file mode 100644 (file)
index 0000000..49178ac
--- /dev/null
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8" />
+  <title>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-9 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>Pages</h2>
+        <ul class="m-dox">
+          <li class="m-dox-collapsible">
+            <a href="#" onclick="return toggle(this)"></a><a href="index.html" class="m-dox">My Project</a> <span class="m-dox"></span>
+            <ul class="m-dox">
+              <li><a href="page.html" class="m-dox">A page</a> <span class="m-dox"></span></li>
+            </ul>
+          </li>
+        </ul>
+        <script>
+        function toggle(e) {
+            e.parentElement.className = e.parentElement.className == 'm-dox-collapsible' ?
+                'm-dox-expansible' : 'm-dox-collapsible';
+            return false;
+        }
+        /* Collapse all nodes marked as such. Doing it via JS instead of directly in
+           markup so disabling it doesn't harm usability. The list is somehow
+           regenerated on every iteration and shrinks as I change the classes. It's not
+           documented anywhere and I'm not sure if this is the same across browsers, so
+           I am going backwards in that list to be sure.  */
+        var collapsed = document.getElementsByClassName("collapsed");
+        for(var i = collapsed.length - 1; i >= 0; --i)
+            collapsed[i].className = 'm-dox-expansible';
+        </script>
+      </div>
+    </div>
+  </div>
+</article></main>
+</body>
+</html>
index 1d4de89e80246bec8711cd9d23c02fbbdd2fce3f..999041d6563c316e577bb16a037223d9b8253169 100644 (file)
@@ -91,3 +91,12 @@ class EmptyTitle(IntegrationTestCase):
     def test(self):
         self.run_dox2html5(wildcard='untitled.xml')
         self.assertEqual(*self.actual_expected_contents('untitled.html'))
+
+class SubpageOfIndex(IntegrationTestCase):
+    def __init__(self, *args, **kwargs):
+        super().__init__(__file__, 'subpage_of_index', *args, **kwargs)
+
+    def test(self):
+        self.run_dox2html5(wildcard='*.xml')
+        self.assertEqual(*self.actual_expected_contents('page.html'))
+        self.assertEqual(*self.actual_expected_contents('pages.html'))