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

Feature request: enable [TOC] markers to insert table of contents in notebooks? #18

Open
maxalbert opened this issue Feb 28, 2020 · 6 comments

Comments

@maxalbert
Copy link
Contributor

Many thanks for fixing the table of contents (as of git rev. 3bd9d3b). 👍😃

One small additional feature request: in pure-markdown pages it is possible to insert a [TOC] marker somewhere in the page, which will be automatically expanded into a table of contents. [1]

Currently this doesn't seem to work for notebooks converted by mknotebooks, but it would be a useful feature, in order to be able to give an at-a-glance overview at the top of longer notebooks. Is there an easy way to enable this based on your recent changes @greenape?

I have a proof of concept implementation which adds a preprocessor to the HTML exporter that simply looks for headings at various levels and inserts links at the top of the page. I'm happy to submit this as a PR but I feel like there is a chance I'm reinventing the wheel and there is probably a way to simply re-use the existing toc extension somehow? Thought I'd ask in any case, but let me know if you'd like me to submit a PR based on my current approach.

Many thanks!

[1] I think this is provided by the toc markdown extension, but the [TOC] marker works even if I don't explicitly enable markdown.extensions.toc in mkdocs.yml, so maybe this is actually something directly built into MkDocs?

@maxalbert
Copy link
Contributor Author

P.S.: If there is a chance to enable [TableOfContents] in addition to [TOC] (as an alias) that would be fantastic, because then notebooks remain readable to non-technical users, e.g. when opened interactively in Binder.

@greenape
Copy link
Owner

🤔 interesting. I think mkdocs uses the toc extension by default, so that’d be why it works when not explicitly enabled. Possibly the plugin is interfering with the processing of the [TOC] marker though. I recall seeing a few relevant issues in the mkdocs/pymarkdown repos, I’ll have a dig..

@greenape
Copy link
Owner

Ahh, I think it is because of Python-Markdown/markdown#100

And might be resolved by ensuring any markdown cells aren’t wrapped in any tags by the template

@maxalbert
Copy link
Contributor Author

Ah, nice find. Thanks!

Turns out it does already work in mknotebooks if I surround the [TOC] marker with blank lines. This kinda makes sense based on the issue you linked, but is not very intuitive if [TOC] is the only content of the cell. 🤔

Do you think it's worth adding a preprocessor which adds blank lines around the [TOC] marker if the cell doesn't contain anything else?

@greenape
Copy link
Owner

greenape commented Mar 2, 2020

Hmm. Not sure on that one. Could just publish a slightly better toc markdown extra?

@kemistep
Copy link

jupyter can't show toc; but makdown can show toc, can you fix it ;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants