Skip to content

Commit 3901242

Browse files
committed
Add links to index on function definitions
1 parent e1535f4 commit 3901242

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ src/**/*.tex
2929

3030
# For the Mac (Finder metatdata files)
3131
*.DS_Store
32+
33+
.luarc.json

src/html-index.lua

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@
44
-- This is combined with the output of the gen_index.py script
55
-- to create a clickable index of all the functions in the documentation
66

7+
8+
index = quarto.utils.resolve_path("./functions-reference/functions_index.qmd")
9+
indexText = io.open(index):read("*a")
10+
711
function extractIndexEntry(elementText)
812
if elementText:find("%; %-%-%>$") ~= nil then
913
return "index-entry-" .. tostring(pandoc.sha1(elementText))
1014
end
1115
return nil
1216
end
1317

14-
if FORMAT == "latex" then
15-
return {} -- latex uses mkindex, not this
16-
else
18+
function escape(text)
19+
return text:gsub("\\", "\\\\"):gsub("*", "\\*")
20+
end
21+
22+
if quarto.doc.is_format("html") then -- latex uses mkindex, not this
1723
return {
1824
RawBlock = function(el)
1925
if el.format == "html" then
@@ -23,6 +29,22 @@ else
2329
end
2430
end
2531
return nil -- no change
32+
end,
33+
Strong = function(el2)
34+
return pandoc.walk_inline(el2, {
35+
Code = function(el3)
36+
if el3.text ~= nil then
37+
-- only create a link if this appears in the index
38+
local escaped = escape(el3.text)
39+
if indexText:find(escaped, 1, true) ~= nil then
40+
return pandoc.Link(el3, "./functions_index.qmd#" .. escaped,
41+
"Jump to index entry", {class="unlink"})
42+
end
43+
end
44+
return nil
45+
end
46+
})
2647
end
2748
}
49+
2850
end

src/theming/quarto_styles.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
}
1919
}
2020

21+
html {
22+
scroll-padding-top: 70px; /* height of header */
23+
}
2124

2225
@media (min-width: 991.98px) {
2326
#quarto-header {
@@ -308,6 +311,11 @@ a.nav-link.active { color: var(--stan-secondary);}
308311
a.sidebar-item-text.sidebar-link.active { color: var(--stan-secondary); }
309312
.sidebar.a.active { color: var(--stan-secondary); }
310313

314+
a.unlink {
315+
color: inherit;
316+
text-decoration: none;
317+
}
318+
311319

312320
div [data-bs-target^="#quarto-sidebar-section"] {
313321
font-weight: bold;

0 commit comments

Comments
 (0)