Releases: cmaas/markdown-it-table-of-contents
v0.8.0
v0.7.0
- Added: Override the container element
⚠️ BREAKING CHANGE: The plugin moved from inline mode to block mode (fixes #62)- Changed: Updated tests, readme etc.
- Removed: Old forceFullToc attribute
Override the container element
Two new options that accept functions that return HTML to render custom containers (and more elements if necessary):
md.use(markdownItTOC, {
transformContainerOpen: () => {
return '<nav class="my-toc"><button>Toggle</button><h3>Table of Contents</h3>';
},
transformContainerClose: () => {
return '</nav>';
}
});
Inline mode is now block mode
Input:
[[toc]]
Output before:
<p><div class="table-of-contents"></div></p>
Output now:
<div class="table-of-contents"></div>
The TOC now is generated in block mode, which removes the wrapping p
tag. Wrapping a div
in a p
is considered invalid HTML.
If you really need a wrapping p-element, you can emulate the old behavior with the new container override functions:
const md = new MarkdownIt();
md.use(markdownItTOC, {
transformContainerOpen: () => {
return '<p><div class="table-of-contents">';
},
transformContainerClose: () => {
return '</div></p>';
}
});
Be aware that the old tests/examples now behave differently when using soft breaks before the [[toc]] markup:
Input:
# Article
Text with soft line break (two spaces)
[[toc]]
## Headline
Output before:
<h1>Article</h1>
<p>Text with soft line break (two spaces)<br>
<div class="table-of-contents">...</div></p>
Output now:
<h1>Article</h1>
<p>Text with soft line break (two spaces)</p>
<div class="table-of-contents">...</div>
v0.6.0
The TOC generator was rewritten, because the old on-the-fly generator couldn't deal with unexpected order of headings and double-indentations. It is now a three-step process:
- Gather all headings in a list.
- Turn that list into a nested tree.
- Generate HTML code based on the nested tree.
Although all tests pass, this release could introduce some breaking changes for you, if you relied on the old way of doing things. Check the test cases to get a better understanding how this plugin handles various cases.
- Added: Support for
markdown-it-attrs
(fixes #54) - Changed: Respects unexpected nesting order (fixes #55)
- Changed: Uses anchor targets from existing id attributes (for example, set by
markdown-it-attrs
ormarkdown-it-anchor
) - Changed: Now nests list correctly if there is a jump (for example: h2, h2, h4 -> h4 is now double-indented)
- Removed: unused tests
v0.5.2
Better handling of content "other than text" in headers. I.e links.
v0.5.1
- Exposes link to formatting function
- Adheres to platform EOL in tests
- Security patch
v0.5.0
v0.4.4
Adds an optional function for transforming the links created in the TOC.
v0.4.3
Fixes faulty parsing of certain [
-chars (#35). Thanks to @GiridharanNarayanan for fixing.
v0.4.2
Adds the possibility to specify header and footer HTML to be injected into the TOC container.
v0.4.1
Rendering bug fixed. Thanks @GiridharanNarayanan