@mintlify/common 1.0.673 → 1.0.675

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,6 +1,9 @@
1
1
  import { visit } from 'unist-util-visit';
2
+ import { MetaOptions } from '../rehype/rehypeCodeBlocks/metaOptions.js';
2
3
  const REACT_COMPONENT_NAME = 'Mermaid';
4
+ const RESERVED_KEYS = ['placement', 'actions'];
3
5
  export const remarkMermaid = () => (tree) => {
6
+ var _a;
4
7
  const codeblocks = [];
5
8
  visit(tree, 'code', (node, index, parent) => {
6
9
  if (node.lang === 'mermaid' && parent && typeof index === 'number') {
@@ -9,35 +12,75 @@ export const remarkMermaid = () => (tree) => {
9
12
  });
10
13
  if (codeblocks.length !== 0) {
11
14
  for (const [node, index, parent] of codeblocks) {
12
- parent.children.splice(index, 1, {
13
- type: 'mdxJsxFlowElement',
14
- name: REACT_COMPONENT_NAME,
15
- attributes: [
16
- {
17
- type: 'mdxJsxAttribute',
18
- name: 'chart',
19
- value: {
20
- type: 'mdxJsxAttributeValueExpression',
21
- data: {
22
- estree: {
23
- body: [
24
- {
25
- type: 'ExpressionStatement',
26
- expression: {
27
- type: 'Literal',
28
- value: node.value,
29
- raw: JSON.stringify(node.value),
30
- },
15
+ const metaOptions = new MetaOptions((_a = node.meta) !== null && _a !== void 0 ? _a : '', RESERVED_KEYS);
16
+ const placement = metaOptions.getString('placement');
17
+ let actions = metaOptions.getBoolean('actions');
18
+ if (actions === undefined) {
19
+ const rangeValue = metaOptions.getRange('actions');
20
+ if (rangeValue === 'true')
21
+ actions = true;
22
+ else if (rangeValue === 'false')
23
+ actions = false;
24
+ }
25
+ const attributes = [
26
+ {
27
+ type: 'mdxJsxAttribute',
28
+ name: 'chart',
29
+ value: {
30
+ type: 'mdxJsxAttributeValueExpression',
31
+ data: {
32
+ estree: {
33
+ body: [
34
+ {
35
+ type: 'ExpressionStatement',
36
+ expression: {
37
+ type: 'Literal',
38
+ value: node.value,
39
+ raw: JSON.stringify(node.value),
31
40
  },
32
- ],
33
- type: 'Program',
34
- sourceType: 'module',
35
- },
41
+ },
42
+ ],
43
+ type: 'Program',
44
+ sourceType: 'module',
36
45
  },
37
- value: node.value,
38
46
  },
47
+ value: node.value,
39
48
  },
40
- ],
49
+ },
50
+ ];
51
+ if (placement) {
52
+ attributes.push({
53
+ type: 'mdxJsxAttribute',
54
+ name: 'placement',
55
+ value: placement,
56
+ });
57
+ }
58
+ if (actions !== undefined) {
59
+ attributes.push({
60
+ type: 'mdxJsxAttribute',
61
+ name: 'actions',
62
+ value: {
63
+ type: 'mdxJsxAttributeValueExpression',
64
+ data: {
65
+ estree: {
66
+ type: 'Program',
67
+ sourceType: 'module',
68
+ body: [
69
+ {
70
+ type: 'ExpressionStatement',
71
+ expression: { type: 'Literal', value: actions, raw: String(actions) },
72
+ },
73
+ ],
74
+ },
75
+ },
76
+ value: String(actions),
77
+ },
78
+ });
79
+ }
80
+ parent.children.splice(index, 1, {
81
+ type: 'mdxJsxFlowElement',
82
+ name: REACT_COMPONENT_NAME,
83
+ attributes,
41
84
  children: [],
42
85
  });
43
86
  }