Skip to content

Generate TOC when exporting to HTML/PDF #80

Closed

Description

@joe223

A new feature:TOC

If there is a way to generator TOC automatically. Or, I just type [toc] in the first line,it will turn to A catalog and update while content is changing.

Activity

  1. joe223 commented on Mar 26, 2018

    @joe223
    Author

    weird, I can not add a Label.

  2. added
    🦄 feature request
    on Mar 26, 2018
  3. Jocs commented on Mar 26, 2018

    @Jocs
    Member

    @joe223 Do you mean to write HTML directly in Mark Text?

  4. joe223 commented on Mar 26, 2018

    @joe223
    Author

    @Jocs just write [TOC].

    example markdown content:

    [toc]
    
    # Chapter 1
    
    ## Chapter 1.1
    
    ## Chapter 1.2
    
    # Chapter 2

    finally, we got

    <ul class="toc">
        <li><a href="#1">Chapter 1</a></li>
            <ul class="toc">
                <li><a href="#1-1">Chapter 1-1</a></li>
                <li><a href="#1-2">Chapter 1-2</a></li>
            </ul>
        <li><a href="#2">Chapter 2</a></li>
    </ul>
    
    # Chapter 1
    
    ## Chapter 1.1
    
    ## Chapter 1.2
    
    # Chapter 2
  5. Jocs commented on Mar 26, 2018

    @Jocs
    Member

    weird, I can not add a Label.
    What's the meaning?

  6. joe223 commented on Mar 27, 2018

    @joe223
    Author

    image

    Only owner can set this.

  7. khaosdoctor commented on Apr 13, 2018

    @khaosdoctor

    I think there's an easier way to set a TOC within the text editor, like the VSCode extension does. Instead of adding a HTML string, just add more Markdown stuff inside some marked comments.

  8. self-assigned this
    on May 27, 2018
  9. gitfineon commented on Jun 29, 2018

    @gitfineon

    TOC is not defined in GFM, so I suggest to only add this as export option. Because how do you want to keep the table of contents up-to-date if there is already one inserted. You have to delete the old one and insert it again.

    An export option for instance by replacing a special string like %TOC-H3% with the markdown representation of all headlines down to level 3 would be easier. A live representation is already there, so we don't need it twice.

    But this is a non-critical feature, it does not make Mark Text more stable. Why is it selected for A more stable Mark Text . How about adding adding a Feature Wishlist project for the fun stuff.

  10. Jocs commented on Jun 29, 2018

    @Jocs
    Member

    Why hasn't the TOC function been implemented?
    Because I haven’t discovered the TOC in other places so far, I have not add it to Mark Text.
    As you said, it does not belong to A more stable Mark Text .

  11. fxha commented on Jan 18, 2019

    @fxha
    Contributor

    @Jocs Why was this issue closed, it's still not implemented? I think it would be a good idea and would definitely prefer @gitfineon idea to generate the TOC when exporting a document to HTML/PDF and replace the [TOC] tag. Otherwise we should mark this as plugin.

    TOC is not defined in GFM, so I suggest to only add this as export option. Because how do you want to keep the table of contents up-to-date if there is already one inserted. You have to delete the old one and insert it again.

    An export option for instance by replacing a special string like %TOC-H3% with the markdown representation of all headlines down to level 3 would be easier. A live representation is already there, so we don't need it twice.

  12. changed the title [-]Support TOC[/-] [+]Generate TOC when exporting to HTML/PDF[/+] on Jan 23, 2019
  13. reopened this on Jan 23, 2019
  14. Jocs commented on Jan 24, 2019

    @Jocs
    Member

    @fxha Yes, it is not implemented, because TOC is not the syntax in the GFM standard, and we also implemented TOC navigation in the sidebar, so I thought it was not necessary to implement it. When exporting, I think we can add an option. Whether to export the TOC. This is a good idea, maybe add it later when optimizing the export feature.

  15. 5 remaining items

  16. dakira commented on Nov 4, 2019

    @dakira

    @Jocs There doesn't need to be any extra syntax. Just ask if a TOC should be included on export. stackedit.io allows for this:

    Bildschirmfoto 2019-11-04 um 21 29 17

    The result adds a navigational sidebar to the html like this:

    Bildschirmfoto 2019-11-04 um 21 33 50

  17. tweinreich commented on Nov 7, 2019

    @tweinreich

    @fxha Yes, it is not implemented, because TOC is not the syntax in the GFM standard, and we also implemented TOC navigation in the sidebar, so I thought it was not necessary to implement it. When exporting, I think we can add an option. Whether to export the TOC. This is a good idea, maybe add it later when optimizing the export feature.

    The GFM should be considered minimal requirements, not maximum allowed. Additional features will not harm its use. There are other additional features in Marktext that are not part of GFM so I don't see why this can't be an editor feature. The sidebar navigation feels very much like an addon and removes the clean interface of seeing only the document itself how the author intended. Many documents are created using [TOC] which is supported on other editors.

    I also hope it doesn't define the maximum that is possible. A [TOC] that is visible while editing, updates itself and also appears in an export would be really nice (I don't like the sidebar opened while writing as well).

    Edit:
    @DutchPete Yes they have done an awesome job and I don't think anyone wants to complain here.

    I think it should be possible to discuss features in an open source community though.

    Dorian-DS expresses a valid view in my opinion and I would as well prefer to have a [TOC]-element like e.g. Typora,

  18. kataras commented on Nov 9, 2020

    @kataras

    Hello,

    This feature is not yet implemented? I am trying for hours to find a way to generate a TOC here...

  19. fxha commented on Nov 13, 2020

    @fxha
    Contributor

    I already have a basic implementation for this locally and can create a draft PR in the following days. It's not feature rich but works for navigating the file.

  20. CrystalRays commented on Jun 29, 2021

    @CrystalRays

    Could Mark Text export pdf with the index?
    What I mean is not the content table in document but the index info that could be recognized by the pdf viewer which will show it on the side bar.

  21. kouichi-c-nakamura commented on Nov 26, 2021

    @kouichi-c-nakamura

    Please give us a choice in Preference to enanle [toc] on Editor. It's simply a pain to go deal with a big markdown without [toc] jumps. Otherwise I may have to find another alternative...

  22. qds-soft commented on Jan 21, 2022

    @qds-soft

    GitLab has [TOC] implemented now. Would be really helpful to see it implemented in marktext, since I'm writeng quite extensive documentations for my projects.
    I'd love to see it. Otherwise marktext is a really awesome editor.

  23. weironz commented on Apr 11, 2022

    @weironz

    WE NEED IT ,THANKS

  24. SekoiaTree commented on Apr 11, 2022

    @SekoiaTree

    I dug through the code a bit; even though the implementation for exports is "there", it seems that the option is disabled. Is that intentional?

    const generateHtmlToc = (tocList, slugger, currentLevel, options) => {
    returns nothing if tocList is empty, and that method is called by
    export const getHtmlToc = (toc, options = {}) => {
    where the parameter toc is passed to generateHtmlToc.
    This is then called by
    const htmlToc = getHtmlToc(this.editor.getTOC(), options)
    , which passes this.editor.toc, which is created by
    const { container } = this.editor = new Muya(ele, options)
    , which does not have any "toc" object. Therefore, the table of contents is never generated.

    Several places also use

    async renderHtml (toc) {
    with no toc parameter passed, so maybe that's also the cause?

  25. 2catycm commented on Jun 23, 2022

    @2catycm

    Hello,

    This feature is not yet implemented? I am trying for hours to find a way to generate a TOC too.

  26. allenzt commented on Jul 14, 2022

    @allenzt

    Hi guys, thanks for your excellent work! Do you have any update?

  27. DutchPete commented on Jul 14, 2022

    @DutchPete

    @allenzt have a look at this: #1290 (comment)

  28. Jocs commented on Jun 26, 2026

    @Jocs
    Member

    Thank you for this request. Both of the features discussed in this thread are now implemented in MarkText:

    TOC navigation sidebar — a live, collapsible table of contents panel in the side bar tracks headings as you edit (View → Toggle Side Bar).

    TOC in HTML/PDF export — if your document contains a standalone [TOC] line, it is replaced with a fully linked table of contents in the exported HTML/PDF. The export settings dialog lets you control whether the top-level heading is included and set a custom title for the TOC section.

    These features are backed by the muya.getTOC() API in the new editor engine (packages/muya/src/state/getTOC.ts) and wired into the export pipeline in packages/desktop/src/renderer/src/util/exportHtml.ts and pdf.ts.

    Closing as already implemented. If you encounter a specific gap or regression, please open a new issue with reproduction steps and the MarkText version.

  29. Ken-Leo commented on Sep 4, 2026

    @Ken-Leo

    Even so, the exported PDF files DO NOT have page numbering in the TOC and just dots. Would this be addressed in the future?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🕊️ export/pdf🐾export/html🦄 feature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions