Skip to content

Commit

Permalink
docs: support unicode anchors (#16782)
Browse files Browse the repository at this point in the history
* docs: fix: support unicode anchor

* update
  • Loading branch information
kecrily committed Feb 18, 2023
1 parent 5fbc0bf commit 7b9e9bf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
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, "img-container", {})
.use(markdownItContainer, "correct", {})
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

0 comments on commit 7b9e9bf

Please sign in to comment.