markdown-toc
markdown-toc copied to clipboard
markdown-toc will generate parts of toc from the content of html tag, like <pre>
I have a markdown file which contain <pre> tag. The content of <pre> is another markdown string. The bug is fired at this situation.
I use this in many different documents that have markdown inside of pre tags and I've never seen this happen. Please provide an example of what's causing the bug so that we can reproduce it.
I write a simple test, like below, and find that if "## test2" and "## test3" are at the head of line, bug will happen.
it('toc', () => {
console.log(toc(`
<pre>
## test2
## test3
</pre>
`).content);
});
result is :
- [test2](#test2)
- [test3](#test3)
command line or API?
edit: thanks for the detail
API calling. "##test2" and "##test3" must be at the beginning of the line.
let toc = require('markdown-toc');
describe('index', () => {
it('toc', () => {
console.log(toc(`
<pre>
## test2
## test3
</pre>
`).content); // I got : - [test2](#test2) \n - [test3](#test3)
});
});
After thinking about this, I think that's technically correct as it is. If you were to use gfm instead of <pre>, you would get the following (using an array because of the nested backticks):
let toc = require('markdown-toc');
console.log(toc([
'# One',
'# Two',
'````',
'## test2',
'## test3',
'````',
'# Three',
'```',
'## test4',
'## test5',
'```',
'# Four',
].join('\n')).content);
// yields
// - [One](#one)
// - [Two](#two)
// - [Three](#three)
// - [Four](#four)
I'd be happy to take a pr to add support for HTML tags - I see the usefulness of it, but we would need to weigh it against the technical debt of the edge cases and code complexity it would add.