JordanShurmer / eleventy-plugin-nesting-toc

11ty plugin to generate a TOC from page content
17 stars 5 forks source link

Add ability to filter out certain elements when constructing labels #6

Closed Princesseuh closed 3 years ago

Princesseuh commented 3 years ago

This fix #5 by allowing users to add a list of items to filter out when constructing the labels for the toc.

It works like so:

const toc = new Toc(`
        <h1>Page Title</h1>
            <h2 id="section1">Section 1</h2>
            <h2 id="section2">Section 2 <a class="permalink">#</a></h2>
`, {ignoredElements: ['.permalink']})

result in the following html:

<ol>
    <li>
        <a href="#section1">Section 1</a>
    </li>
    <li>
        <a href="#section2">Section 2</a>
    </li>
</ol>

Before this PR, it would have resulted in Section 2 being Section 2 # instead of Section 2. Tests have been added and the README has been edited.

JordanShurmer commented 3 years ago

This looks great. Thanks @Princesseuh