generated from dustin-jw/eleventy-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support heading IDs for jump links (#264)
* chore: install markdown-it-attrs * chore: support ID attributes in markdown * chore: install markdown-it-anchor * feat: support permalinks to headings within pages * feat: tweak styles * chore: remove unused attrs plugin * chore: update dependencies * chore: resolve breaking eslint changes * feat: show permalinks when hovering isn't viable
- Loading branch information
1 parent
d1d5f29
commit 3824ba3
Showing
10 changed files
with
242 additions
and
560 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,52 @@ | ||
const hljs = require('highlight.js'); | ||
const md = require('markdown-it'); | ||
const markdownIt = require('markdown-it'); | ||
const markdownItAnchor = require('markdown-it-anchor'); | ||
|
||
module.exports = function (eleventyConfig) { | ||
eleventyConfig.addPassthroughCopy({ 'src/public': '/' }); | ||
eleventyConfig.addPassthroughCopy({ 'src/public': '/' }); | ||
|
||
const markdownOptions = { | ||
html: true, | ||
highlight: function (str, lang) { | ||
if (lang && hljs.getLanguage(lang)) { | ||
try { | ||
return `<pre tabindex="0" role="region" aria-label="Code sample"><code class="language-${lang}">${ | ||
const markdownOptions = { | ||
html: true, | ||
highlight: function (str, lang) { | ||
if (lang && hljs.getLanguage(lang)) { | ||
try { | ||
return `<pre tabindex="0" role="region" aria-label="Code sample"><code class="language-${lang}">${ | ||
hljs.highlight(str, { | ||
language: lang, | ||
ignoreIllegals: true, | ||
}).value | ||
}</code></pre>`; | ||
} catch { | ||
// swallow error, fall through to default case | ||
} | ||
} | ||
} catch { | ||
// swallow error, fall through to default case | ||
} | ||
} | ||
|
||
return `<pre tabindex="0" role="region" aria-label="Code sample"><code>${md.utils.escapeHtml(str)}</code></pre>`; | ||
}, | ||
}; | ||
return `<pre tabindex="0" role="region" aria-label="Code sample"><code>${markdownIt.utils.escapeHtml(str)}</code></pre>`; | ||
}, | ||
}; | ||
|
||
eleventyConfig.setLibrary('md', md(markdownOptions)); | ||
eleventyConfig.addLayoutAlias('default', 'partials/layout.njk'); | ||
const md = markdownIt(markdownOptions) | ||
.use(markdownItAnchor, { | ||
level: 2, | ||
permalink: markdownItAnchor.permalink.linkAfterHeader({ | ||
class: 'cmp-permalink__link', | ||
style: 'visually-hidden', | ||
assistiveText: (title) => `Permalink: ${title}`, | ||
visuallyHiddenClass: 'util-visually-hidden', | ||
placement: 'before', | ||
wrapper: ['<div class="cmp-permalink__wrapper">', '</div>'], | ||
}), | ||
}); | ||
|
||
return { | ||
dir: { | ||
input: 'pages', | ||
output: 'dist', | ||
includes: '../src', | ||
}, | ||
markdownTemplateEngine: 'njk', | ||
}; | ||
eleventyConfig.setLibrary('md', md); | ||
eleventyConfig.addLayoutAlias('default', 'partials/layout.njk'); | ||
|
||
return { | ||
dir: { | ||
input: 'pages', | ||
output: 'dist', | ||
includes: '../src', | ||
}, | ||
markdownTemplateEngine: 'njk', | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const globals = require('globals'); | ||
const js = require('@eslint/js'); | ||
const prettier = require('eslint-config-prettier'); | ||
|
||
module.exports = [ | ||
js.configs.recommended, | ||
prettier, | ||
{ | ||
languageOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
globals: { | ||
...globals.browser, | ||
...globals.node, | ||
...globals.es2021, | ||
}, | ||
}, | ||
}, | ||
{ | ||
ignores: ['node_modules', 'dist'], | ||
}, | ||
]; |
Oops, something went wrong.