Skip to content

Commit 0d6d689

Browse files
authored
fix(legacy-html): convert entry.changes to html (#352)
* fix(legacy-html): convert entry.changes to html * chore: nitpick * refactor: remove hast conversion
1 parent cae76bf commit 0d6d689

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

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

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,35 @@ const buildHtmlTypeLink = node => {
7676
);
7777
};
7878

79+
/**
80+
* Creates a history table row.
81+
*
82+
* @param {ApiDocMetadataChange} change
83+
* @param {import('unified').Processor} remark
84+
*/
85+
const createHistoryTableRow = (
86+
{ version: changeVersions, description },
87+
remark
88+
) => {
89+
const descriptionNode = remark.parse(description);
90+
91+
return createElement('tr', [
92+
createElement(
93+
'td',
94+
Array.isArray(changeVersions) ? changeVersions.join(', ') : changeVersions
95+
),
96+
createElement('td', descriptionNode),
97+
]);
98+
};
99+
79100
/**
80101
* Builds the Metadata Properties into content
81102
*
82-
* @param {ApiDocMetadataEntry} node The node to build to build the properties from
103+
* @param {ApiDocMetadataEntry} node The node to build the properties from
104+
* @param {import('unified').Processor} remark The Remark instance to be used to process changes table
83105
* @returns {import('unist').Parent} The HTML AST tree of the properties content
84106
*/
85-
const buildMetadataElement = node => {
107+
const buildMetadataElement = (node, remark) => {
86108
const metadataElement = createElement('div.api_metadata');
87109

88110
// We use a `span` element to display the source link as a clickable link to the source within Node.js
@@ -159,17 +181,8 @@ const buildMetadataElement = node => {
159181
if (typeof node.changes !== 'undefined' && node.changes.length) {
160182
// Maps the changes into a `tr` element with the version and the description
161183
// 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-
])
184+
const historyEntries = node.changes.map(change =>
185+
createHistoryTableRow(change, remark)
173186
);
174187

175188
const historyDetailsElement = createElement('details.changelog', [
@@ -227,7 +240,7 @@ export default (headNodes, metadataEntries, remark) => {
227240
// Concatenates all the strings and parses with remark into an AST tree
228241
return createElement('section', [
229242
headingNode,
230-
buildMetadataElement(entry),
243+
buildMetadataElement(entry, remark),
231244
buildExtraContent(headNodes, entry),
232245
...restNodes,
233246
]);

0 commit comments

Comments
 (0)