eleventy-plugin-toc icon indicating copy to clipboard operation
eleventy-plugin-toc copied to clipboard

PluginTOC renders permalink symbol from markdown-it

Open davidjost opened this issue 3 years ago • 1 comments
trafficstars

Environment

Node version: v17.0.1 OS/version: Mac OS 11.6 Big Sur

Eleventy

Eleventy version: 0.12.1 Template engine: Nunjucks

Plugin

Plugin module version: 1.1.0


Description of the issue

PluginTOC renders everything inside the h(n) tag. Markdown-it generates permalinks by placing an a tag inside the h(n) tag.

Desired output

PluginTOC renders the text content of the h(n) tag and ignores any other markup inside it.

davidjost avatar Jan 24 '22 16:01 davidjost

I solved it by writing an 11ty filter, the ☍ is the permalink symbol:

// .eleventy.js
eleventyConfig.addFilter("removeSymbol", function(value) {
    value.val = value.val.replace(/ ☍/g, "");
    return value;
  });

This needs to be applied in the template:

{{ content | toc | safe | removeSymbol }}

davidjost avatar Jan 24 '22 18:01 davidjost