Skip to content

🔗 Fix URLs in table of contents directive #2140

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

Merged
merged 14 commits into from
Jul 18, 2025

Conversation

brianhawthorne
Copy link
Contributor

@brianhawthorne brianhawthorne commented Jul 1, 2025

Copy link

changeset-bot bot commented Jul 1, 2025

🦋 Changeset detected

Latest commit: 3db2a50

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
myst-transforms Patch

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

@brianhawthorne brianhawthorne changed the title WIP: #2119 Fix URLs in TOC 🔗 WIP: #2119 Fix URLs in TOC Jul 4, 2025
@brianhawthorne brianhawthorne marked this pull request as ready for review July 7, 2025 23:20
@choldgraf choldgraf added the enhancement New feature or request label Jul 7, 2025
Copy link
Collaborator

@stefanv stefanv left a comment

Choose a reason for hiding this comment

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

OK, I took a bit more time to read this, and the changes LGTM!

I'm curious whether I just missed something about the ProjectPage type, whether we need to get that type definition from elsewhere, or whether we should extend the type definition here.

return item;
}

function listItemChildFromPage(page: ProjectPage, projectSlug?: string): Text | Link {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Confusing function name they used here, took me a while to figure out what's going on 🙃

const page = pages[0];
const child = listItemChildFromPage(page, projectSlug);
const item = makeListItem(child);
if (pages[1] && pages[1].level > page.level) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like nesting is happening here; may be worth pointing out in a comment.

return item;
}

function listItemChildFromHeading(heading: Heading): Text | Link {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have a way of documenting these? I think even a simple one sentence description would be quite helpful for future readers!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a small bit of documentation. The mutually recursive function pairs here are turning me a little bit cross-eyed honestly. Since I don't fully understand the logic, I'm afraid if I add too much by way of explaining, it might end up misleading.

I did note that the two mutually recursive function pairs (listFromPages/listItemFromPages and listFromHeadings/listItemFromHeadings) are largely identical modulo the details of the base-case transformation and the choice of .level vs .depth as the property that controls the recursion. If they were to settle on either level or depth for both kinds of TOC trees, then the four could be combined into a single mutually recursive pair parametrized by a node transformer function. I wasn't sure if the choice to use two different property names to represent what looks like the same thing in these two cases was a design decision or just incidental... maybe an opportunity to refactor, but not something I'd be inclined to take on just yet 😁 .

Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably something @fwkoch would know!

@stefanv
Copy link
Collaborator

stefanv commented Jul 15, 2025

Note some linting errors too; perhaps try fixing with npm run format or npm run lint:format.

Copy link
Collaborator

@stefanv stefanv left a comment

Choose a reason for hiding this comment

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

Thanks, @brianhawthorne! This looks good to me. We'll have to get @fwkoch or someone else on the team to take a second look, since I don't know this code well enough to merge.

@rowanc1 rowanc1 changed the title 🔗 WIP: #2119 Fix URLs in TOC 🔗 Fix URLs in table of contents directive Jul 18, 2025
@rowanc1
Copy link
Member

rowanc1 commented Jul 18, 2025

Will get this in shortly - @brianhawthorne thanks for the contribution!!

@rowanc1 rowanc1 merged commit cb76fb7 into jupyter-book:main Jul 18, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

URL entries show up as plain text in toc directive
4 participants