diff --git a/src/generators/json-simple/index.mjs b/src/generators/json-simple/index.mjs index b098581..d588836 100644 --- a/src/generators/json-simple/index.mjs +++ b/src/generators/json-simple/index.mjs @@ -34,18 +34,18 @@ export default { const remarkProcessor = getRemark(); // Iterates the input (ApiDocMetadataEntry) and performs a few changes - const mappedInput = input.map(({ content, ...rest }) => { - // Depp clones the content nodes to avoid affecting upstream nodes - const clonedContent = JSON.parse(JSON.stringify(content)); + const mappedInput = input.map(node => { + // Deep clones the content nodes to avoid affecting upstream nodes + const content = JSON.parse(JSON.stringify(node.content)); // Removes all the Stability Index nodes, since they shouldn't be included in the final JSON // and are already represented in the metadata (metadata.stability.toJSON) - remove(clonedContent, [createQueries.UNIST.isStabilityNode]); + remove(content, [createQueries.UNIST.isStabilityNode]); // For the JSON generate we want to transform the whole content into JSON - clonedContent.toJSON = () => remarkProcessor.stringify(clonedContent); + content.toJSON = () => remarkProcessor.stringify(content); - return { ...rest, content: clonedContent }; + return { ...node, content }; }); // This simply grabs all the different files and stringifies them diff --git a/src/queries.mjs b/src/queries.mjs index 86764d4..5222439 100644 --- a/src/queries.mjs +++ b/src/queries.mjs @@ -170,9 +170,12 @@ const createQueries = () => { createQueries.QUERIES = { // Fixes the references to Markdown pages into the API documentation markdownUrl: /^(?![+a-zA-Z]+:)([^#?]+)\.md(#.+)?$/, - // ReGeX to match the {Type} (Structure Type metadatas) + // ReGeX to match the {Type} (API type references) // eslint-disable-next-line no-useless-escape normalizeTypes: /(\{|<)(?! )[a-zA-Z0-9.| \[\]\\]+(?! )(\}|>)/g, + // ReGex to match the type API type references that got already parsed + // so that they can be transformed into HTML links + linksWithTypes: /\[`<([a-zA-Z0-9.| \\[\]]+)>`\]\((.*)\)/, // ReGeX for handling Stability Indexes Metadata stabilityIndex: /^Stability: ([0-5])(?:\s*-\s*)?(.*)$/s, // ReGeX for handling the Stability Index Prefix @@ -189,6 +192,8 @@ createQueries.UNIST = { type === 'html' && createQueries.QUERIES.yamlInnerContent.test(value), isTextWithType: ({ type, value }) => type === 'text' && createQueries.QUERIES.normalizeTypes.test(value), + isHtmlWithType: ({ type, value }) => + type === 'html' && createQueries.QUERIES.linksWithTypes.test(value), isMarkdownUrl: ({ type, url }) => type === 'link' && createQueries.QUERIES.markdownUrl.test(url), isHeading: ({ type, depth }) =>