@readme/markdown 14.2.6 → 14.4.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.
@@ -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
- * Runs with no scope, so only self-contained expressions resolve
7
- * (e.g. `{1+1}`, `{"hi".toUpperCase()}`); anything that references an external
8
- * identifier falls through to the error branch and is kept as literal `{...}` text.
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;
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Skip certain regions / parts of the content that htmlparser2 should not handle
3
+ */
4
+ export declare const maskNonTagRegions: (html: string) => string;
1
5
  interface TagEvent {
2
6
  end: number;
3
7
  name: string;
@@ -1,5 +1,6 @@
1
1
  import type { Node } from 'mdast';
2
2
  export interface Insert {
3
+ consumes?: number;
3
4
  offset: number;
4
5
  text: string;
5
6
  }
@@ -8,14 +8,15 @@
8
8
  *
9
9
  * @link https://spec.commonmark.org/0.29/#html-blocks
10
10
  *
11
- * This preprocessor inserts a blank line after standalone HTML lines when the
12
- * next line is non-blank and not an HTML construct (because they still might be part of the HTML flow),
13
- * ensuring micromark's HTML flow tokenizer terminates and subsequent content is parsed independently.
11
+ * This preprocessor inserts a blank line after standalone HTML lines when the next
12
+ * line is non-blank and not an HTML construct, ensuring micromark's HTML flow
13
+ * tokenizer terminates and subsequent content is parsed independently.
14
14
  *
15
15
  * Conditions:
16
- * 1. Only targets non-indented lines with lowercase tag names. Uppercase tags
17
- * (e.g., `<Table>`, `<MyComponent>`) are JSX custom components and don't
18
- * trigger CommonMark HTML blocks, so they are left untouched.
19
- * 2. Lines inside protected blocks (e.g., code blocks) should be left untouched.
16
+ * 1. Only non-indented lines with lowercase tag names are considered. Uppercase tags
17
+ * (e.g. `<Table>`, `<MyComponent>`) are JSX custom components and don't trigger
18
+ * CommonMark HTML blocks.
19
+ * 2. Lines inside protected blocks (e.g. fenced code) are left untouched.
20
+ * 3. Lines with an unclosed RAW_CONTENT_TAGS opener are exempted.
20
21
  */
21
22
  export declare function terminateHtmlFlowBlocks(content: string): string;
@@ -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. Runs with no scope, so only self-contained literals resolve.
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.2.6",
5
+ "version": "14.4.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": "920KB"
180
+ "maxSize": "947KB"
176
181
  }
177
182
  ]
178
183
  },
package/types.d.ts CHANGED
@@ -136,6 +136,7 @@ export interface ImageBlockAttrs {
136
136
  caption?: string;
137
137
  children?: RootContent[];
138
138
  className?: string;
139
+ framed?: boolean;
139
140
  height?: string;
140
141
  lazy?: boolean;
141
142
  sizing?: string;