-
Notifications
You must be signed in to change notification settings - Fork 100
🔗 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
🔗 Fix URLs in table of contents directive #2140
Conversation
🦋 Changeset detectedLatest commit: 3db2a50 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this 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.
packages/myst-transforms/src/toc.ts
Outdated
return item; | ||
} | ||
|
||
function listItemChildFromPage(page: ProjectPage, projectSlug?: string): Text | Link { |
There was a problem hiding this comment.
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 🙃
packages/myst-transforms/src/toc.ts
Outdated
const page = pages[0]; | ||
const child = listItemChildFromPage(page, projectSlug); | ||
const item = makeListItem(child); | ||
if (pages[1] && pages[1].level > page.level) { |
There was a problem hiding this comment.
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.
packages/myst-transforms/src/toc.ts
Outdated
return item; | ||
} | ||
|
||
function listItemChildFromHeading(heading: Heading): Text | Link { |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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 😁 .
There was a problem hiding this comment.
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!
Note some linting errors too; perhaps try fixing with |
There was a problem hiding this 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.
Will get this in shortly - @brianhawthorne thanks for the contribution!! |
toc
directive #2119