1

I'm new to markdown and I'm writing a README.md file in Github. I know how to create a table of contents with markdown and also a separate collapsible section.

Is there a way to create a collapsible table of contents with markdown? (A table of contents, which can be collapsed by the user's click.)

## Table of Contents
-   [Regex](#regex)


<details>
  <summary>Table of Contents</summary>
  -   I want to add a link to the *Regex* section in my markdown.
</details>



### Regex
The details will be here...
dan1st
  • 12,568
  • 8
  • 34
  • 67
fsefidabi
  • 153
  • 1
  • 12
  • How are you currently creating a table of contents and a collapsible section? Neither of those things are part of Markdown itself. Are you using HTML? A Markdown tool that has nonstandard extensions? – ChrisGPT was on strike Oct 27 '21 at 17:43
  • [Table of contents](https://stackoverflow.com/questions/11948245/markdown-to-create-pages-and-table-of-contents) / [collapsible section](https://stackoverflow.com/questions/31562552/collapsible-header-in-markdown-to-html) – fsefidabi Oct 27 '21 at 17:49
  • 1
    Each of those questions has multiple answers across multiple tools. What are _you_ doing? What tools are _you_ using? And don't just link to another question, [edit] your question to show a [mre]. Please read [ask]. – ChrisGPT was on strike Oct 27 '21 at 17:56
  • I'm not using any special tool. I just wanted to write a simple `README.md` file for a Github repo. – fsefidabi Oct 27 '21 at 18:00
  • 2
    Then GitHub is your tool. But your sample Markdown should be _here, as inline code_, not in GitHub. Don't make it hard for us to help you. If the code is here we can look at it and answer. If it's on GitHub, we need to click over to your GitHub repository, then navigate to the README file, then open the raw view, then look at it, _then_ come back and answer. And if you remove the code on GitHub, your question becomes useless to future users. Again, please read [ask]. – ChrisGPT was on strike Oct 27 '21 at 20:06
  • Yes, you're right. I edited my question. Could you please help me if there is any way to implement it? – fsefidabi Oct 28 '21 at 02:35

1 Answers1

0

From what I see, it looks like you want the 'Table of Contents' to be a heading. While I don't know how to do make a heading collapsible, you can work around that by styling your summary to look like a heading this way:

<style>

    #tableOfContents {
        font-size: 1.5em;
    }

</style>

<p>
<details>
<summary id="tableOfContents">Table of Contents</summary>

- [Regex](#regex)

</details>
</p>

### Regex
The details will be here..
Sherpad
  • 1
  • 2
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 09 '22 at 13:33