-
Notifications
You must be signed in to change notification settings - Fork 87
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
Refactor htmlToMd.ts
: Split prepareHandlers
function
#943
Conversation
Thanks for contributing to Qiskit documentation! Before your PR can be merged, it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. Thanks! 🙌 |
}); | ||
} | ||
|
||
function buildDt( |
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.
Same logic as before but encapsulated in a helper function
if (node.properties.id && node.properties.className?.includes("target")) { | ||
if ( | ||
node.properties.id && | ||
(node.properties.className?.includes("target") || | ||
node.children.length === 0) | ||
) { | ||
return [buildSpanId(node.properties.id), ...all(h, node)]; | ||
} | ||
|
||
if (node.properties.id && node.children.length === 0) { | ||
return buildSpanId(node.properties.id); | ||
} | ||
|
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.
The difference between these two ifs was the call to all(h, node)
. This merge should be safe given that the all
method transforms the children of a hast parent to mdast or returns an empty array if no children are found.
Description of the function at https://github.com/syntax-tree/hast-util-to-mdast?tab=readme-ov-file#fields-1
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.
Nice! Good call to not have buildDeprecatedAdmonition
call buildAdmonition
. This is much more direct. Sometimes DRY can go too far, which is why WET exists hahaha (write everything twice)
Part of Qiskit#845 This PR refactors the `htmlToMd.ts` script. It splits the `prepareHandlers` function into some helper functions to simplify the logic and improve the readability.
Part of #845
This PR refactors the
htmlToMd.ts
script. It splits theprepareHandlers
function into some helper functions to simplify the logic and improve the readability.