@readme/markdown 14.2.5 → 14.3.0
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/components/Embed/index.tsx +24 -4
- package/components/TailwindStyle/index.tsx +19 -6
- package/dist/components/Embed/index.d.ts +2 -2
- package/dist/main.js +512 -52
- package/dist/main.node.js +542 -52
- package/dist/main.node.js.map +1 -1
- package/dist/processor/transform/mdxish/evaluate-exports.d.ts +27 -0
- package/dist/processor/transform/mdxish/evaluate-expressions.d.ts +4 -3
- package/dist/processor/utils.d.ts +10 -2
- package/package.json +7 -2
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
import type { Plugin } from 'unified';
|
|
3
|
+
export type MdxishScope = Record<string, unknown>;
|
|
4
|
+
declare module 'vfile' {
|
|
5
|
+
interface DataMap {
|
|
6
|
+
mdxishScope?: MdxishScope;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
declare module 'hast' {
|
|
10
|
+
interface RootData {
|
|
11
|
+
mdxishScope?: MdxishScope;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Evaluate `export const/function` declarations introduced by mdxjsEsm nodes.
|
|
16
|
+
*
|
|
17
|
+
* Walks each mdxjsEsm node's estree to gather all export declarations while
|
|
18
|
+
* stripping the `export` statements. All declarations are then evaluated in a
|
|
19
|
+
* single sandboxed Function so that they can reference one another regardless
|
|
20
|
+
* of source order. Every resulting binding lands in a flat scope record —
|
|
21
|
+
* components, helpers, and plain values share the same map.
|
|
22
|
+
*
|
|
23
|
+
* Any evaluation error is consumed and logged. We don't throw because it's
|
|
24
|
+
* against the spirit of this engine to be less permissive than MDX needs.
|
|
25
|
+
*/
|
|
26
|
+
declare const evaluateExports: Plugin<[], Root>;
|
|
27
|
+
export default evaluateExports;
|
|
@@ -3,9 +3,10 @@ import type { Plugin } from 'unified';
|
|
|
3
3
|
/**
|
|
4
4
|
* AST transformer to evaluate MDX expressions.
|
|
5
5
|
* Replaces mdxFlowExpression and mdxTextExpression nodes with their evaluated values.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Self-contained expressions resolve directly (e.g. `{1+1}`); expressions that
|
|
7
|
+
* reference identifiers can resolve if those identifiers were introduced by an
|
|
8
|
+
* earlier `export const/function` (collected onto `file.data.mdxishScope`).
|
|
9
|
+
* Anything else falls through to the error branch and is kept as literal `{...}` text.
|
|
9
10
|
*/
|
|
10
11
|
declare const evaluateExpressions: Plugin<[], Root>;
|
|
11
12
|
export default evaluateExpressions;
|
|
@@ -2,11 +2,19 @@ import type { Root as HastRoot } from 'hast';
|
|
|
2
2
|
import type { Node, Root as MdastRoot, Root } from 'mdast';
|
|
3
3
|
import type { MdxJsxFlowElement, MdxJsxTextElement, MdxjsEsm } from 'mdast-util-mdx';
|
|
4
4
|
import type { MdxJsxAttribute } from 'mdast-util-mdx-jsx';
|
|
5
|
+
import { Parser } from 'acorn';
|
|
6
|
+
/**
|
|
7
|
+
* Single instance of acorn parser extended with `acorn-jsx`
|
|
8
|
+
* to parse expressions containing JSX.
|
|
9
|
+
*/
|
|
10
|
+
export declare const jsxAcornParser: typeof Parser;
|
|
5
11
|
/**
|
|
6
12
|
* Evaluate a JavaScript expression source and return its value.
|
|
7
13
|
*
|
|
8
14
|
* Wrapping in parens lets object literals (`{color: 'red'}`) parse as
|
|
9
|
-
* expressions.
|
|
15
|
+
* expressions. Pass `scope` to expose named bindings (e.g. values introduced
|
|
16
|
+
* by an `export const`) to the expression; without it, only self-contained
|
|
17
|
+
* literals resolve.
|
|
10
18
|
*
|
|
11
19
|
* > ☢️ **Danger**: this `eval`s JavaScript. Only call when safeMode is off —
|
|
12
20
|
* > safeMode's contract is that expression syntax is never evaluated, and the
|
|
@@ -15,7 +23,7 @@ import type { MdxJsxAttribute } from 'mdast-util-mdx-jsx';
|
|
|
15
23
|
*
|
|
16
24
|
* Throws on parse/runtime error; callers decide the fallback.
|
|
17
25
|
*/
|
|
18
|
-
export declare function evaluate(source: string): any;
|
|
26
|
+
export declare function evaluate(source: string, scope?: Record<string, unknown>): any;
|
|
19
27
|
/**
|
|
20
28
|
* Formats the hProperties of a node as a string, so they can be compiled back into JSX/MDX.
|
|
21
29
|
* This currently sets all the values to a string since we process/compile the MDX on the fly
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@readme/markdown",
|
|
3
3
|
"description": "ReadMe's React-based Markdown parser",
|
|
4
4
|
"author": "Rafe Goldberg <rafe@readme.io>",
|
|
5
|
-
"version": "14.
|
|
5
|
+
"version": "14.3.0",
|
|
6
6
|
"main": "dist/main.node.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"browser": "dist/main.js",
|
|
@@ -35,6 +35,8 @@
|
|
|
35
35
|
"deepmerge": "^4.3.1",
|
|
36
36
|
"emoji-regex": "^10.2.1",
|
|
37
37
|
"entities": "^4.5.0",
|
|
38
|
+
"estree-util-build-jsx": "^3.0.1",
|
|
39
|
+
"estree-util-to-js": "^2.0.0",
|
|
38
40
|
"estree-util-value-to-estree": "^3.1.1",
|
|
39
41
|
"gemoji": "^8.1.0",
|
|
40
42
|
"github-slugger": "^2.0.0",
|
|
@@ -50,11 +52,13 @@
|
|
|
50
52
|
"mdast-util-gfm-strikethrough": "^2.0.0",
|
|
51
53
|
"mdast-util-mdx": "^3.0.0",
|
|
52
54
|
"mdast-util-mdx-expression": "2.0.0",
|
|
55
|
+
"mdast-util-mdxjs-esm": "^2.0.1",
|
|
53
56
|
"mdast-util-phrasing": "^4.1.0",
|
|
54
57
|
"mdast-util-to-markdown": "^2.1.2",
|
|
55
58
|
"micromark-extension-gfm-strikethrough": "^2.1.0",
|
|
56
59
|
"micromark-extension-mdx-expression": "^3.0.1",
|
|
57
60
|
"micromark-extension-mdxjs": "^3.0.0",
|
|
61
|
+
"micromark-extension-mdxjs-esm": "^3.0.0",
|
|
58
62
|
"micromark-util-character": "^2.1.1",
|
|
59
63
|
"micromark-util-html-tag-name": "^2.0.1",
|
|
60
64
|
"micromark-util-symbol": "^2.0.1",
|
|
@@ -91,6 +95,7 @@
|
|
|
91
95
|
"@mdx-js/react": "^3.0.0",
|
|
92
96
|
"@tippyjs/react": "^4.1.0",
|
|
93
97
|
"acorn": "v8.13.0",
|
|
98
|
+
"acorn-jsx": "^5.3.2",
|
|
94
99
|
"react": "18.x",
|
|
95
100
|
"react-dom": "18.x"
|
|
96
101
|
},
|
|
@@ -172,7 +177,7 @@
|
|
|
172
177
|
},
|
|
173
178
|
{
|
|
174
179
|
"path": "dist/main.node.js",
|
|
175
|
-
"maxSize": "
|
|
180
|
+
"maxSize": "945KB"
|
|
176
181
|
}
|
|
177
182
|
]
|
|
178
183
|
},
|