react-native-marked 8.2.0 → 8.3.1
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/LICENSE +20 -20
- package/README.md +374 -354
- package/dist/commonjs/components/MDImage.js +3 -3
- package/dist/commonjs/components/MDImage.js.map +1 -1
- package/dist/commonjs/components/MDList.js.map +1 -1
- package/dist/commonjs/components/MDSvg.js.map +1 -1
- package/dist/commonjs/components/MDTable.js.map +1 -1
- package/dist/commonjs/hooks/useMarkdown.js +4 -2
- package/dist/commonjs/hooks/useMarkdown.js.map +1 -1
- package/dist/commonjs/hooks/useMarkdownWithComponents.js +7 -1
- package/dist/commonjs/hooks/useMarkdownWithComponents.js.map +1 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/lib/Markdown.js +4 -2
- package/dist/commonjs/lib/Markdown.js.map +1 -1
- package/dist/commonjs/lib/Parser.js +7 -7
- package/dist/commonjs/lib/Parser.js.map +1 -1
- package/dist/commonjs/lib/ReactComponentRegistry.js.map +1 -1
- package/dist/commonjs/lib/ReactComponentTokenizer.js.map +1 -1
- package/dist/commonjs/lib/Renderer.js +7 -5
- package/dist/commonjs/lib/Renderer.js.map +1 -1
- package/dist/commonjs/lib/types.js.map +1 -1
- package/dist/commonjs/theme/colors.js.map +1 -1
- package/dist/commonjs/theme/spacing.js.map +1 -1
- package/dist/commonjs/theme/styles.js +4 -0
- package/dist/commonjs/theme/styles.js.map +1 -1
- package/dist/commonjs/theme/types.js.map +1 -1
- package/dist/commonjs/utils/handlers.js.map +1 -1
- package/dist/commonjs/utils/svg.js.map +1 -1
- package/dist/commonjs/utils/table.js.map +1 -1
- package/dist/commonjs/utils/url.js.map +1 -1
- package/dist/module/components/MDImage.js +3 -3
- package/dist/module/components/MDImage.js.map +1 -1
- package/dist/module/components/MDList.js.map +1 -1
- package/dist/module/components/MDSvg.js.map +1 -1
- package/dist/module/components/MDTable.js.map +1 -1
- package/dist/module/hooks/useMarkdown.js +4 -2
- package/dist/module/hooks/useMarkdown.js.map +1 -1
- package/dist/module/hooks/useMarkdownWithComponents.js +7 -1
- package/dist/module/hooks/useMarkdownWithComponents.js.map +1 -1
- package/dist/module/index.js.map +1 -1
- package/dist/module/lib/Markdown.js +4 -2
- package/dist/module/lib/Markdown.js.map +1 -1
- package/dist/module/lib/Parser.js +7 -7
- package/dist/module/lib/Parser.js.map +1 -1
- package/dist/module/lib/ReactComponentRegistry.js.map +1 -1
- package/dist/module/lib/ReactComponentTokenizer.js.map +1 -1
- package/dist/module/lib/Renderer.js +7 -5
- package/dist/module/lib/Renderer.js.map +1 -1
- package/dist/module/lib/types.js.map +1 -1
- package/dist/module/theme/colors.js.map +1 -1
- package/dist/module/theme/spacing.js.map +1 -1
- package/dist/module/theme/styles.js +4 -0
- package/dist/module/theme/styles.js.map +1 -1
- package/dist/module/theme/types.js.map +1 -1
- package/dist/module/utils/handlers.js.map +1 -1
- package/dist/module/utils/svg.js.map +1 -1
- package/dist/module/utils/table.js.map +1 -1
- package/dist/module/utils/url.js.map +1 -1
- package/dist/typescript/hooks/useMarkdown.d.ts +3 -0
- package/dist/typescript/hooks/useMarkdown.d.ts.map +1 -1
- package/dist/typescript/hooks/useMarkdownWithComponents.d.ts.map +1 -1
- package/dist/typescript/index.d.ts +2 -2
- package/dist/typescript/index.d.ts.map +1 -1
- package/dist/typescript/lib/Markdown.d.ts +1 -1
- package/dist/typescript/lib/Markdown.d.ts.map +1 -1
- package/dist/typescript/lib/Renderer.d.ts +8 -1
- package/dist/typescript/lib/Renderer.d.ts.map +1 -1
- package/dist/typescript/lib/types.d.ts +6 -0
- package/dist/typescript/lib/types.d.ts.map +1 -1
- package/dist/typescript/theme/styles.d.ts.map +1 -1
- package/dist/typescript/theme/types.d.ts +1 -0
- package/dist/typescript/theme/types.d.ts.map +1 -1
- package/package.json +178 -175
- package/src/components/MDImage.tsx +90 -90
- package/src/components/MDList.tsx +46 -46
- package/src/components/MDSvg.tsx +108 -108
- package/src/components/MDTable.tsx +60 -60
- package/src/hooks/useMarkdown.ts +56 -51
- package/src/hooks/useMarkdownWithComponents.tsx +94 -89
- package/src/index.ts +44 -43
- package/src/lib/Markdown.tsx +55 -53
- package/src/lib/Parser.tsx +316 -316
- package/src/lib/ReactComponentRegistry.tsx +52 -52
- package/src/lib/ReactComponentTokenizer.ts +149 -149
- package/src/lib/Renderer.tsx +247 -238
- package/src/lib/types.ts +93 -87
- package/src/theme/colors.ts +31 -31
- package/src/theme/spacing.ts +10 -10
- package/src/theme/styles.ts +206 -198
- package/src/theme/types.ts +34 -33
- package/src/utils/handlers.ts +9 -9
- package/src/utils/svg.ts +14 -14
- package/src/utils/table.ts +29 -29
- package/src/utils/url.ts +22 -22
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import type { ReactNode } from "react";
|
|
2
|
-
import React, { createContext, useContext, useMemo } from "react";
|
|
3
|
-
import type { ReactComponentProps } from "./ReactComponentTokenizer";
|
|
4
|
-
|
|
5
|
-
export interface ReactComponentRendererProps {
|
|
6
|
-
props: ReactComponentProps;
|
|
7
|
-
children?: ReactNode;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type ReactComponentRenderer = (
|
|
11
|
-
props: ReactComponentRendererProps,
|
|
12
|
-
) => ReactNode;
|
|
13
|
-
|
|
14
|
-
export type ReactComponentRegistry = Record<string, ReactComponentRenderer>;
|
|
15
|
-
|
|
16
|
-
interface ReactComponentRegistryContextValue {
|
|
17
|
-
components: ReactComponentRegistry;
|
|
18
|
-
getComponent: (name: string) => ReactComponentRenderer | undefined;
|
|
19
|
-
hasComponent: (name: string) => boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const ReactComponentRegistryContext =
|
|
23
|
-
createContext<ReactComponentRegistryContextValue | null>(null);
|
|
24
|
-
|
|
25
|
-
interface ReactComponentRegistryProviderProps {
|
|
26
|
-
components: ReactComponentRegistry;
|
|
27
|
-
children: ReactNode;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function ReactComponentRegistryProvider({
|
|
31
|
-
components,
|
|
32
|
-
children,
|
|
33
|
-
}: ReactComponentRegistryProviderProps) {
|
|
34
|
-
const contextValue = useMemo<ReactComponentRegistryContextValue>(
|
|
35
|
-
() => ({
|
|
36
|
-
components,
|
|
37
|
-
getComponent: (name: string) => components[name],
|
|
38
|
-
hasComponent: (name: string) => name in components,
|
|
39
|
-
}),
|
|
40
|
-
[components],
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<ReactComponentRegistryContext.Provider value={contextValue}>
|
|
45
|
-
{children}
|
|
46
|
-
</ReactComponentRegistryContext.Provider>
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function useReactComponentRegistry(): ReactComponentRegistryContextValue | null {
|
|
51
|
-
return useContext(ReactComponentRegistryContext);
|
|
52
|
-
}
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import React, { createContext, useContext, useMemo } from "react";
|
|
3
|
+
import type { ReactComponentProps } from "./ReactComponentTokenizer";
|
|
4
|
+
|
|
5
|
+
export interface ReactComponentRendererProps {
|
|
6
|
+
props: ReactComponentProps;
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type ReactComponentRenderer = (
|
|
11
|
+
props: ReactComponentRendererProps,
|
|
12
|
+
) => ReactNode;
|
|
13
|
+
|
|
14
|
+
export type ReactComponentRegistry = Record<string, ReactComponentRenderer>;
|
|
15
|
+
|
|
16
|
+
interface ReactComponentRegistryContextValue {
|
|
17
|
+
components: ReactComponentRegistry;
|
|
18
|
+
getComponent: (name: string) => ReactComponentRenderer | undefined;
|
|
19
|
+
hasComponent: (name: string) => boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const ReactComponentRegistryContext =
|
|
23
|
+
createContext<ReactComponentRegistryContextValue | null>(null);
|
|
24
|
+
|
|
25
|
+
interface ReactComponentRegistryProviderProps {
|
|
26
|
+
components: ReactComponentRegistry;
|
|
27
|
+
children: ReactNode;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function ReactComponentRegistryProvider({
|
|
31
|
+
components,
|
|
32
|
+
children,
|
|
33
|
+
}: ReactComponentRegistryProviderProps) {
|
|
34
|
+
const contextValue = useMemo<ReactComponentRegistryContextValue>(
|
|
35
|
+
() => ({
|
|
36
|
+
components,
|
|
37
|
+
getComponent: (name: string) => components[name],
|
|
38
|
+
hasComponent: (name: string) => name in components,
|
|
39
|
+
}),
|
|
40
|
+
[components],
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<ReactComponentRegistryContext.Provider value={contextValue}>
|
|
45
|
+
{children}
|
|
46
|
+
</ReactComponentRegistryContext.Provider>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function useReactComponentRegistry(): ReactComponentRegistryContextValue | null {
|
|
51
|
+
return useContext(ReactComponentRegistryContext);
|
|
52
|
+
}
|
|
@@ -1,149 +1,149 @@
|
|
|
1
|
-
import type { Tokens } from "marked";
|
|
2
|
-
import { Tokenizer } from "marked";
|
|
3
|
-
|
|
4
|
-
const SELF_CLOSING_REGEX = /^<([A-Z][a-zA-Z0-9]*)([^>]*?)\s*\/>/;
|
|
5
|
-
const OPENING_TAG_REGEX = /^<([A-Z][a-zA-Z0-9]*)([^>]*)>/;
|
|
6
|
-
const PROP_REGEX = /(\w+)(?:=(?:"([^"]*)"|'([^']*)'|\{([^}]*)\}))?/g;
|
|
7
|
-
|
|
8
|
-
export type ReactComponentProps = Record<string, string | boolean | number>;
|
|
9
|
-
|
|
10
|
-
export interface ReactComponentToken extends Tokens.HTML {
|
|
11
|
-
componentName: string;
|
|
12
|
-
componentProps: ReactComponentProps;
|
|
13
|
-
componentChildren: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function parseProps(propsString: string): ReactComponentProps {
|
|
17
|
-
const props: ReactComponentProps = {};
|
|
18
|
-
if (!propsString) return props;
|
|
19
|
-
|
|
20
|
-
let match: RegExpExecArray | null;
|
|
21
|
-
|
|
22
|
-
match = PROP_REGEX.exec(propsString);
|
|
23
|
-
while (match !== null) {
|
|
24
|
-
const [, propName, doubleQuoted, singleQuoted, braced] = match;
|
|
25
|
-
if (propName) {
|
|
26
|
-
if (doubleQuoted !== undefined) {
|
|
27
|
-
props[propName] = doubleQuoted;
|
|
28
|
-
} else if (singleQuoted !== undefined) {
|
|
29
|
-
props[propName] = singleQuoted;
|
|
30
|
-
} else if (braced !== undefined) {
|
|
31
|
-
const trimmed = braced.trim();
|
|
32
|
-
if (trimmed === "true") {
|
|
33
|
-
props[propName] = true;
|
|
34
|
-
} else if (trimmed === "false") {
|
|
35
|
-
props[propName] = false;
|
|
36
|
-
} else if (!Number.isNaN(Number(trimmed))) {
|
|
37
|
-
props[propName] = Number(trimmed);
|
|
38
|
-
} else {
|
|
39
|
-
props[propName] = trimmed;
|
|
40
|
-
}
|
|
41
|
-
} else {
|
|
42
|
-
props[propName] = true;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
match = PROP_REGEX.exec(propsString);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
PROP_REGEX.lastIndex = 0;
|
|
49
|
-
return props;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function findClosingTag(
|
|
53
|
-
src: string,
|
|
54
|
-
componentName: string,
|
|
55
|
-
startIndex: number,
|
|
56
|
-
): { endIndex: number; children: string } | null {
|
|
57
|
-
const openingTag = new RegExp(`<${componentName}(?:\\s[^>]*)?>`, "g");
|
|
58
|
-
const closingTag = `</${componentName}>`;
|
|
59
|
-
|
|
60
|
-
let depth = 1;
|
|
61
|
-
let currentIndex = startIndex;
|
|
62
|
-
|
|
63
|
-
while (depth > 0 && currentIndex < src.length) {
|
|
64
|
-
const closingIndex = src.indexOf(closingTag, currentIndex);
|
|
65
|
-
if (closingIndex === -1) return null;
|
|
66
|
-
|
|
67
|
-
openingTag.lastIndex = currentIndex;
|
|
68
|
-
let nestedMatch: RegExpExecArray | null;
|
|
69
|
-
nestedMatch = openingTag.exec(src);
|
|
70
|
-
while (nestedMatch !== null && nestedMatch.index < closingIndex) {
|
|
71
|
-
depth++;
|
|
72
|
-
nestedMatch = openingTag.exec(src);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
depth--;
|
|
76
|
-
if (depth === 0) {
|
|
77
|
-
return {
|
|
78
|
-
endIndex: closingIndex + closingTag.length,
|
|
79
|
-
children: src.slice(startIndex, closingIndex),
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
currentIndex = closingIndex + closingTag.length;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export class ReactComponentTokenizer extends Tokenizer {
|
|
89
|
-
override html(src: string): Tokens.HTML | undefined {
|
|
90
|
-
const selfClosingMatch = SELF_CLOSING_REGEX.exec(src);
|
|
91
|
-
if (selfClosingMatch) {
|
|
92
|
-
const [raw, componentName, propsString] = selfClosingMatch;
|
|
93
|
-
return this.createReactComponentToken(
|
|
94
|
-
raw,
|
|
95
|
-
componentName ?? "",
|
|
96
|
-
propsString ?? "",
|
|
97
|
-
"",
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const openingMatch = OPENING_TAG_REGEX.exec(src);
|
|
102
|
-
if (openingMatch) {
|
|
103
|
-
const [openingTag, componentName, propsString] = openingMatch;
|
|
104
|
-
const result = findClosingTag(
|
|
105
|
-
src,
|
|
106
|
-
componentName ?? "",
|
|
107
|
-
openingTag?.length ?? 0,
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
if (result) {
|
|
111
|
-
const raw = src.slice(0, result.endIndex);
|
|
112
|
-
return this.createReactComponentToken(
|
|
113
|
-
raw,
|
|
114
|
-
componentName ?? "",
|
|
115
|
-
propsString ?? "",
|
|
116
|
-
result.children,
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return super.html(src);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
private createReactComponentToken(
|
|
125
|
-
raw: string,
|
|
126
|
-
componentName: string,
|
|
127
|
-
propsString: string,
|
|
128
|
-
children: string,
|
|
129
|
-
): ReactComponentToken {
|
|
130
|
-
return {
|
|
131
|
-
type: "html",
|
|
132
|
-
raw,
|
|
133
|
-
text: raw,
|
|
134
|
-
block: true,
|
|
135
|
-
pre: false,
|
|
136
|
-
componentName,
|
|
137
|
-
componentProps: parseProps(propsString),
|
|
138
|
-
componentChildren: children.trim(),
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export function isReactComponentToken(
|
|
144
|
-
token: Tokens.HTML,
|
|
145
|
-
): token is ReactComponentToken {
|
|
146
|
-
return "componentName" in token && typeof token.componentName === "string";
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export default ReactComponentTokenizer;
|
|
1
|
+
import type { Tokens } from "marked";
|
|
2
|
+
import { Tokenizer } from "marked";
|
|
3
|
+
|
|
4
|
+
const SELF_CLOSING_REGEX = /^<([A-Z][a-zA-Z0-9]*)([^>]*?)\s*\/>/;
|
|
5
|
+
const OPENING_TAG_REGEX = /^<([A-Z][a-zA-Z0-9]*)([^>]*)>/;
|
|
6
|
+
const PROP_REGEX = /(\w+)(?:=(?:"([^"]*)"|'([^']*)'|\{([^}]*)\}))?/g;
|
|
7
|
+
|
|
8
|
+
export type ReactComponentProps = Record<string, string | boolean | number>;
|
|
9
|
+
|
|
10
|
+
export interface ReactComponentToken extends Tokens.HTML {
|
|
11
|
+
componentName: string;
|
|
12
|
+
componentProps: ReactComponentProps;
|
|
13
|
+
componentChildren: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function parseProps(propsString: string): ReactComponentProps {
|
|
17
|
+
const props: ReactComponentProps = {};
|
|
18
|
+
if (!propsString) return props;
|
|
19
|
+
|
|
20
|
+
let match: RegExpExecArray | null;
|
|
21
|
+
|
|
22
|
+
match = PROP_REGEX.exec(propsString);
|
|
23
|
+
while (match !== null) {
|
|
24
|
+
const [, propName, doubleQuoted, singleQuoted, braced] = match;
|
|
25
|
+
if (propName) {
|
|
26
|
+
if (doubleQuoted !== undefined) {
|
|
27
|
+
props[propName] = doubleQuoted;
|
|
28
|
+
} else if (singleQuoted !== undefined) {
|
|
29
|
+
props[propName] = singleQuoted;
|
|
30
|
+
} else if (braced !== undefined) {
|
|
31
|
+
const trimmed = braced.trim();
|
|
32
|
+
if (trimmed === "true") {
|
|
33
|
+
props[propName] = true;
|
|
34
|
+
} else if (trimmed === "false") {
|
|
35
|
+
props[propName] = false;
|
|
36
|
+
} else if (!Number.isNaN(Number(trimmed))) {
|
|
37
|
+
props[propName] = Number(trimmed);
|
|
38
|
+
} else {
|
|
39
|
+
props[propName] = trimmed;
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
props[propName] = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
match = PROP_REGEX.exec(propsString);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
PROP_REGEX.lastIndex = 0;
|
|
49
|
+
return props;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function findClosingTag(
|
|
53
|
+
src: string,
|
|
54
|
+
componentName: string,
|
|
55
|
+
startIndex: number,
|
|
56
|
+
): { endIndex: number; children: string } | null {
|
|
57
|
+
const openingTag = new RegExp(`<${componentName}(?:\\s[^>]*)?>`, "g");
|
|
58
|
+
const closingTag = `</${componentName}>`;
|
|
59
|
+
|
|
60
|
+
let depth = 1;
|
|
61
|
+
let currentIndex = startIndex;
|
|
62
|
+
|
|
63
|
+
while (depth > 0 && currentIndex < src.length) {
|
|
64
|
+
const closingIndex = src.indexOf(closingTag, currentIndex);
|
|
65
|
+
if (closingIndex === -1) return null;
|
|
66
|
+
|
|
67
|
+
openingTag.lastIndex = currentIndex;
|
|
68
|
+
let nestedMatch: RegExpExecArray | null;
|
|
69
|
+
nestedMatch = openingTag.exec(src);
|
|
70
|
+
while (nestedMatch !== null && nestedMatch.index < closingIndex) {
|
|
71
|
+
depth++;
|
|
72
|
+
nestedMatch = openingTag.exec(src);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
depth--;
|
|
76
|
+
if (depth === 0) {
|
|
77
|
+
return {
|
|
78
|
+
endIndex: closingIndex + closingTag.length,
|
|
79
|
+
children: src.slice(startIndex, closingIndex),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
currentIndex = closingIndex + closingTag.length;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export class ReactComponentTokenizer extends Tokenizer {
|
|
89
|
+
override html(src: string): Tokens.HTML | undefined {
|
|
90
|
+
const selfClosingMatch = SELF_CLOSING_REGEX.exec(src);
|
|
91
|
+
if (selfClosingMatch) {
|
|
92
|
+
const [raw, componentName, propsString] = selfClosingMatch;
|
|
93
|
+
return this.createReactComponentToken(
|
|
94
|
+
raw,
|
|
95
|
+
componentName ?? "",
|
|
96
|
+
propsString ?? "",
|
|
97
|
+
"",
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const openingMatch = OPENING_TAG_REGEX.exec(src);
|
|
102
|
+
if (openingMatch) {
|
|
103
|
+
const [openingTag, componentName, propsString] = openingMatch;
|
|
104
|
+
const result = findClosingTag(
|
|
105
|
+
src,
|
|
106
|
+
componentName ?? "",
|
|
107
|
+
openingTag?.length ?? 0,
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
if (result) {
|
|
111
|
+
const raw = src.slice(0, result.endIndex);
|
|
112
|
+
return this.createReactComponentToken(
|
|
113
|
+
raw,
|
|
114
|
+
componentName ?? "",
|
|
115
|
+
propsString ?? "",
|
|
116
|
+
result.children,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return super.html(src);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private createReactComponentToken(
|
|
125
|
+
raw: string,
|
|
126
|
+
componentName: string,
|
|
127
|
+
propsString: string,
|
|
128
|
+
children: string,
|
|
129
|
+
): ReactComponentToken {
|
|
130
|
+
return {
|
|
131
|
+
type: "html",
|
|
132
|
+
raw,
|
|
133
|
+
text: raw,
|
|
134
|
+
block: true,
|
|
135
|
+
pre: false,
|
|
136
|
+
componentName,
|
|
137
|
+
componentProps: parseProps(propsString),
|
|
138
|
+
componentChildren: children.trim(),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function isReactComponentToken(
|
|
144
|
+
token: Tokens.HTML,
|
|
145
|
+
): token is ReactComponentToken {
|
|
146
|
+
return "componentName" in token && typeof token.componentName === "string";
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export default ReactComponentTokenizer;
|