Skip to content

Commit

Permalink
Adds support for eleventy:id-ignore attribute for IdAttribute plugi…
Browse files Browse the repository at this point in the history
…n to ignore content in nodes
  • Loading branch information
zachleat committed Sep 26, 2024
1 parent a11346d commit 98f7edc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Plugins/IdAttributePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import slugifyFilter from "../Filters/Slugify.js";
import MemoizeUtil from "../Util/MemoizeFunction.js";

function getTextNodeContent(node) {
if (node.attrs?.["eleventy:id-ignore"] === "") {
delete node.attrs["eleventy:id-ignore"];
return "";
}
if (!node.content) {
return "";
}
Expand Down
13 changes: 13 additions & 0 deletions test/IdAttributePluginTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ test("Using the IdAttribute plugin #3356", async (t) => {
t.is(results[0].content, `<h1 id="this-is-a-heading">This is a heading</h1><h2 id="already">This is another heading</h2><h2 id="this-is-another-heading">This is another heading</h2><h3 id="this-is-another-heading-2">This is another heading</h3>`);
});

test("Using the IdAttribute plugin, ignore attribute #3356", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", "./test/stubs-virtual/_site", {
config: function (eleventyConfig) {
eleventyConfig.addPlugin(IdAttributePlugin);

eleventyConfig.addTemplate("test.njk", `<h1>This is a heading</h1><h2 id="already">This is another heading</h2><h2>This is another heading</h2><h3>This is another <span eleventy:id-ignore>heading</span></h3>`, {});
},
});

let results = await elev.toJSON();
t.is(results[0].content, `<h1 id="this-is-a-heading">This is a heading</h1><h2 id="already">This is another heading</h2><h2 id="this-is-another-heading">This is another heading</h2><h3 id="this-is-another">This is another <span>heading</span></h3>`);
});

test("Using the IdAttribute plugin with escaped quoted text", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", "./test/stubs-virtual/_site", {
config: function (eleventyConfig) {
Expand Down

0 comments on commit 98f7edc

Please sign in to comment.