@readme/markdown 12.2.0 → 13.1.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/Glossary/style.scss +1 -1
- package/components/Image/index.tsx +6 -2
- package/dist/components/Image/index.d.ts +1 -1
- package/dist/lib/mdast-util/magic-block/index.d.ts +19 -0
- package/dist/lib/mdast-util/magic-block/types.d.ts +30 -0
- package/dist/lib/mdxish.d.ts +11 -0
- package/dist/lib/micromark/magic-block/index.d.ts +12 -0
- package/dist/lib/micromark/magic-block/syntax.d.ts +35 -0
- package/dist/lib/utils/mdxish/protect-code-blocks.d.ts +61 -0
- package/dist/main.css +1 -1
- package/dist/main.css.map +1 -1
- package/dist/main.js +2441 -736
- package/dist/main.node.js +2441 -736
- package/dist/main.node.js.map +1 -1
- package/dist/processor/compile/index.d.ts +3 -1
- package/dist/processor/compile/variable.d.ts +10 -0
- package/dist/processor/transform/mdxish/magic-blocks/magic-block-transformer.d.ts +15 -0
- package/dist/processor/transform/mdxish/magic-blocks/placeholder.d.ts +72 -0
- package/dist/processor/transform/mdxish/magic-blocks/types.d.ts +120 -0
- package/dist/processor/transform/mdxish/mdxish-jsx-to-mdast.d.ts +15 -0
- package/dist/processor/transform/mdxish/mdxish-snake-case-components.d.ts +13 -1
- package/package.json +4 -2
- package/styles/gfm.scss +4 -0
- package/dist/lib/utils/extractMagicBlocks.d.ts +0 -25
- package/dist/processor/transform/mdxish/mdxish-magic-blocks.d.ts +0 -25
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified plugin that transforms `magicBlock` MDAST nodes into final nodes.
|
|
3
|
+
*
|
|
4
|
+
* This replaces the magicBlockRestorer plugin by working directly with
|
|
5
|
+
* parsed `magicBlock` nodes from the micromark tokenizer instead of
|
|
6
|
+
* finding placeholder tokens.
|
|
7
|
+
*/
|
|
8
|
+
import type { MagicBlockTransformerOptions } from './types';
|
|
9
|
+
import type { Root as MdastRoot } from 'mdast';
|
|
10
|
+
import type { Plugin } from 'unified';
|
|
11
|
+
/**
|
|
12
|
+
* Unified plugin that transforms magicBlock nodes into final MDAST nodes.
|
|
13
|
+
*/
|
|
14
|
+
declare const magicBlockTransformer: Plugin<[MagicBlockTransformerOptions?], MdastRoot>;
|
|
15
|
+
export default magicBlockTransformer;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export declare const EMPTY_IMAGE_PLACEHOLDER: {
|
|
2
|
+
type: string;
|
|
3
|
+
url: string;
|
|
4
|
+
alt: string;
|
|
5
|
+
title: string;
|
|
6
|
+
data: {
|
|
7
|
+
hProperties: {};
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare const EMPTY_EMBED_PLACEHOLDER: {
|
|
11
|
+
type: string;
|
|
12
|
+
children: {
|
|
13
|
+
type: string;
|
|
14
|
+
url: string;
|
|
15
|
+
title: string;
|
|
16
|
+
children: {
|
|
17
|
+
type: string;
|
|
18
|
+
value: string;
|
|
19
|
+
}[];
|
|
20
|
+
}[];
|
|
21
|
+
data: {
|
|
22
|
+
hName: string;
|
|
23
|
+
hProperties: {
|
|
24
|
+
url: string;
|
|
25
|
+
href: string;
|
|
26
|
+
title: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export declare const EMPTY_RECIPE_PLACEHOLDER: {
|
|
31
|
+
type: string;
|
|
32
|
+
name: string;
|
|
33
|
+
attributes: any[];
|
|
34
|
+
children: any[];
|
|
35
|
+
};
|
|
36
|
+
export declare const EMPTY_CALLOUT_PLACEHOLDER: {
|
|
37
|
+
type: string;
|
|
38
|
+
name: string;
|
|
39
|
+
attributes: {
|
|
40
|
+
type: string;
|
|
41
|
+
name: string;
|
|
42
|
+
value: string;
|
|
43
|
+
}[];
|
|
44
|
+
children: {
|
|
45
|
+
type: string;
|
|
46
|
+
depth: number;
|
|
47
|
+
children: {
|
|
48
|
+
type: string;
|
|
49
|
+
value: string;
|
|
50
|
+
}[];
|
|
51
|
+
}[];
|
|
52
|
+
};
|
|
53
|
+
export declare const EMPTY_TABLE_PLACEHOLDER: {
|
|
54
|
+
type: string;
|
|
55
|
+
align: string[];
|
|
56
|
+
children: {
|
|
57
|
+
type: string;
|
|
58
|
+
children: {
|
|
59
|
+
type: string;
|
|
60
|
+
children: {
|
|
61
|
+
type: string;
|
|
62
|
+
value: string;
|
|
63
|
+
}[];
|
|
64
|
+
}[];
|
|
65
|
+
}[];
|
|
66
|
+
};
|
|
67
|
+
export declare const EMPTY_CODE_PLACEHOLDER: {
|
|
68
|
+
type: string;
|
|
69
|
+
value: string;
|
|
70
|
+
lang: any;
|
|
71
|
+
meta: any;
|
|
72
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { RootContent } from 'mdast';
|
|
2
|
+
import type { Position } from 'unist';
|
|
3
|
+
export interface MdastNode {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
children?: MdastNode[];
|
|
6
|
+
type: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Base interface for magic block JSON data.
|
|
10
|
+
*/
|
|
11
|
+
export interface MagicBlockJson {
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
sidebar?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface CodeBlockJson extends MagicBlockJson {
|
|
16
|
+
codes: {
|
|
17
|
+
code: string;
|
|
18
|
+
language: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
}[];
|
|
21
|
+
}
|
|
22
|
+
export interface ApiHeaderJson extends MagicBlockJson {
|
|
23
|
+
level?: number;
|
|
24
|
+
title?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ImageBlockJson extends MagicBlockJson {
|
|
27
|
+
images: {
|
|
28
|
+
align?: string;
|
|
29
|
+
border?: boolean;
|
|
30
|
+
caption?: string;
|
|
31
|
+
image?: [string, string?, string?];
|
|
32
|
+
sizing?: string;
|
|
33
|
+
}[];
|
|
34
|
+
}
|
|
35
|
+
export interface CalloutJson extends MagicBlockJson {
|
|
36
|
+
body?: string;
|
|
37
|
+
icon?: string;
|
|
38
|
+
title?: string;
|
|
39
|
+
type?: string | [string, string];
|
|
40
|
+
}
|
|
41
|
+
export interface ParametersJson extends MagicBlockJson {
|
|
42
|
+
align?: string[];
|
|
43
|
+
cols: number;
|
|
44
|
+
data: Record<string, string>;
|
|
45
|
+
rows: number;
|
|
46
|
+
}
|
|
47
|
+
export interface EmbedJson extends MagicBlockJson {
|
|
48
|
+
html?: boolean;
|
|
49
|
+
provider?: string;
|
|
50
|
+
title?: string | null;
|
|
51
|
+
url: string;
|
|
52
|
+
}
|
|
53
|
+
export interface HtmlJson extends MagicBlockJson {
|
|
54
|
+
html: string;
|
|
55
|
+
}
|
|
56
|
+
export interface RecipeJson extends MagicBlockJson {
|
|
57
|
+
backgroundColor?: string;
|
|
58
|
+
emoji?: string;
|
|
59
|
+
id?: string;
|
|
60
|
+
link?: string;
|
|
61
|
+
slug: string;
|
|
62
|
+
title: string;
|
|
63
|
+
}
|
|
64
|
+
export interface MagicBlockTransformerOptions {
|
|
65
|
+
compatibilityMode?: boolean;
|
|
66
|
+
safeMode?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Magic block image node structure (output from magicBlockTransformer).
|
|
70
|
+
* This is an intermediate format before conversion to ImageBlock.
|
|
71
|
+
*/
|
|
72
|
+
export interface MagicBlockImage {
|
|
73
|
+
alt?: string;
|
|
74
|
+
data?: {
|
|
75
|
+
hProperties?: {
|
|
76
|
+
align?: string;
|
|
77
|
+
border?: string;
|
|
78
|
+
width?: string;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
position?: Position;
|
|
82
|
+
title?: string;
|
|
83
|
+
type: 'image';
|
|
84
|
+
url?: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Magic block embed node structure (output from magicBlockTransformer).
|
|
88
|
+
* This is an intermediate format before conversion to EmbedBlock.
|
|
89
|
+
*/
|
|
90
|
+
export interface MagicBlockEmbed {
|
|
91
|
+
children?: RootContent[];
|
|
92
|
+
data?: {
|
|
93
|
+
hName?: string;
|
|
94
|
+
hProperties?: {
|
|
95
|
+
favicon?: string;
|
|
96
|
+
href?: string;
|
|
97
|
+
html?: string;
|
|
98
|
+
image?: string;
|
|
99
|
+
provider?: string;
|
|
100
|
+
providerName?: string;
|
|
101
|
+
providerUrl?: string;
|
|
102
|
+
title?: string;
|
|
103
|
+
url?: string;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
position?: Position;
|
|
107
|
+
type: 'embed';
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Figure node that may contain an image (from magicBlockTransformer with caption).
|
|
111
|
+
* This is an intermediate format before conversion to Figure.
|
|
112
|
+
*/
|
|
113
|
+
export interface MagicBlockFigure {
|
|
114
|
+
children: RootContent[];
|
|
115
|
+
data?: {
|
|
116
|
+
hName?: string;
|
|
117
|
+
};
|
|
118
|
+
position?: Position;
|
|
119
|
+
type: 'figure';
|
|
120
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Parent } from 'mdast';
|
|
2
|
+
import type { Plugin } from 'unified';
|
|
3
|
+
/**
|
|
4
|
+
* Transform mdxJsxFlowElement nodes and magic block nodes into proper MDAST node types.
|
|
5
|
+
*
|
|
6
|
+
* This transformer runs after mdxishComponentBlocks and converts:
|
|
7
|
+
* - JSX component elements (Image, Callout, Embed, Recipe) into their corresponding MDAST types
|
|
8
|
+
* - Magic block image nodes (type: 'image') into image-block
|
|
9
|
+
* - Magic block embed nodes (type: 'embed') into embed-block
|
|
10
|
+
* - Figure nodes containing images (from magic blocks with captions) - transforms the inner image
|
|
11
|
+
*
|
|
12
|
+
* This is controlled by the `newEditorTypes` flag to maintain backwards compatibility.
|
|
13
|
+
*/
|
|
14
|
+
declare const mdxishJsxToMdast: Plugin<[], Parent>;
|
|
15
|
+
export default mdxishJsxToMdast;
|
|
@@ -3,12 +3,24 @@ export interface SnakeCasePreprocessResult {
|
|
|
3
3
|
content: string;
|
|
4
4
|
mapping: SnakeCaseMapping;
|
|
5
5
|
}
|
|
6
|
+
export interface ProcessSnakeCaseOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Set of known component names
|
|
9
|
+
* Used to filter which snake_case components to transform
|
|
10
|
+
*/
|
|
11
|
+
knownComponents?: Set<string>;
|
|
12
|
+
}
|
|
6
13
|
/**
|
|
7
14
|
* Replaces snake_case component names with valid HTML placeholders.
|
|
8
15
|
* Required because remark-parse rejects tags with underscores.
|
|
9
16
|
* Example: `<Snake_case />` → `<MDXishSnakeCase0 />`
|
|
17
|
+
*
|
|
18
|
+
* Code blocks and inline code are protected and will not be transformed.
|
|
19
|
+
*
|
|
20
|
+
* @param content - The markdown content to process
|
|
21
|
+
* @param options - Options including knownComponents to filter by
|
|
10
22
|
*/
|
|
11
|
-
export declare function processSnakeCaseComponent(content: string): SnakeCasePreprocessResult;
|
|
23
|
+
export declare function processSnakeCaseComponent(content: string, options?: ProcessSnakeCaseOptions): SnakeCasePreprocessResult;
|
|
12
24
|
/**
|
|
13
25
|
* Restores placeholder name to original snake_case name.
|
|
14
26
|
* Uses case-insensitive matching since HTML parsers normalize to lowercase.
|
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": "
|
|
5
|
+
"version": "13.1.0",
|
|
6
6
|
"main": "dist/main.node.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"browser": "dist/main.js",
|
|
@@ -45,6 +45,8 @@
|
|
|
45
45
|
"mdast-util-phrasing": "^4.1.0",
|
|
46
46
|
"mdast-util-to-markdown": "^2.1.2",
|
|
47
47
|
"micromark-extension-mdx-expression": "^3.0.1",
|
|
48
|
+
"micromark-util-character": "^2.1.1",
|
|
49
|
+
"micromark-util-symbol": "^2.0.1",
|
|
48
50
|
"path-browserify": "^1.0.1",
|
|
49
51
|
"postcss": "^8.5.1",
|
|
50
52
|
"postcss-prefix-selector": "^2.1.0",
|
|
@@ -156,7 +158,7 @@
|
|
|
156
158
|
},
|
|
157
159
|
{
|
|
158
160
|
"path": "dist/main.node.js",
|
|
159
|
-
"maxSize": "
|
|
161
|
+
"maxSize": "800KB"
|
|
160
162
|
}
|
|
161
163
|
]
|
|
162
164
|
},
|
package/styles/gfm.scss
CHANGED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export interface BlockHit {
|
|
2
|
-
key: string;
|
|
3
|
-
raw: string;
|
|
4
|
-
token: string;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* The content matching in this regex captures everything between `[block:TYPE]`
|
|
8
|
-
* and `[/block]`, including new lines. Negative lookahead for the closing
|
|
9
|
-
* `[/block]` tag is required to prevent greedy matching to ensure it stops at
|
|
10
|
-
* the first closing tag it encounters preventing vulnerability to polynomial
|
|
11
|
-
* backtracking issues.
|
|
12
|
-
*/
|
|
13
|
-
export declare const MAGIC_BLOCK_REGEX: RegExp;
|
|
14
|
-
/**
|
|
15
|
-
* Extract legacy magic block syntax from a markdown string.
|
|
16
|
-
* Returns the modified markdown and an array of extracted blocks.
|
|
17
|
-
*/
|
|
18
|
-
export declare function extractMagicBlocks(markdown: string): {
|
|
19
|
-
replaced: string;
|
|
20
|
-
blocks: BlockHit[];
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Restore extracted magic blocks back into a markdown string.
|
|
24
|
-
*/
|
|
25
|
-
export declare function restoreMagicBlocks(replaced: string, blocks: BlockHit[]): string;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Legacy magic block parser for RDMD compatibility.
|
|
3
|
-
* Parses `[block:TYPE]JSON[/block]` syntax and returns MDAST nodes.
|
|
4
|
-
* Taken from the v6 branch with some modifications to be more type safe
|
|
5
|
-
* and adapted with the mdxish flow.
|
|
6
|
-
*/
|
|
7
|
-
import type { BlockHit } from '../../../lib/utils/extractMagicBlocks';
|
|
8
|
-
import type { Root as MdastRoot } from 'mdast';
|
|
9
|
-
import type { Plugin } from 'unified';
|
|
10
|
-
export interface ParseMagicBlockOptions {
|
|
11
|
-
alwaysThrow?: boolean;
|
|
12
|
-
compatibilityMode?: boolean;
|
|
13
|
-
safeMode?: boolean;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Unified plugin that restores magic blocks from placeholder tokens.
|
|
17
|
-
*
|
|
18
|
-
* During preprocessing, extractMagicBlocks replaces [block:TYPE]...[/block]
|
|
19
|
-
* with inline code tokens like `__MAGIC_BLOCK_0__`. This plugin finds those
|
|
20
|
-
* tokens in the parsed MDAST and replaces them with the parsed block content.
|
|
21
|
-
*/
|
|
22
|
-
declare const magicBlockRestorer: Plugin<[{
|
|
23
|
-
blocks: BlockHit[];
|
|
24
|
-
}], MdastRoot>;
|
|
25
|
-
export default magicBlockRestorer;
|