Skip to content

Commit febf704

Browse files
stefanvjarrodmillman
authored andcommitted
Render header anchors
1 parent 1909bc4 commit febf704

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

assets/js/shortcuts.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ function setupShortcuts(shortcutDepth = 2) {
110110
if (shortcutsTarget) {
111111
const classElements = Array.from(document.querySelectorAll(classes));
112112
classElements.map((el) => {
113-
const title = el.textContent;
113+
// Get title but remove anchor character #
114+
const title = el.textContent.replace(/#$/, "");
114115
const elId = el.id;
115116
// Gets the element type (e.g. h2, h3)
116117
const elType = el.tagName;

assets/theme-css/styles.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,15 @@ pre {
369369
overflow: auto;
370370
}
371371

372+
/* hide headerlinks until hovered over */
373+
a.headerlink {
374+
visibility: hidden;
375+
}
376+
377+
:is(h1, h2, h3, h4, h5, h6):hover > a.headerlink {
378+
visibility: visible;
379+
}
380+
372381
/* Local Variables: */
373382
/* css-indent-offset: 2 */
374383
/* End: */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h{{ .Level }} id="{{ .Anchor | safeURL }}">{{ .Text | safeHTML }}<a class="headerlink" href="#{{ .Anchor | safeURL }}" title="Link to this heading">#</a></h{{ .Level }}>

0 commit comments

Comments
 (0)