summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/docgen.nim17
-rw-r--r--config/nimdoc.cfg8
-rw-r--r--nimdoc/testproject/expected/testproject.html7
3 files changed, 23 insertions, 9 deletions
diff --git a/compiler/docgen.nim b/compiler/docgen.nim
index ed5fe06ef..d728c535f 100644
--- a/compiler/docgen.nim
+++ b/compiler/docgen.nim
@@ -1474,10 +1474,21 @@ proc genSection(d: PDoc, kind: TSymKind, groupedToc = false) =
     for item in d.tocSimple[kind].sorted(cmp):
       d.toc2[kind].add item.content
 
-  d.toc[kind] = getConfigVar(d.conf, "doc.section.toc") % [
-      "sectionid", $ord(kind), "sectionTitle", title,
-      "sectionTitleID", $(ord(kind) + 50), "content", d.toc2[kind]]
+  let sectionValues = @[
+     "sectionID", $ord(kind), "sectionTitleID", $(ord(kind) + 50),
+     "sectionTitle", title
+  ]
 
+  # Check if the toc has any children
+  if d.toc2[kind] != "":
+    # Use the dropdown version instead and store the children in the dropdown
+    d.toc[kind] = getConfigVar(d.conf, "doc.section.toc") % (sectionValues & @[
+       "content", d.toc2[kind]
+    ])
+  else:
+    # Just have the link
+    d.toc[kind] =  getConfigVar(d.conf, "doc.section.toc_item") % sectionValues
+    
 proc relLink(outDir: AbsoluteDir, destFile: AbsoluteFile, linkto: RelativeFile): string =
   $relativeTo(outDir / linkto, destFile.splitFile().dir, '/')
 
diff --git a/config/nimdoc.cfg b/config/nimdoc.cfg
index 3b0afe8d6..7aee50d8c 100644
--- a/config/nimdoc.cfg
+++ b/config/nimdoc.cfg
@@ -16,6 +16,14 @@ doc.section = """
 </div>
 """
 
+# Just a single item in the TOC (e.g. imports, exports)
+doc.section.toc_item = """
+<li>
+  <a class="reference reference-toplevel" href="#$sectionID" id="$sectionTitleID">$sectionTitle</a>
+</li>
+"""
+
+# This is a section (e.g. procs, types) in the TOC which gets turned into a drop down
 doc.section.toc = """
 <li>
   <details open>
diff --git a/nimdoc/testproject/expected/testproject.html b/nimdoc/testproject/expected/testproject.html
index 24dfdc13f..5fb9e697c 100644
--- a/nimdoc/testproject/expected/testproject.html
+++ b/nimdoc/testproject/expected/testproject.html
@@ -51,12 +51,7 @@
     </div>
     <ul class="simple simple-toc" id="toc-list">
   <li>
-  <details open>
-    <summary><a class="reference reference-toplevel" href="#6" id="56">Imports</a></summary>
-    <ul class="simple simple-toc-section">
-      
-    </ul>
-  </details>
+  <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
 </li>
 <li>
   <details open>