jdsteinbach / eleventy-plugin-toc

11ty plugin to generate a TOC from page content
61 stars 19 forks source link

PluginTOC renders permalink symbol from markdown-it #33

Open davidjost opened 2 years ago

davidjost commented 2 years ago

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 commented 2 years ago

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 }}