Skip to content

doc: fix stability 1.x links excluding the decimal digit #58783

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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tools/doc/html.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,11 @@ function linkJsTypeDocs(text) {

const isJSFlavorSnippet = (node) => node.lang === 'cjs' || node.lang === 'mjs';

const STABILITY_RE = /(.*:)\s*(\d(?:\.\d)?)([\s\S]*)/;

// Preprocess headers, stability blockquotes, and YAML blocks.
export function preprocessElements({ filename }) {
return (tree) => {
const STABILITY_RE = /(.*:)\s*(\d)([\s\S]*)/;
let headingIndex = -1;
let heading = null;

Expand Down Expand Up @@ -325,7 +326,7 @@ export function preprocessElements({ filename }) {
// Insert div with prefix and number
node.children.unshift({
type: 'html',
value: `<div class="api_stability api_stability_${number}">` +
value: `<div class="api_stability api_stability_${parseInt(number)}">` +
Copy link
Member

Choose a reason for hiding this comment

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

parseInt will only grab the numeric pieces of "number" right?

Copy link
Member Author

@dario-piotrowicz dario-piotrowicz Jun 22, 2025

Choose a reason for hiding this comment

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

Yes, in the regex that the part for number is /\d(?:\.\d)? meaning that the number matched value can be a single digit optionally followed by a dot followed by another digit, parseInt run on such numbers/strings always returns the integer part of the number:
Screenshot at 2025-06-22 18-50-14

And that's the part we need based on the css classes we have:

.api_stability_0 {
background-color: var(--red1);
}
.api_stability_1 {
background-color: var(--red3);
}
.api_stability_2 {
background-color: var(--green2);
}
.api_stability_3 {
background-color: var(--blue1);
}

Copy link
Member

Choose a reason for hiding this comment

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

I used the same trick in the web generator :-)

Copy link
Member

Choose a reason for hiding this comment

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

I just wanted to confirm. I recall either parseInt or Number() parse the numeric parseable stuff until it finds something non-numeric.

Copy link
Member

Choose a reason for hiding this comment

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

No, not until it finds something non-numeric. It parses the float since it's a valid number, and flattens it to an integer.

(noLinking ? '' :
'<a href="documentation.html#stability-index">') +
`${prefix} ${number}${noLinking ? '' : '</a>'}`
Expand Down
Loading