-
Notifications
You must be signed in to change notification settings - Fork 73
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
✨ New table of contents directive #1826
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: aa26dd9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Thanks @fwkoch! Quick question (and sorry if I missed something, but I don't see docs in the PR), how does it work for PDF output? For example, for standalone documents I'm currently using a raw typst outline directive and sticking to typst templates, with a block in triple-backquotes like this:
This works fine, but obviously would be best to have toc management be done at the mystmd level so it's consistent across output types. Thoughts on how to gracefully handle this? (and I totally understand if it's too much to deal with for now and that's a future enhancement). |
Hey @fperez - for this PR, PDFs are out of scope; the new directive is just ignored. Your approach of raw typst is still best. I agree consistency across output types would be nice, but for that to be smooth, I think we need more control over the different export types (e.g. #1833) so features can easily be "turned on and off." |
Understood @fwkoch, no problem. I guess for now I can just add the new toc directive into the document so I get them in html, and leave my raw typst block as well - a bit redundant, but it works fine in letting me control precisely each type of output with things that make sense for each. Not a problem at all, thanks! |
This PR addresses #1800
It introduces a new
toc
directive that, for site builds, is transformed into a list-based table of contents. You may specifycontext
to switch between project, page, and section contents. The default context is project.project
- for this context, entries in the table of contents are all project pages and folders. You may also usetoctree
as an alias for the directive. (This provides partial functionality similar to the sphinx toctree directive, although that directive allows you to define child pages and their order. The MyST toc directive is only for display and entirely dependent on the toc structure defined in themyst.yml
file. See sphinx toctree here: https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-toctree)The following are all equivalent
page
- for this context, entries in the table of contents are all the headings on a page.section
- for this context, entries in the table of contents are only the headings of the current section you are in (sections are delimited by headings of the same depth). You may also usecontents
as an alias for toc directive with section context, to provide functionality similar to the docutils contents directive: https://docutils.sourceforge.io/0.4/docs/ref/rst/directives.html#table-of-contents)The following are all equivalent
You may also provide a heading for your table of contents:
Currently
toc
directives are ignored by PDF and other non-site build targets.