Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: support unicode anchors #16782

Merged
merged 2 commits into from Feb 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 2 additions & 13 deletions docs/.eleventy.js
Expand Up @@ -64,23 +64,12 @@ module.exports = function(eleventyConfig) {

eleventyConfig.addFilter("jsonify", variable => JSON.stringify(variable));

/**
* Takes in a string and converts to a slug
* @param {string} text text to be converted into slug
* @returns {string} slug to be used as anchors
*/
function slugify(text) {
return slug(text.replace(/[<>()[\]{}]/gu, ""))
// eslint-disable-next-line no-control-regex -- used regex from https://github.com/eslint/archive-website/blob/master/_11ty/plugins/markdown-plugins.js#L37
.replace(/[^\u{00}-\u{FF}]/gu, "");
}

eleventyConfig.addFilter("slugify", str => {
if (!str) {
return "";
}

return slugify(str);
return slug(str);
});

eleventyConfig.addFilter("URIencode", str => {
Expand Down Expand Up @@ -193,7 +182,7 @@ module.exports = function(eleventyConfig) {
const markdownIt = require("markdown-it");
const md = markdownIt({ html: true, linkify: true, typographer: true, highlight: (str, lang) => highlighter(md, str, lang) })
.use(markdownItAnchor, {
slugify
slugify: s => slug(s)
})
.use(markdownItContainer, "correct", {})
.use(markdownItContainer, "incorrect", {})
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Expand Up @@ -31,7 +31,7 @@
"eleventy-plugin-nesting-toc": "^1.3.0",
"eleventy-plugin-page-assets": "^0.3.0",
"eleventy-plugin-reading-time": "^0.0.1",
"github-slugger": "^1.4.0",
"github-slugger": "^1.5.0",
"imagemin": "^8.0.1",
"imagemin-cli": "^7.0.0",
"js-yaml": "^3.14.1",
Expand Down