Skip to content

Commit

Permalink
hotfix: added missing json simple parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ovflowd committed Aug 13, 2024
1 parent 1ac979c commit dc693b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/generators/json-simple/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/queries.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}<Type> (Structure Type metadatas)
// ReGeX to match the {Type}<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
Expand All @@ -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 }) =>
Expand Down

0 comments on commit dc693b7

Please sign in to comment.