@redocly/theme 0.46.3 → 0.46.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,30 @@
1
1
  import markdoc from '@markdoc/markdoc';
2
2
 
3
- import type { Config, Node } from '@markdoc/markdoc';
3
+ import type { Config, Node, RenderableTreeNode } from '@markdoc/markdoc';
4
4
  import type { MarkdocSchemaWrapper } from '@redocly/theme/markdoc/tags/types';
5
5
 
6
+ // Walk through AST and look for raw markdown to parse
7
+ function parseInlineMarkdown(
8
+ ast: RenderableTreeNode | RenderableTreeNode[],
9
+ config: Config,
10
+ ): RenderableTreeNode | RenderableTreeNode[] {
11
+ if (Array.isArray(ast)) {
12
+ return ast.flatMap((child) => parseInlineMarkdown(child, config));
13
+ }
14
+
15
+ if (typeof ast === 'string') {
16
+ const parsed = markdoc.parse(ast);
17
+ return markdoc.transform(parsed, config);
18
+ }
19
+
20
+ if (ast && typeof ast === 'object' && ast.$$mdtype === 'Tag') {
21
+ const children = parseInlineMarkdown(ast.children, config);
22
+ return { ...ast, children } as RenderableTreeNode;
23
+ }
24
+
25
+ return ast;
26
+ }
27
+
6
28
  // This custom tag prevents evaluating any children markdoc tags (no children) so we can
7
29
  // have markdoc examples in code fences
8
30
  // approach copied from: https://github.com/markdoc/docs/blob/main/markdoc/tags/markdoc-example.markdoc.js
@@ -29,13 +51,16 @@ export const markdocExample: MarkdocSchemaWrapper = {
29
51
  title = fenceWithTitle?.value;
30
52
  }
31
53
 
54
+ const demoContent = node.children[0].transformChildren(config);
55
+ const parsedDemoContent = parseInlineMarkdown(demoContent, config);
56
+
32
57
  return new markdoc.Tag(
33
58
  'MarkdocExample',
34
59
  {
35
60
  ...attributes,
36
61
  title,
37
62
  language,
38
- demoContent: node.children[0].transformChildren(config),
63
+ demoContent: parsedDemoContent,
39
64
  rawContent: content,
40
65
  },
41
66
  [],