@terrafirmagreg-team/mdx 1.2.11 → 1.2.13
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.
- package/package.json +6 -4
- package/src/lib/mdx/accordions.ts +3 -9
- package/src/lib/mdx/banner.ts +4 -8
- package/src/lib/mdx/directive-utils.ts +18 -20
- package/src/lib/mdx/entries/factory.ts +2 -9
- package/src/lib/mdx/files.ts +2 -3
- package/src/lib/mdx/tabs.ts +4 -5
- package/src/lib/story-remark.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terrafirmagreg-team/mdx",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MDX/markdown pipeline",
|
|
6
6
|
"license": "LGPL-3.0-only",
|
|
@@ -20,13 +20,15 @@
|
|
|
20
20
|
"./lib/markdown": "./src/lib/markdown/index.ts"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@terrafirmagreg-team/translate": "^1.2.
|
|
24
|
-
"@terrafirmagreg-team/ui": "^1.2.
|
|
23
|
+
"@terrafirmagreg-team/translate": "^1.2.14",
|
|
24
|
+
"@terrafirmagreg-team/ui": "^1.2.22",
|
|
25
|
+
"estree-util-to-js": "^2.0.0",
|
|
26
|
+
"estree-util-value-to-estree": "^3.5.0",
|
|
25
27
|
"fumadocs-docgen": "^3.2.0",
|
|
26
28
|
"fumadocs-twoslash": "^4.0.4",
|
|
27
29
|
"fumadocs-typescript": "5.6.0",
|
|
28
30
|
"gemoji": "^8.1.0",
|
|
29
|
-
"lucide-react": "^1.
|
|
31
|
+
"lucide-react": "^1.72.0",
|
|
30
32
|
"mdast-util-to-string": "^4.0.0",
|
|
31
33
|
"rehype-katex": "^7.0.1",
|
|
32
34
|
"rehype-raw": "^7.0.0",
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
contentChildren,
|
|
3
|
-
estreeBoolean,
|
|
4
|
-
estreeStringArray,
|
|
5
3
|
extractDirectiveLabel,
|
|
6
4
|
extractLeafLabel,
|
|
7
5
|
jsxAttr,
|
|
6
|
+
jsxAttrValue,
|
|
8
7
|
jsxExpression,
|
|
9
8
|
walkContainers,
|
|
10
9
|
type DirectiveNode,
|
|
@@ -46,9 +45,7 @@ function wrapSingle(node: DirectiveNode): void {
|
|
|
46
45
|
{
|
|
47
46
|
type: 'mdxJsxAttribute',
|
|
48
47
|
name: 'defaultValue',
|
|
49
|
-
value: jsxExpression(
|
|
50
|
-
estreeStringArray([String(extractDirectiveLabel(node))]),
|
|
51
|
-
),
|
|
48
|
+
value: jsxExpression([extractDirectiveLabel(node)]),
|
|
52
49
|
} as JsxAttribute,
|
|
53
50
|
]
|
|
54
51
|
: [],
|
|
@@ -71,10 +68,7 @@ function accordionsAttributes(node: DirectiveNode): JsxAttribute[] {
|
|
|
71
68
|
out.push({
|
|
72
69
|
type: 'mdxJsxAttribute',
|
|
73
70
|
name,
|
|
74
|
-
value:
|
|
75
|
-
value == null || value === ''
|
|
76
|
-
? jsxExpression(estreeBoolean(true))
|
|
77
|
-
: value,
|
|
71
|
+
value: jsxAttrValue(value),
|
|
78
72
|
});
|
|
79
73
|
}
|
|
80
74
|
|
package/src/lib/mdx/banner.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
estreeStringArray,
|
|
2
|
+
jsxAttrValue,
|
|
4
3
|
jsxExpression,
|
|
5
4
|
walkContainers,
|
|
6
5
|
type DirectiveNode,
|
|
@@ -18,7 +17,7 @@ export function remarkBanner() {
|
|
|
18
17
|
{
|
|
19
18
|
type: 'mdxJsxAttribute',
|
|
20
19
|
name: 'changeLayout',
|
|
21
|
-
value: jsxExpression(
|
|
20
|
+
value: jsxExpression(false),
|
|
22
21
|
},
|
|
23
22
|
...toAttributes(directive),
|
|
24
23
|
],
|
|
@@ -40,16 +39,13 @@ function toAttributes(directive: DirectiveNode) {
|
|
|
40
39
|
return {
|
|
41
40
|
type: 'mdxJsxAttribute' as const,
|
|
42
41
|
name,
|
|
43
|
-
value: jsxExpression(
|
|
42
|
+
value: jsxExpression(colors),
|
|
44
43
|
};
|
|
45
44
|
}
|
|
46
45
|
return {
|
|
47
46
|
type: 'mdxJsxAttribute' as const,
|
|
48
47
|
name,
|
|
49
|
-
value:
|
|
50
|
-
value == null || value === ''
|
|
51
|
-
? jsxExpression(estreeBoolean(true))
|
|
52
|
-
: value,
|
|
48
|
+
value: jsxAttrValue(value),
|
|
53
49
|
};
|
|
54
50
|
});
|
|
55
51
|
}
|
|
@@ -13,6 +13,8 @@ export type {
|
|
|
13
13
|
MdastNode,
|
|
14
14
|
} from '../../types/mdx';
|
|
15
15
|
|
|
16
|
+
import { toJs } from 'estree-util-to-js';
|
|
17
|
+
import { valueToEstree } from 'estree-util-value-to-estree';
|
|
16
18
|
import { visit, SKIP, CONTINUE } from 'unist-util-visit';
|
|
17
19
|
|
|
18
20
|
export function walkContainers(
|
|
@@ -43,7 +45,7 @@ export function toJsxAttributes(node: DirectiveNode): JsxAttribute[] {
|
|
|
43
45
|
return Object.entries(node.attributes ?? {}).map(([name, value]) => ({
|
|
44
46
|
type: 'mdxJsxAttribute',
|
|
45
47
|
name,
|
|
46
|
-
value: value
|
|
48
|
+
value: jsxAttrValue(value),
|
|
47
49
|
}));
|
|
48
50
|
}
|
|
49
51
|
|
|
@@ -84,35 +86,31 @@ export function contentChildren(node: DirectiveNode): MdastNode[] {
|
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
export function jsxAttr(name: string, value: string | boolean): JsxAttribute {
|
|
87
|
-
return {
|
|
89
|
+
return {
|
|
90
|
+
type: 'mdxJsxAttribute',
|
|
91
|
+
name,
|
|
92
|
+
value: typeof value === 'boolean' ? jsxExpression(value) : value,
|
|
93
|
+
};
|
|
88
94
|
}
|
|
89
95
|
|
|
90
|
-
export function
|
|
96
|
+
export function jsxAttrValue(value: unknown): JsxAttributeValue {
|
|
97
|
+
if (value == null || value === '') return jsxExpression(true);
|
|
98
|
+
if (typeof value === 'boolean') return jsxExpression(value);
|
|
99
|
+
return String(value);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function jsxExpression(value: unknown): JsxAttributeValue {
|
|
103
|
+
const expression = valueToEstree(value);
|
|
91
104
|
return {
|
|
92
105
|
type: 'mdxJsxAttributeValueExpression',
|
|
93
|
-
value:
|
|
106
|
+
value: toJs(expression as unknown as Parameters<typeof toJs>[0]).value,
|
|
94
107
|
data: {
|
|
95
108
|
estree: {
|
|
96
109
|
type: 'Program',
|
|
97
110
|
body: [{ type: 'ExpressionStatement', expression }],
|
|
98
|
-
sourceType: '
|
|
111
|
+
sourceType: 'module',
|
|
99
112
|
},
|
|
100
113
|
},
|
|
101
114
|
};
|
|
102
115
|
}
|
|
103
116
|
|
|
104
|
-
export function estreeString(value: string): unknown {
|
|
105
|
-
return { type: 'Literal', value, raw: JSON.stringify(value) };
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export function estreeStringArray(labels: string[]): unknown {
|
|
109
|
-
return {
|
|
110
|
-
type: 'ArrayExpression',
|
|
111
|
-
elements: labels.map(estreeString),
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export function estreeBoolean(value: boolean): unknown {
|
|
116
|
-
return { type: 'Literal', value, raw: String(value) };
|
|
117
|
-
}
|
|
118
|
-
|
|
@@ -2,10 +2,8 @@ import {
|
|
|
2
2
|
contentChildren,
|
|
3
3
|
extractDirectiveLabel,
|
|
4
4
|
extractLeafLabel,
|
|
5
|
-
estreeBoolean,
|
|
6
|
-
estreeString,
|
|
7
5
|
jsxAttr,
|
|
8
|
-
|
|
6
|
+
jsxAttrValue,
|
|
9
7
|
walkDirectives,
|
|
10
8
|
type DirectiveNode,
|
|
11
9
|
type JsxAttribute,
|
|
@@ -37,12 +35,7 @@ export function toAttributes(directive: DirectiveNode): JsxAttribute[] {
|
|
|
37
35
|
return Object.entries(directive.attributes ?? {}).map(([name, value]) => ({
|
|
38
36
|
type: 'mdxJsxAttribute' as const,
|
|
39
37
|
name,
|
|
40
|
-
value:
|
|
41
|
-
value == null || value === ''
|
|
42
|
-
? jsxExpression(estreeBoolean(true))
|
|
43
|
-
: typeof value === 'string'
|
|
44
|
-
? value
|
|
45
|
-
: jsxExpression(estreeString(String(value))),
|
|
38
|
+
value: jsxAttrValue(value),
|
|
46
39
|
}));
|
|
47
40
|
}
|
|
48
41
|
|
package/src/lib/mdx/files.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
} from 'fumadocs-core/mdx-plugins/remark-mdx-files';
|
|
6
6
|
import { toString } from 'mdast-util-to-string';
|
|
7
7
|
import { visit } from 'unist-util-visit';
|
|
8
|
-
import type
|
|
8
|
+
import { jsxAttr, type DirectiveNode } from './directive-utils.ts';
|
|
9
9
|
import type { JsxAttribute, JsxElement, MdastNode } from '../../types/mdx';
|
|
10
10
|
|
|
11
11
|
type TreeNode = FileNode | FolderNode;
|
|
@@ -49,8 +49,7 @@ function nodeToMdx(node: TreeNode, options: ToMdxOptions): JsxElement {
|
|
|
49
49
|
attributes: attrs,
|
|
50
50
|
children: [],
|
|
51
51
|
};
|
|
52
|
-
if (options.defaultOpenAll)
|
|
53
|
-
attrs.push({ type: 'mdxJsxAttribute', name: 'defaultOpen', value: true });
|
|
52
|
+
if (options.defaultOpenAll) attrs.push(jsxAttr('defaultOpen', true));
|
|
54
53
|
const children =
|
|
55
54
|
node.type === 'folder'
|
|
56
55
|
? node.children.map((item) => nodeToMdx(item, options) as unknown as MdastNode)
|
package/src/lib/mdx/tabs.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
estreeStringArray,
|
|
3
2
|
extractLeafLabel,
|
|
4
3
|
jsxExpression,
|
|
5
4
|
toJsxAttributes,
|
|
@@ -19,7 +18,7 @@ export function remarkTabs() {
|
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
function escapeValue(value: string): string {
|
|
22
|
-
return value.toLowerCase().replace(/\s
|
|
21
|
+
return value.toLowerCase().replace(/\s/g, '-');
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
function toTabs(node: DirectiveNode): void {
|
|
@@ -51,18 +50,18 @@ function toTabs(node: DirectiveNode): void {
|
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
const attributes = toJsxAttributes(node).map((attribute) =>
|
|
54
|
-
attribute.name === 'default'
|
|
53
|
+
attribute.name === 'default' && typeof attribute.value === 'string'
|
|
55
54
|
? {
|
|
56
55
|
type: 'mdxJsxAttribute' as const,
|
|
57
56
|
name: 'defaultValue',
|
|
58
|
-
value: escapeValue(
|
|
57
|
+
value: escapeValue(attribute.value),
|
|
59
58
|
}
|
|
60
59
|
: attribute,
|
|
61
60
|
);
|
|
62
61
|
attributes.unshift({
|
|
63
62
|
type: 'mdxJsxAttribute',
|
|
64
63
|
name: 'items',
|
|
65
|
-
value: jsxExpression(
|
|
64
|
+
value: jsxExpression(items),
|
|
66
65
|
});
|
|
67
66
|
|
|
68
67
|
Object.assign(node, {
|
package/src/lib/story-remark.ts
CHANGED
|
@@ -402,7 +402,7 @@ const DIRECTIVE_META: Record<string, DirectiveMeta> = {
|
|
|
402
402
|
remark: false,
|
|
403
403
|
props: ['url', 'section', 'dataset', 'slug', 'lang', 'version'],
|
|
404
404
|
descriptions: {
|
|
405
|
-
url: 'Page or image.
|
|
405
|
+
url: 'Page or image.webp URL — overrides the fields below',
|
|
406
406
|
section: 'Site section the page belongs to',
|
|
407
407
|
dataset: 'Dataset id within the section',
|
|
408
408
|
slug: 'Page path inside the dataset, e.g. getting-started/install',
|