|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | import { h as createElement } from 'hastscript'; |
| 4 | +import { toHast } from 'mdast-util-to-hast'; |
4 | 5 | import { u as createTree } from 'unist-builder'; |
5 | 6 | import { SKIP, visit } from 'unist-util-visit'; |
6 | 7 |
|
@@ -76,13 +77,38 @@ const buildHtmlTypeLink = node => { |
76 | 77 | ); |
77 | 78 | }; |
78 | 79 |
|
| 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 | + |
79 | 104 | /** |
80 | 105 | * Builds the Metadata Properties into content |
81 | 106 | * |
82 | 107 | * @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 |
83 | 109 | * @returns {import('unist').Parent} The HTML AST tree of the properties content |
84 | 110 | */ |
85 | | -const buildMetadataElement = node => { |
| 111 | +const buildMetadataElement = (node, remark) => { |
86 | 112 | const metadataElement = createElement('div.api_metadata'); |
87 | 113 |
|
88 | 114 | // 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 => { |
159 | 185 | if (typeof node.changes !== 'undefined' && node.changes.length) { |
160 | 186 | // Maps the changes into a `tr` element with the version and the description |
161 | 187 | // 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) |
173 | 190 | ); |
174 | 191 |
|
175 | 192 | const historyDetailsElement = createElement('details.changelog', [ |
@@ -227,7 +244,7 @@ export default (headNodes, metadataEntries, remark) => { |
227 | 244 | // Concatenates all the strings and parses with remark into an AST tree |
228 | 245 | return createElement('section', [ |
229 | 246 | headingNode, |
230 | | - buildMetadataElement(entry), |
| 247 | + buildMetadataElement(entry, remark), |
231 | 248 | buildExtraContent(headNodes, entry), |
232 | 249 | ...restNodes, |
233 | 250 | ]); |
|
0 commit comments