Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content between TOC and next header gets removed #18

Closed
pascal-mugnier-sonarsource opened this issue Jul 19, 2018 · 10 comments
Closed

Content between TOC and next header gets removed #18

pascal-mugnier-sonarsource opened this issue Jul 19, 2018 · 10 comments
Labels
🙋 no/question This does not need any changes

Comments

@pascal-mugnier-sonarsource
Copy link

pascal-mugnier-sonarsource commented Jul 19, 2018

If you have content between the TOC header and the next header, the plugin will remove it.

Exemple:

## Table of Contents

Some text here...

## First title

In this example, Some teext here... will get removed.

I think this can be fixed by changing this line:

node.children.slice(result.index)

to

node.children.slice(result.endIndex)

@wooorm
Copy link
Member

wooorm commented Jul 19, 2018

Why do you think that’s a bug? IMO it’s a feature 🤷‍♂️ What else would you like to put in a toc?

@pascal-mugnier-sonarsource
Copy link
Author

I think I was not clear enough...
Let's say you have this markdown:

## Table of Contents

This is my intro text, explaining what is on this page, lorem ipsum dolor sit amet.

## Title One
### Sub title A

Some text from Sub title A

### Sub title B

Some text from Sub title B

I would expect, with the ToC plugin, to end up with something like this:

## Table of Contents
## Title One
### Sub title A
### Sub title B

This is my intro text, explaining what is on this page, lorem ipsum dolor sit amet.

## Title One
### Sub title A

Some text from Sub title A

### Sub title B

Some text from Sub title B

But I end up with:

## Table of Contents
## Title One
### Sub title A
### Sub title B

## Title One
### Sub title A

Some text from Sub title A

### Sub title B

Some text from Sub title B

The intro text gets remove.

@wooorm
Copy link
Member

wooorm commented Jul 20, 2018

Hmm, from all the tables of contents I’ve seen I think that they only house a list of the content. I don’t think I’ve seen alternative content being used.

Why not go with:

...

This is my intro text, explaining what is on this page, lorem ipsum dolor sit amet.

## Table of Contents

* Title One
  * Sub title A
  * Sub title B

## Title One
### Sub title A

Some text from Sub title A

### Sub title B

Some text from Sub title B

...

@pascal-mugnier-sonarsource
Copy link
Author

Well, this can be done this way of course. But I still think this is a bug, and it can be fixed quite easily.

Paragraphs between ToC and first title should not simply disappear IMO.

@wooorm
Copy link
Member

wooorm commented Jul 20, 2018

Currently we’re looking for a heading and replacing the whole content of that “section”. The same is done for remark-usage and remark-license. It’s used throughout the ecosystem.

Alternatively, we could look for comments, called “ranges”. See mdast-zone for more info. I believe that would be able to do what you want. I’m sure a PR to BarryThePenguin/mdast-util-toc for that support would be OK (this plugin is just a small wrapper around that).

@wooorm
Copy link
Member

wooorm commented Aug 10, 2018

Feel free to open a PR there if you’d like to add this new feature.
I don’t see your report as a bug though.

@wooorm wooorm closed this as completed Aug 10, 2018
@wooorm wooorm added the 🙋 no/question This does not need any changes label Aug 14, 2019
trevtrich added a commit to trevtrich/project-scaffolder that referenced this issue Aug 28, 2020
- if the usage section had no content, the consumer badges were being found under the TOC section. Given that the [TOC plugin expects to stomp the entire section](remarkjs/remark-toc#18), it was eating the consumer-badges target section
- fixes form8ion#475
@florianwalther-private
Copy link

I have the same problem right now. I want to have some intro text after the ToC without its own heading. Is there a way to achieve this?

@florianwalther-private
Copy link

My workaround, for now, is to add an "Intro" header to the intro section, let remark-toc skip it:

.use(remarkToc, {skip: 'Intro'})

And then I hide the h2 tag with CSS (I wanna keep the empty space):


.blogPostContainer :global(h2#intro) {
    visibility: hidden;
}

@wooorm
Copy link
Member

wooorm commented Jul 11, 2022

The same response (#18 (comment)) still holds.

twodam added a commit to nance-eth/nance-interface that referenced this issue Sep 7, 2023
…tion so the text in between won't be replaced by auto-generated TOC

remarkjs/remark-toc#18
@dereckmezquita
Copy link

@pascal-mugnier-sonarsource I created my won function to use as a plugin and shared it here: #40 (comment)

Jeff1010-web added a commit to Jeff1010-web/nance-interface that referenced this issue Jun 1, 2024
…tion so the text in between won't be replaced by auto-generated TOC

remarkjs/remark-toc#18
megalord1024 added a commit to megalord1024/nance-interface that referenced this issue Jun 22, 2024
…tion so the text in between won't be replaced by auto-generated TOC

remarkjs/remark-toc#18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 no/question This does not need any changes
Development

No branches or pull requests

4 participants