From 67aebacb7325f68fd48a7b573054d561077af682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilherme=20Ara=C3=BAjo?= Date: Mon, 14 Jul 2025 19:54:44 -0300 Subject: [PATCH 1/3] fix(legacy-html): convert entry.changes to html --- package-lock.json | 1 + package.json | 1 + .../legacy-html/utils/buildContent.mjs | 43 +++++++++++++------ 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 18e2beb0..001534c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "glob": "^11.0.3", "hast-util-to-string": "^3.0.1", "hastscript": "^9.0.1", + "mdast-util-to-hast": "^13.2.0", "reading-time": "^1.5.0", "recma-jsx": "^1.0.0", "rehype-recma": "^1.0.0", diff --git a/package.json b/package.json index e7ee7ae9..087771c3 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "glob": "^11.0.3", "hast-util-to-string": "^3.0.1", "hastscript": "^9.0.1", + "mdast-util-to-hast": "^13.2.0", "reading-time": "^1.5.0", "recma-jsx": "^1.0.0", "rehype-recma": "^1.0.0", diff --git a/src/generators/legacy-html/utils/buildContent.mjs b/src/generators/legacy-html/utils/buildContent.mjs index 46c230b5..d819dac7 100644 --- a/src/generators/legacy-html/utils/buildContent.mjs +++ b/src/generators/legacy-html/utils/buildContent.mjs @@ -1,6 +1,7 @@ 'use strict'; import { h as createElement } from 'hastscript'; +import { toHast } from 'mdast-util-to-hast'; import { u as createTree } from 'unist-builder'; import { SKIP, visit } from 'unist-util-visit'; @@ -76,13 +77,38 @@ const buildHtmlTypeLink = node => { ); }; +/** + * Creates a history table row. + * + * @param {ApiDocMetadataChange} change + * @param {import('unified').Processor} remark + */ +const createHistoryTableRow = ( + { version: changeVersions, description }, + remark +) => { + const descriptionNode = remark.parse(description); + + // Convert node to hast to make it compatible with createElement + const descriptionHast = toHast(descriptionNode); + + return createElement('tr', [ + createElement( + 'td', + Array.isArray(changeVersions) ? changeVersions.join(', ') : changeVersions + ), + createElement('td', descriptionHast), + ]); +}; + /** * Builds the Metadata Properties into content * * @param {ApiDocMetadataEntry} node The node to build to build the properties from + * @param {import('unified').Processor} remark The Remark instance to be used to process changes table * @returns {import('unist').Parent} The HTML AST tree of the properties content */ -const buildMetadataElement = node => { +const buildMetadataElement = (node, remark) => { const metadataElement = createElement('div.api_metadata'); // 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 => { if (typeof node.changes !== 'undefined' && node.changes.length) { // Maps the changes into a `tr` element with the version and the description // An array containing hast nodes for the history entries if any - const historyEntries = node.changes.map( - ({ version: changeVersions, description }) => - createElement('tr', [ - createElement( - 'td', - Array.isArray(changeVersions) - ? changeVersions.join(', ') - : changeVersions - ), - createElement('td', description), - ]) + const historyEntries = node.changes.map(change => + createHistoryTableRow(change, remark) ); const historyDetailsElement = createElement('details.changelog', [ @@ -227,7 +244,7 @@ export default (headNodes, metadataEntries, remark) => { // Concatenates all the strings and parses with remark into an AST tree return createElement('section', [ headingNode, - buildMetadataElement(entry), + buildMetadataElement(entry, remark), buildExtraContent(headNodes, entry), ...restNodes, ]); From 43a281695d7d2fb78d48e1218a3f792a91eb2e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilherme=20Ara=C3=BAjo?= Date: Mon, 14 Jul 2025 20:01:50 -0300 Subject: [PATCH 2/3] chore: nitpick --- src/generators/legacy-html/utils/buildContent.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generators/legacy-html/utils/buildContent.mjs b/src/generators/legacy-html/utils/buildContent.mjs index d819dac7..822b4b6b 100644 --- a/src/generators/legacy-html/utils/buildContent.mjs +++ b/src/generators/legacy-html/utils/buildContent.mjs @@ -104,7 +104,7 @@ const createHistoryTableRow = ( /** * Builds the Metadata Properties into content * - * @param {ApiDocMetadataEntry} node The node to build to build the properties from + * @param {ApiDocMetadataEntry} node The node to build the properties from * @param {import('unified').Processor} remark The Remark instance to be used to process changes table * @returns {import('unist').Parent} The HTML AST tree of the properties content */ From 6853e92ac3c0919e20117ba5f25a0d30e775bdac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilherme=20Ara=C3=BAjo?= Date: Mon, 14 Jul 2025 20:04:20 -0300 Subject: [PATCH 3/3] refactor: remove hast conversion --- package-lock.json | 1 - package.json | 1 - src/generators/legacy-html/utils/buildContent.mjs | 6 +----- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 001534c3..18e2beb0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,6 @@ "glob": "^11.0.3", "hast-util-to-string": "^3.0.1", "hastscript": "^9.0.1", - "mdast-util-to-hast": "^13.2.0", "reading-time": "^1.5.0", "recma-jsx": "^1.0.0", "rehype-recma": "^1.0.0", diff --git a/package.json b/package.json index 087771c3..e7ee7ae9 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,6 @@ "glob": "^11.0.3", "hast-util-to-string": "^3.0.1", "hastscript": "^9.0.1", - "mdast-util-to-hast": "^13.2.0", "reading-time": "^1.5.0", "recma-jsx": "^1.0.0", "rehype-recma": "^1.0.0", diff --git a/src/generators/legacy-html/utils/buildContent.mjs b/src/generators/legacy-html/utils/buildContent.mjs index 822b4b6b..9b0e9a3b 100644 --- a/src/generators/legacy-html/utils/buildContent.mjs +++ b/src/generators/legacy-html/utils/buildContent.mjs @@ -1,7 +1,6 @@ 'use strict'; import { h as createElement } from 'hastscript'; -import { toHast } from 'mdast-util-to-hast'; import { u as createTree } from 'unist-builder'; import { SKIP, visit } from 'unist-util-visit'; @@ -89,15 +88,12 @@ const createHistoryTableRow = ( ) => { const descriptionNode = remark.parse(description); - // Convert node to hast to make it compatible with createElement - const descriptionHast = toHast(descriptionNode); - return createElement('tr', [ createElement( 'td', Array.isArray(changeVersions) ? changeVersions.join(', ') : changeVersions ), - createElement('td', descriptionHast), + createElement('td', descriptionNode), ]); };