Skip to content

Commit 0846862

Browse files
authored
feat(web): improve deprecation page (#365)
1 parent 7442b80 commit 0846862

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-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: 19 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,22 @@ export const transformHeadingNode = (entry, remark, node, index, parent) => {
185178
createChangeElement(entry, remark)
186179
);
187180

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

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)