Add support for slashes in tags

This commit is contained in:
Ole Eskild Steensen 2023-01-21 12:03:39 +01:00
parent 3176a78c03
commit 255e1d531d

View File

@ -8,6 +8,8 @@ const { parse } = require("node-html-parser");
const { headerToId, namedHeadingsFilter } = require("./src/helpers/utils"); const { headerToId, namedHeadingsFilter } = require("./src/helpers/utils");
const tagRegex = /(^|\s|\>)(#[^\s!@#$%^&*()=+\.,\[{\]};:'"?><]+)(?!([^<]*>))/g;
module.exports = function (eleventyConfig) { module.exports = function (eleventyConfig) {
let markdownLib = markdownIt({ let markdownLib = markdownIt({
breaks: true, breaks: true,
@ -194,7 +196,7 @@ module.exports = function (eleventyConfig) {
return ( return (
str && str &&
str.replace( str.replace(
/(^|\s|\>)(#[^\s!@#$%^&*()=+\.\/,\[{\]};:'"?><]+)(?!([^<]*>))/g, tagRegex,
function (match, precede, tag) { function (match, precede, tag) {
return `${precede}<a class="tag" onclick="toggleTagSearch(this)">${tag}</a>`; return `${precede}<a class="tag" onclick="toggleTagSearch(this)">${tag}</a>`;
} }
@ -207,7 +209,7 @@ module.exports = function (eleventyConfig) {
let match = let match =
str && str &&
str.match( str.match(
/(^|\s|\>)(#[^\s!@#$%^&*()=+\.\/,\[{\]};:'"?><]+)(?!([^<]*>))/g tagRegex,
); );
if (match) { if (match) {
tags = match tags = match