Skip to content

Commit 67aebac

Browse files
committed
fix(legacy-html): convert entry.changes to html
1 parent 6fa7d1b commit 67aebac

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"glob": "^11.0.3",
5454
"hast-util-to-string": "^3.0.1",
5555
"hastscript": "^9.0.1",
56+
"mdast-util-to-hast": "^13.2.0",
5657
"reading-time": "^1.5.0",
5758
"recma-jsx": "^1.0.0",
5859
"rehype-recma": "^1.0.0",

src/generators/legacy-html/utils/buildContent.mjs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
import { h as createElement } from 'hastscript';
4+
import { toHast } from 'mdast-util-to-hast';
45
import { u as createTree } from 'unist-builder';
56
import { SKIP, visit } from 'unist-util-visit';
67

@@ -76,13 +77,38 @@ const buildHtmlTypeLink = node => {
7677
);
7778
};
7879

80+
/**
81+
* Creates a history table row.
82+
*
83+
* @param {ApiDocMetadataChange} change
84+
* @param {import('unified').Processor} remark
85+
*/
86+
const createHistoryTableRow = (
87+
{ version: changeVersions, description },
88+
remark
89+
) => {
90+
const descriptionNode = remark.parse(description);
91+
92+
// Convert node to hast to make it compatible with createElement
93+
const descriptionHast = toHast(descriptionNode);
94+
95+
return createElement('tr', [
96+
createElement(
97+
'td',
98+
Array.isArray(changeVersions) ? changeVersions.join(', ') : changeVersions
99+
),
100+
createElement('td', descriptionHast),
101+
]);
102+
};
103+
79104
/**
80105
* Builds the Metadata Properties into content
81106
*
82107
* @param {ApiDocMetadataEntry} node The node to build to build the properties from
108+
* @param {import('unified').Processor} remark The Remark instance to be used to process changes table
83109
* @returns {import('unist').Parent} The HTML AST tree of the properties content
84110
*/
85-
const buildMetadataElement = node => {
111+
const buildMetadataElement = (node, remark) => {
86112
const metadataElement = createElement('div.api_metadata');
87113

88114
// We use a `span` element to display the source link as a clickable link to the source within Node.js
@@ -159,17 +185,8 @@ const buildMetadataElement = node => {
159185
if (typeof node.changes !== 'undefined' && node.changes.length) {
160186
// Maps the changes into a `tr` element with the version and the description
161187
// An array containing hast nodes for the history entries if any
162-
const historyEntries = node.changes.map(
163-
({ version: changeVersions, description }) =>
164-
createElement('tr', [
165-
createElement(
166-
'td',
167-
Array.isArray(changeVersions)
168-
? changeVersions.join(', ')
169-
: changeVersions
170-
),
171-
createElement('td', description),
172-
])
188+
const historyEntries = node.changes.map(change =>
189+
createHistoryTableRow(change, remark)
173190
);
174191

175192
const historyDetailsElement = createElement('details.changelog', [
@@ -227,7 +244,7 @@ export default (headNodes, metadataEntries, remark) => {
227244
// Concatenates all the strings and parses with remark into an AST tree
228245
return createElement('section', [
229246
headingNode,
230-
buildMetadataElement(entry),
247+
buildMetadataElement(entry, remark),
231248
buildExtraContent(headNodes, entry),
232249
...restNodes,
233250
]);

0 commit comments

Comments
 (0)