Skip to content

Commit c43a377

Browse files
authored
Make imports/exports not be a dropdown in sidebar (nim-lang#19907)
* Don't make a section be a dropdown if it has no child links * - Cleaned up code - Updated tests * Document what the 'if' is checking
1 parent 094d86f commit c43a377

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

compiler/docgen.nim

+14-3
Original file line numberDiff line numberDiff line change
@@ -1474,10 +1474,21 @@ proc genSection(d: PDoc, kind: TSymKind, groupedToc = false) =
14741474
for item in d.tocSimple[kind].sorted(cmp):
14751475
d.toc2[kind].add item.content
14761476

1477-
d.toc[kind] = getConfigVar(d.conf, "doc.section.toc") % [
1478-
"sectionid", $ord(kind), "sectionTitle", title,
1479-
"sectionTitleID", $(ord(kind) + 50), "content", d.toc2[kind]]
1477+
let sectionValues = @[
1478+
"sectionID", $ord(kind), "sectionTitleID", $(ord(kind) + 50),
1479+
"sectionTitle", title
1480+
]
14801481

1482+
# Check if the toc has any children
1483+
if d.toc2[kind] != "":
1484+
# Use the dropdown version instead and store the children in the dropdown
1485+
d.toc[kind] = getConfigVar(d.conf, "doc.section.toc") % (sectionValues & @[
1486+
"content", d.toc2[kind]
1487+
])
1488+
else:
1489+
# Just have the link
1490+
d.toc[kind] = getConfigVar(d.conf, "doc.section.toc_item") % sectionValues
1491+
14811492
proc relLink(outDir: AbsoluteDir, destFile: AbsoluteFile, linkto: RelativeFile): string =
14821493
$relativeTo(outDir / linkto, destFile.splitFile().dir, '/')
14831494

config/nimdoc.cfg

+8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ doc.section = """
1616
</div>
1717
"""
1818
19+
# Just a single item in the TOC (e.g. imports, exports)
20+
doc.section.toc_item = """
21+
<li>
22+
<a class="reference reference-toplevel" href="#$sectionID" id="$sectionTitleID">$sectionTitle</a>
23+
</li>
24+
"""
25+
26+
# This is a section (e.g. procs, types) in the TOC which gets turned into a drop down
1927
doc.section.toc = """
2028
<li>
2129
<details open>

nimdoc/testproject/expected/testproject.html

+1-6
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,7 @@ <h1 class="title">testproject</h1>
5151
</div>
5252
<ul class="simple simple-toc" id="toc-list">
5353
<li>
54-
<details open>
55-
<summary><a class="reference reference-toplevel" href="#6" id="56">Imports</a></summary>
56-
<ul class="simple simple-toc-section">
57-
58-
</ul>
59-
</details>
54+
<a class="reference reference-toplevel" href="#6" id="56">Imports</a>
6055
</li>
6156
<li>
6257
<details open>

0 commit comments

Comments
 (0)