-
Notifications
You must be signed in to change notification settings - Fork 1
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
DISCO-290 Set Rex heading levels for Assignable #2269
Conversation
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.
overall this is fine, just some comments on the actual mutation
function changeHeadingLevels(rootEl: HTMLElement, topHeadingLevel: number) { | ||
let currentLevel = topHeadingLevel; | ||
|
||
[ 1, 2, 3, 4, 5, 6 ].forEach((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.
i was thinking you'd query the highest level header in the content, take the difference from the desired topHeadingLevel, and then modify every heading by that delta
i think your current logic sort of attempts to "fix" an invalid heading structure that is missing levels, but i don't think we want to mess around with that
|
||
if (tags.length > 0) { | ||
const newTagName = `h${currentLevel}`; | ||
tags.forEach((el) => el.outerHTML = el.outerHTML.replace(RegExp(`<${origTagName}`, 'g'), `<${newTagName}`) |
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.
there is some risk of this regex replacing things it shouldn't.... i would iterate over tags
and create a new tag element at the correct level, copy attributes over, and then use replaceWith
to replace the element in the tree
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.
would be nice to see a spec, but looks generally good to me
const headingLevels = [ 1, 2, 3, 4, 5, 6 ]; | ||
const currentTopHeading = headingLevels.find((level) => rootEl.querySelectorAll(`h${level}`)?.length); | ||
|
||
if (!currentTopHeading || topHeadingLevel <= currentTopHeading) { |
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.
if desired topHeading level is 2, and the currentTopHeading is 3, we don't want to skip we want to bump them all up.
if they are equal we can return
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.
ah ok, was confused on this point
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 good but hold off for a sec while we verify if the top level should be 2 or 3
* transition textSize -> text_size * return token as token data; conditionally assign json encoded sub fields to token data * 👕 * Add tests back into ci file * update launchToken specs * update snapshot for #2269 * shut up test output * fix keys on chapter filter loops * reduce test output for invalid props on mock elements * wrap act * fix uuid import warning * fix act warning * fix leaky mocks in search result sidebar specs * do not re-fetch book for content warning * remove invalid test * fix Page.spec * fix search sidebar specs * fix transform spec * coverage for cdn gateway * add thresholds to jest config * coverage for search sidebar * add coverage for textsize * 👕 * fix effect dependency * 👕 --------- Co-authored-by: staxly[bot] <35789409+staxly[bot]@users.noreply.github.com>
I can see like 10 different ways to do this so maybe it's best if you told me if you like this or not