Skip to content

Commit ccd1415

Browse files
committed
add a anchor visible sign on non-H1 headers
1 parent c2c57e4 commit ccd1415

File tree

4 files changed

+178
-182
lines changed

4 files changed

+178
-182
lines changed

.eleventy.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,28 @@ module.exports = function (eleventyConfig) {
3737
eleventyConfig.addPlugin(pluginRss);
3838
eleventyConfig.addPlugin(syntaxHighlight);
3939

40-
//Slugify (add strict mode)
41-
const markdownItAnchorOptions = {
42-
level: [1, 2, 3],
40+
//Replace Markdown with custom configurations
41+
const md = markdownIt({
42+
html: true,
43+
linkify: true,
44+
typographer: true
45+
}).use(markdownItAnchor, {
46+
level: [2, 3, 4, 5, 6],
4347
slugify: (str) =>
4448
slugify(str, {
4549
lower: true,
4650
strict: true,
4751
remove: /["]/g,
4852
}),
49-
};
53+
permalink: markdownItAnchor.permalink.linkInsideHeader({
54+
symbol: ' #',
55+
placement: 'after',
56+
ariaHidden: true,
57+
class: 'header-anchor',
58+
}),
59+
});
5060

51-
//Replace Markdown with custom configurations
52-
eleventyConfig.setLibrary("md", markdownIt().use(markdownItAnchor, markdownItAnchorOptions))
61+
eleventyConfig.setLibrary("md", md);
5362

5463
//Search: pageFind
5564
eleventyConfig.on('eleventy.after', () => {

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
},
4343
"dependencies": {
4444
"eleventy-plugin-youtube-embed": "^1.11.0",
45+
"markdown-it": "^14.1.0",
46+
"markdown-it-attrs": "^4.3.1",
4547
"remove": "^0.1.5",
4648
"slugify": "^1.6.6"
4749
},

src/css/main.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,18 @@
5757
text-decoration: none;
5858
color: #7f7f7f;
5959
}
60+
61+
.header-anchor {
62+
text-decoration: none;
63+
margin-left: 0.25em;
64+
font-weight: normal;
65+
visibility: hidden;
66+
}
67+
68+
h2:hover .header-anchor,
69+
h3:hover .header-anchor,
70+
h4:hover .header-anchor,
71+
h5:hover .header-anchor,
72+
h6:hover .header-anchor {
73+
visibility: visible;
74+
}

0 commit comments

Comments
 (0)