medfreeman / markdown-it-toc-and-anchor

markdown-it plugin to add a toc and anchor links in headings
MIT License
60 stars 35 forks source link

Paragraph wraps TOC #25

Open Avol-V opened 7 years ago

Avol-V commented 7 years ago

When I try to place TOC with placeholder @[toc], it produce paragraph tags around.

        md.use(
            markdownItTocAndAnchor,
            {
                toc: true,
                tocFirstLevel: 2,
                tocLastLevel: 3,
                anchorLink: false
            }
        );
# Header 1

@[toc]

## Subheader 1

Test text
<h1 id="header-1">Header 1</h1>
<p><ul class="markdownIt-TOC">
<li><a href="#subheader-1">Subheader 1</a></li>
</ul>
</p>
<h2 id="subheader-1">Subheader 1</h2>
<p>Test text</p>
medfreeman commented 7 years ago

Hi,

i'm not sure that's an issue, that's how this plugin has been designed right from the start. If you need i could add a 'wrap' option or something like that, that defines in which element the toc is wrapped, with a default of 'p', to preserve compatibility. Or feel free to provide a pr, haven't got much time for the rest of the month.

Avol-V commented 7 years ago

Thanks for the quick response! It looks like issue, because <ul> can't be inside <p>. Browser transforms it into empty <p></p>, before and after <ul>…</ul>. It would be great if you add an option for change this tag, or even to remove it (UL with class seems sufficient).

Avol-V commented 7 years ago

As I see, we must to change chain type from inline to block and the rule to place after. But it breaks code and I don't know how to work with markdown-it plugin system.

I still try to work with it, but I do't have much time.

pmpinto commented 1 year ago

@medfreeman Not a lot happened around here since this was reported. Allow me to emphasise what @Avol-V mentioned: The <ul> can't be placed inside a <p> — that's invalid markup.

I assume that at some point @[toc] is being replaced with the actual list markup. Perhaps that's happening after markdown-it has converted @[toc] to <p>@[toc]</p>?

Could this be easily solved just by replacing <p>@[toc]</p> with the list markup? Or is that too farfetched?