alanwalk / markdown-toc

MarkdownTOC(Table Of Contents) Plugin for Visual Studio Code.
MIT License
141 stars 111 forks source link

Code snippet of same name directly following heading interferes with TOC: insert/update #69

Closed miller-productions closed 3 years ago

miller-productions commented 5 years ago

Hi Alan,

Thanks for creating markdown-toc, I enjoy using it.

I recently discovered a really bizarre edge case bug that you might be interested in.


Summary

If you have a heading line which is directly followed by a <code-snippet-with-angle-brackets> and the code snippet has the same text as the heading, the TOC generated by TOC: insert/update gets cut off.

Below is an example. See how the generated TOC doesn't go further than Heading3...

------- BEGIN EXAMPLE ----------

<!-- TOC -->

- [Heading1](#heading1)
- [Heading2](#heading2)
- [Heading3](#heading3)

<!-- /TOC -->

## Heading1 ##

Some text

## Heading2 #

Some more text, with a ```<heading2>``` code snippet

## Heading3 ###

```<heading3>``` code snippet is the first entry after the heading, and has the same name

Suspect that this code snippet is the culprit

## Other Heading ##

Expect to see this other heading in the TOC

## Also Expected ##

Will this turn up in TOC?
mcornella commented 3 years ago

This is a problem in the algorithm of detecting code blocks. That said, ``</code> is only used for multiline code blocks, you should just use.

EDIT: actually I think it doesn't make sense to fix a wrongly formatted document. If you see wrong results it'll make you try to fix your syntax.

miller-productions commented 3 years ago

Thanks @mcornella

If I understand what you have said correctly, does that mean the issue doesn't exist if you:

a) use triple back-ticks ``` for a multi-line code block...

e.g. this
over several 
lines

b) use single back-ticks ` for single-line code example

e.g. this on one line

Did I get that right?

mcornella commented 3 years ago

From what I've tested it seems this is how it works yeah.