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

Generate TOC when exporting to HTML/PDF #80

Open
joe223 opened this issue Mar 26, 2018 · 25 comments
Open

Generate TOC when exporting to HTML/PDF #80

joe223 opened this issue Mar 26, 2018 · 25 comments
Assignees
Labels
🕊️ export/pdf Issue about exporting to PDF or printing 🐾export/html Issue about exporting to HTML 🦄 feature request New feature or request

Comments

@joe223
Copy link

joe223 commented Mar 26, 2018

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.

@joe223
Copy link
Author

joe223 commented Mar 26, 2018

weird, I can not add a Label.

@Jocs Jocs added the 🦄 feature request New feature or request label Mar 26, 2018
@Jocs
Copy link
Member

Jocs commented Mar 26, 2018

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

@joe223
Copy link
Author

joe223 commented Mar 26, 2018

@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

@Jocs
Copy link
Member

Jocs commented Mar 26, 2018

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

@joe223
Copy link
Author

joe223 commented Mar 27, 2018

image

Only owner can set this.

@khaosdoctor
Copy link

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.

@Jocs Jocs added this to TODO List in version 0.12.xx May 20, 2018
@Jocs Jocs self-assigned this May 27, 2018
@Jocs Jocs moved this from TODO List to In progress in version 0.12.xx Jun 6, 2018
@Jocs Jocs removed this from In progress in version 0.12.xx Jun 15, 2018
@Jocs Jocs added this to todo in A more stable Mark Text Jun 18, 2018
@gitfineon
Copy link

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.

@Jocs
Copy link
Member

Jocs commented Jun 29, 2018

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 .

@Jocs Jocs removed this from todo in A more stable Mark Text Sep 11, 2018
@Jocs Jocs closed this as completed Oct 10, 2018
@fxha
Copy link
Contributor

fxha commented Jan 18, 2019

@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.

@fxha fxha changed the title Support TOC Generate TOC when exporting to HTML/PDF Jan 23, 2019
@fxha fxha reopened this Jan 23, 2019
@Jocs
Copy link
Member

Jocs commented Jan 24, 2019

@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.

@RoyiAvital
Copy link

It is important to allow the user to set the TOC Levels.

Something like TOC[2, 3, 4] which means only headers of Levels 2, 3 and 4 will enter the TOC.
The reason is usually # is used for title (Hence it shouldn't be in the TOC) and lower levels aren't needed.

@fxha fxha added 🐾export/html Issue about exporting to HTML 🕊️ export/pdf Issue about exporting to PDF or printing labels Apr 17, 2019
@Dorian-DS
Copy link

Dorian-DS commented Aug 17, 2019

@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.

@DutchPete
Copy link

The sidebar navigation feels very much like an addon and removes the clean interface of seeing only the document itself how the author intended.

I certainly do NOT agree with that, and it definitely does NOT remove the clean interface: the width can be set by the user. The sidebar navigation is a very useful feature and the devs have done a very good job implementing it.

What's more, for those who do not like the side bar or temporarily do not need it, they can turn it off in the menu, View, Toggle Side Bar.

@dakira
Copy link

dakira commented Nov 4, 2019

@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

@tweinreich
Copy link

tweinreich commented Nov 7, 2019

@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,

@kataras
Copy link

kataras commented Nov 9, 2020

Hello,

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

@fxha
Copy link
Contributor

fxha commented Nov 13, 2020

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.

@CrystalRays
Copy link

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.

@kouichi-c-nakamura
Copy link

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...

@qds-soft
Copy link

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.

@willzhang
Copy link

WE NEED IT ,THANKS

@SekoiaTree
Copy link

SekoiaTree commented Apr 11, 2022

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?

@2catycm
Copy link

2catycm commented Jun 23, 2022

Hello,

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

@allenzt
Copy link

allenzt commented Jul 14, 2022

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

@DutchPete
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🕊️ export/pdf Issue about exporting to PDF or printing 🐾export/html Issue about exporting to HTML 🦄 feature request New feature or request
Projects
None yet
Development

No branches or pull requests