|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +import { u as createTree } from 'unist-builder'; |
| 4 | +import { SKIP, visit } from 'unist-util-visit'; |
| 5 | +import createQueries from '../../../utils/queries/index.mjs'; |
| 6 | +import { createJSXElement } from './mdxUtilities.mjs'; |
| 7 | +import { STABILITY_LEVELS } from '../constants.mjs'; |
| 8 | + |
| 9 | +/** |
| 10 | + * |
| 11 | + * @param {import('@types/mdast').Blockquote} node The HTML AST tree of the Stability Index content |
| 12 | + * @param {number} index The index of the current node |
| 13 | + * @param {import('unist').Parent} parent The parent node of the current node |
| 14 | + */ |
| 15 | +const visitStabilityNode = (node, index, parent) => { |
| 16 | + parent.children.splice( |
| 17 | + index, |
| 18 | + 1, |
| 19 | + createJSXElement('AlertBox', { |
| 20 | + children: node.data.description, |
| 21 | + level: STABILITY_LEVELS[node.data.index], |
| 22 | + title: node.data.index, |
| 23 | + }) |
| 24 | + ); |
| 25 | + return [SKIP]; |
| 26 | +}; |
| 27 | + |
| 28 | +/** |
| 29 | + * Process a single content entry by applying all transformations |
| 30 | + * @param {import('unist').Node} content The content to process |
| 31 | + * @returns {import('unist').Node} The processed content |
| 32 | + */ |
| 33 | +const processContent = content => { |
| 34 | + const clonedContent = structuredClone(content); |
| 35 | + visit(clonedContent, createQueries.UNIST.isStabilityNode, visitStabilityNode); |
| 36 | + return clonedContent; |
| 37 | +}; |
| 38 | + |
| 39 | +/** |
| 40 | + * Transforms API metadata entries into markdown content with special handling for stability nodes |
| 41 | + * @param {any} _ Unused parameter |
| 42 | + * @param {Array<ApiDocMetadataEntry>} metadataEntries Entries to transform |
| 43 | + * @returns {import('unist').Node} Root node with processed content |
| 44 | + */ |
| 45 | +export default (_, metadataEntries) => { |
| 46 | + const rootNode = createTree( |
| 47 | + 'root', |
| 48 | + metadataEntries.map(entry => processContent(entry.content)) |
| 49 | + ); |
| 50 | + |
| 51 | + return rootNode; |
| 52 | +}; |
0 commit comments