Skip to content

Commit dd5e23c

Browse files
committed
feat(web): improve deprecation page
1 parent cbc2a99 commit dd5e23c

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/generators/jsx-ast/constants.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export const TOC_MAX_HEADING_DEPTH = 3;
1818
// 'Stability: '.length + ' - '.length
1919
export const STABILITY_PREFIX_LENGTH = 14;
2020

21+
// 'Type: '.length
22+
export const TYPE_PREFIX_LENGTH = 6;
23+
2124
/**
2225
* HTML tag to UI component mappings
2326
*/

src/generators/jsx-ast/utils/buildContent.mjs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { h as createElement } from 'hastscript';
2-
import { slice, findText } from 'mdast-util-slice-markdown';
2+
import { slice } from 'mdast-util-slice-markdown';
33
import { u as createTree } from 'unist-builder';
44
import { SKIP, visit } from 'unist-util-visit';
55

@@ -17,6 +17,7 @@ import {
1717
INTERNATIONALIZABLE,
1818
STABILITY_PREFIX_LENGTH,
1919
TYPES_WITH_METHOD_SIGNATURES,
20+
TYPE_PREFIX_LENGTH,
2021
} from '../constants.mjs';
2122
import insertSignature, { getFullName } from './buildSignature.mjs';
2223

@@ -105,15 +106,7 @@ export const extractHeadingContent = content => {
105106
return type === 'ctor' ? `${fullName} Constructor` : fullName;
106107
}
107108

108-
// Find the index of the first colon, i.e. `Class:`.
109-
const colonPos = findText(content, ':')[0];
110-
111-
if (!colonPos) {
112-
return content.children;
113-
}
114-
115-
// Slice out the prefix from the index gotten above.
116-
return slice(content, colonPos + 1).node.children;
109+
return content.children;
117110
};
118111

119112
/**
@@ -185,6 +178,20 @@ export const transformHeadingNode = (entry, remark, node, index, parent) => {
185178
createChangeElement(entry, remark)
186179
);
187180

181+
if (entry.api === 'deprecations') {
182+
// On the 'deprecations.md' page, "Type: <XYZ>" turns into an AlertBox
183+
const typeNode = parent.children[index + 1];
184+
if (typeNode) {
185+
parent.children[index + 1] = createJSXElement(JSX_IMPORTS.AlertBox.name, {
186+
children: slice(typeNode, TYPE_PREFIX_LENGTH, undefined, {
187+
textHandling: { boundaries: 'preserve' },
188+
}).node.children,
189+
level: 'danger',
190+
title: 'Type',
191+
});
192+
}
193+
}
194+
188195
// Add source link element if available, right after heading
189196
const sourceLink = createSourceLink(entry.source_link);
190197

src/generators/web/ui/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ main {
1212
/* Code should inherit its font size */
1313
code {
1414
font-size: inherit;
15+
font-weight: inherit;
1516
}
1617

1718
/* Don't overflow the parent */

0 commit comments

Comments
 (0)