From dd5e23c93fbc04f95859448c1904fedc6eec6c82 Mon Sep 17 00:00:00 2001 From: avivkeller Date: Sun, 20 Jul 2025 17:15:28 -0400 Subject: [PATCH 1/2] feat(web): improve deprecation page --- src/generators/jsx-ast/constants.mjs | 3 +++ src/generators/jsx-ast/utils/buildContent.mjs | 27 ++++++++++++------- src/generators/web/ui/index.css | 1 + 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/generators/jsx-ast/constants.mjs b/src/generators/jsx-ast/constants.mjs index 07fd62ca..5e9b0a1f 100644 --- a/src/generators/jsx-ast/constants.mjs +++ b/src/generators/jsx-ast/constants.mjs @@ -18,6 +18,9 @@ export const TOC_MAX_HEADING_DEPTH = 3; // 'Stability: '.length + ' - '.length export const STABILITY_PREFIX_LENGTH = 14; +// 'Type: '.length +export const TYPE_PREFIX_LENGTH = 6; + /** * HTML tag to UI component mappings */ diff --git a/src/generators/jsx-ast/utils/buildContent.mjs b/src/generators/jsx-ast/utils/buildContent.mjs index 7a6d89fa..006b5c4e 100644 --- a/src/generators/jsx-ast/utils/buildContent.mjs +++ b/src/generators/jsx-ast/utils/buildContent.mjs @@ -1,5 +1,5 @@ import { h as createElement } from 'hastscript'; -import { slice, findText } from 'mdast-util-slice-markdown'; +import { slice } from 'mdast-util-slice-markdown'; import { u as createTree } from 'unist-builder'; import { SKIP, visit } from 'unist-util-visit'; @@ -17,6 +17,7 @@ import { INTERNATIONALIZABLE, STABILITY_PREFIX_LENGTH, TYPES_WITH_METHOD_SIGNATURES, + TYPE_PREFIX_LENGTH, } from '../constants.mjs'; import insertSignature, { getFullName } from './buildSignature.mjs'; @@ -105,15 +106,7 @@ export const extractHeadingContent = content => { return type === 'ctor' ? `${fullName} Constructor` : fullName; } - // Find the index of the first colon, i.e. `Class:`. - const colonPos = findText(content, ':')[0]; - - if (!colonPos) { - return content.children; - } - - // Slice out the prefix from the index gotten above. - return slice(content, colonPos + 1).node.children; + return content.children; }; /** @@ -185,6 +178,20 @@ export const transformHeadingNode = (entry, remark, node, index, parent) => { createChangeElement(entry, remark) ); + if (entry.api === 'deprecations') { + // On the 'deprecations.md' page, "Type: " turns into an AlertBox + const typeNode = parent.children[index + 1]; + if (typeNode) { + parent.children[index + 1] = createJSXElement(JSX_IMPORTS.AlertBox.name, { + children: slice(typeNode, TYPE_PREFIX_LENGTH, undefined, { + textHandling: { boundaries: 'preserve' }, + }).node.children, + level: 'danger', + title: 'Type', + }); + } + } + // Add source link element if available, right after heading const sourceLink = createSourceLink(entry.source_link); diff --git a/src/generators/web/ui/index.css b/src/generators/web/ui/index.css index 6836fd37..f2950c97 100644 --- a/src/generators/web/ui/index.css +++ b/src/generators/web/ui/index.css @@ -12,6 +12,7 @@ main { /* Code should inherit its font size */ code { font-size: inherit; + font-weight: inherit; } /* Don't overflow the parent */ From d381372f111a584d37b1b2c6f21a2a013958f96b Mon Sep 17 00:00:00 2001 From: avivkeller Date: Sun, 20 Jul 2025 17:22:41 -0400 Subject: [PATCH 2/2] fixup! --- src/generators/jsx-ast/utils/buildContent.mjs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/generators/jsx-ast/utils/buildContent.mjs b/src/generators/jsx-ast/utils/buildContent.mjs index 006b5c4e..17b48bf9 100644 --- a/src/generators/jsx-ast/utils/buildContent.mjs +++ b/src/generators/jsx-ast/utils/buildContent.mjs @@ -178,18 +178,20 @@ export const transformHeadingNode = (entry, remark, node, index, parent) => { createChangeElement(entry, remark) ); - if (entry.api === 'deprecations') { + if (entry.api === 'deprecations' && node.depth === 3) { // On the 'deprecations.md' page, "Type: " turns into an AlertBox - const typeNode = parent.children[index + 1]; - if (typeNode) { - parent.children[index + 1] = createJSXElement(JSX_IMPORTS.AlertBox.name, { - children: slice(typeNode, TYPE_PREFIX_LENGTH, undefined, { + parent.children[index + 1] = createJSXElement(JSX_IMPORTS.AlertBox.name, { + children: slice( + parent.children[index + 1], + TYPE_PREFIX_LENGTH, + undefined, + { textHandling: { boundaries: 'preserve' }, - }).node.children, - level: 'danger', - title: 'Type', - }); - } + } + ).node.children, + level: 'danger', + title: 'Type', + }); } // Add source link element if available, right after heading