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

ENH: add new sphinx-external-toc package #956

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

agoose77
Copy link
Collaborator

@agoose77 agoose77 commented Mar 5, 2024

This PR adds a new sphinx-external-toc package. The intention is to replicate the functionality of the sphinx-external-toc Python package, for later plumbing into MyST-CLI and JupyterLab-MyST.

This PR:

  • Adds support for upgrading legacy ToCs
  • Adds support for book, article, and no-format ToCs
  • Implements ToC validation using JSON Schema

@agoose77 agoose77 force-pushed the agoose77/feat-new-toc-package branch 4 times, most recently from 6bc4245 to d86b0d9 Compare March 5, 2024 14:55
@agoose77 agoose77 requested a review from rowanc1 March 5, 2024 14:57
@agoose77 agoose77 changed the title feat: add new sphinx-external-toc package ENH: add new sphinx-external-toc package Mar 5, 2024
Copy link
Member

@fwkoch fwkoch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really nice! Didn't totally parse all the coercion logic, but it looks sensible. And the JSON validation from types is good - easy!

const ajv = new Ajv.default();
const validate = ajv.compile(schema);
if (!validate(toc)) {
throw new Error(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth adding validate.errors to this message? I think you were saying those errors were sometimes totally undecipherable because of all the complexity with unions, so probably not, I suppose.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure -- as you note, I found that the errors are fairly non-intuitive. I think for now it might be sufficient just to complain about an invalid TOC.

packages/sphinx-external-toc/src/toc.ts Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@fwkoch
Copy link
Member

fwkoch commented Mar 11, 2024

I was just wondering if this should be a separate package on executablebooks, since it isn't really MyST related...?

@agoose77
Copy link
Collaborator Author

That's a good question. I think for now we keep it here because it will exclusively be used by myst-cli. Soon it will end up in jupyterlab-myst / jupyter-book, and at that time we can pull it out once the organisational structure is clearer?

@agoose77 agoose77 self-assigned this Mar 19, 2024
@agoose77 agoose77 force-pushed the agoose77/feat-new-toc-package branch from 3d8b23e to 1ec13bb Compare March 21, 2024 11:20
@rowanc1
Copy link
Member

rowanc1 commented Mar 21, 2024

@agoose77 looks like test are failing here. Are you working on that to get this ready to review?

@agoose77
Copy link
Collaborator Author

agoose77 looks like test are failing here. Are you working on that to get this ready to review?

Typical! I just rebased it, so I'll check out what's regressed. I think it's to do with AJV. c.f. ajv-validator/ajv#2389

@rowanc1
Copy link
Member

rowanc1 commented Mar 21, 2024

I understand the TOC round-tripping issues a bit better. Thanks for the call @agoose77.

Plan we discussed:

  • merge the first version of sphinx-external-toc when tests pass here (@agoose77 can advise)
  • second PR (ENH: use new TOC package in myst-cli #957), which uses it and replaces the current reader is breaking because we are (potentially) round-tripping incorrectly. The current implementation is not as strict as the spec, and the writing can be wrong. We can either leave that for a bit, or have a fallback to the current implementation and a warning.
  • We should have a simpler format for internally reasoning about tocs (probably unist based!), that requires more though, especially about numbering. That thinking/proposal can happen any time, maybe @agoose77 can have a go.

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

Successfully merging this pull request may close these issues.

None yet

3 participants