@mdxeditor/editor 2.3.4 → 2.3.6
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,137 @@
|
|
|
1
|
+
import { factorySpace } from "micromark-factory-space";
|
|
2
|
+
import { markdownLineEnding } from "./node_modules/micromark-util-character/index.js";
|
|
3
|
+
import { codes, types } from "micromark-util-symbol";
|
|
4
|
+
function commentFromMarkdown(_options) {
|
|
5
|
+
return {
|
|
6
|
+
canContainEols: ["comment"],
|
|
7
|
+
enter: {
|
|
8
|
+
comment(_) {
|
|
9
|
+
this.buffer();
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
exit: {
|
|
13
|
+
comment(token) {
|
|
14
|
+
const text = this.resume();
|
|
15
|
+
if (_options == null ? void 0 : _options.ast) {
|
|
16
|
+
this.enter(
|
|
17
|
+
{
|
|
18
|
+
// @ts-expect-error: hush.
|
|
19
|
+
type: "comment",
|
|
20
|
+
value: "",
|
|
21
|
+
commentValue: text.slice(0, -2)
|
|
22
|
+
},
|
|
23
|
+
token
|
|
24
|
+
);
|
|
25
|
+
this.exit(token);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const tokenize = (effects, ok, nok) => {
|
|
32
|
+
return start;
|
|
33
|
+
function start(code) {
|
|
34
|
+
effects.enter("comment");
|
|
35
|
+
effects.consume(code);
|
|
36
|
+
return open;
|
|
37
|
+
}
|
|
38
|
+
function open(code) {
|
|
39
|
+
if (code === codes.exclamationMark) {
|
|
40
|
+
effects.consume(code);
|
|
41
|
+
return declarationOpen;
|
|
42
|
+
}
|
|
43
|
+
return nok(code);
|
|
44
|
+
}
|
|
45
|
+
function declarationOpen(code) {
|
|
46
|
+
if (code === codes.dash) {
|
|
47
|
+
effects.consume(code);
|
|
48
|
+
return commentOpen;
|
|
49
|
+
}
|
|
50
|
+
return nok(code);
|
|
51
|
+
}
|
|
52
|
+
function commentOpen(code) {
|
|
53
|
+
if (code === codes.dash) {
|
|
54
|
+
effects.consume(code);
|
|
55
|
+
return commentStart;
|
|
56
|
+
}
|
|
57
|
+
return nok(code);
|
|
58
|
+
}
|
|
59
|
+
function commentStart(code) {
|
|
60
|
+
if (code === codes.greaterThan) {
|
|
61
|
+
return nok(code);
|
|
62
|
+
}
|
|
63
|
+
if (markdownLineEnding(code)) {
|
|
64
|
+
return atLineEnding(code);
|
|
65
|
+
}
|
|
66
|
+
effects.enter(types.data);
|
|
67
|
+
if (code === codes.dash) {
|
|
68
|
+
effects.consume(code);
|
|
69
|
+
return commentStartDash;
|
|
70
|
+
}
|
|
71
|
+
return comment2(code);
|
|
72
|
+
}
|
|
73
|
+
function commentStartDash(code) {
|
|
74
|
+
if (code === codes.greaterThan) {
|
|
75
|
+
return nok(code);
|
|
76
|
+
}
|
|
77
|
+
return comment2(code);
|
|
78
|
+
}
|
|
79
|
+
function comment2(code) {
|
|
80
|
+
if (code === codes.eof) {
|
|
81
|
+
return nok(code);
|
|
82
|
+
}
|
|
83
|
+
if (code === codes.dash) {
|
|
84
|
+
effects.consume(code);
|
|
85
|
+
return commentClose;
|
|
86
|
+
}
|
|
87
|
+
if (markdownLineEnding(code)) {
|
|
88
|
+
effects.exit(types.data);
|
|
89
|
+
return atLineEnding(code);
|
|
90
|
+
}
|
|
91
|
+
effects.consume(code);
|
|
92
|
+
return comment2;
|
|
93
|
+
}
|
|
94
|
+
function atLineEnding(code) {
|
|
95
|
+
effects.enter(types.lineEnding);
|
|
96
|
+
effects.consume(code);
|
|
97
|
+
effects.exit(types.lineEnding);
|
|
98
|
+
return factorySpace(effects, afterPrefix, types.linePrefix);
|
|
99
|
+
}
|
|
100
|
+
function afterPrefix(code) {
|
|
101
|
+
if (markdownLineEnding(code)) {
|
|
102
|
+
return atLineEnding(code);
|
|
103
|
+
}
|
|
104
|
+
effects.enter(types.data);
|
|
105
|
+
return comment2(code);
|
|
106
|
+
}
|
|
107
|
+
function commentClose(code) {
|
|
108
|
+
if (code === codes.dash) {
|
|
109
|
+
effects.consume(code);
|
|
110
|
+
return end;
|
|
111
|
+
}
|
|
112
|
+
return comment2(code);
|
|
113
|
+
}
|
|
114
|
+
function end(code) {
|
|
115
|
+
if (code === codes.greaterThan) {
|
|
116
|
+
effects.exit(types.data);
|
|
117
|
+
effects.enter("commentEnd");
|
|
118
|
+
effects.consume(code);
|
|
119
|
+
effects.exit("commentEnd");
|
|
120
|
+
effects.exit("comment");
|
|
121
|
+
return ok(code);
|
|
122
|
+
}
|
|
123
|
+
if (code === codes.dash) {
|
|
124
|
+
effects.consume(code);
|
|
125
|
+
return end;
|
|
126
|
+
}
|
|
127
|
+
return comment2(code);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const comment = {
|
|
131
|
+
flow: { [60]: { tokenize, concrete: true } },
|
|
132
|
+
text: { [60]: { tokenize } }
|
|
133
|
+
};
|
|
134
|
+
export {
|
|
135
|
+
comment,
|
|
136
|
+
commentFromMarkdown
|
|
137
|
+
};
|
|
@@ -27,6 +27,7 @@ import { MdastParagraphVisitor } from "./MdastParagraphVisitor.js";
|
|
|
27
27
|
import { MdastRootVisitor } from "./MdastRootVisitor.js";
|
|
28
28
|
import { MdastTextVisitor } from "./MdastTextVisitor.js";
|
|
29
29
|
import { SharedHistoryPlugin } from "./SharedHistoryPlugin.js";
|
|
30
|
+
import { commentFromMarkdown, comment } from "../../mdastUtilHtmlComment.js";
|
|
30
31
|
const NESTED_EDITOR_UPDATED_COMMAND = createCommand("NESTED_EDITOR_UPDATED_COMMAND");
|
|
31
32
|
const rootEditor$ = Cell(null);
|
|
32
33
|
const activeEditor$ = Cell(null);
|
|
@@ -459,6 +460,7 @@ const corePlugin = realmPlugin({
|
|
|
459
460
|
init(r, params) {
|
|
460
461
|
r.register(createRootEditorSubscription$);
|
|
461
462
|
r.register(createActiveEditorSubscription$);
|
|
463
|
+
r.register(markdownSignal$);
|
|
462
464
|
r.pubIn({
|
|
463
465
|
[initialMarkdown$]: params == null ? void 0 : params.initialMarkdown.trim(),
|
|
464
466
|
[iconComponentFor$]: params == null ? void 0 : params.iconComponentFor,
|
|
@@ -487,8 +489,8 @@ const corePlugin = realmPlugin({
|
|
|
487
489
|
});
|
|
488
490
|
if (!(params == null ? void 0 : params.suppressHtmlProcessing)) {
|
|
489
491
|
r.pubIn({
|
|
490
|
-
[addMdastExtension$]: mdxJsxFromMarkdown(),
|
|
491
|
-
[addSyntaxExtension$]: [mdxJsx(), mdxMd()],
|
|
492
|
+
[addMdastExtension$]: [mdxJsxFromMarkdown(), commentFromMarkdown({ ast: false })],
|
|
493
|
+
[addSyntaxExtension$]: [mdxJsx(), mdxMd(), comment],
|
|
492
494
|
[addToMarkdownExtension$]: mdxJsxToMarkdown(),
|
|
493
495
|
[addImportVisitor$]: MdastHTMLVisitor
|
|
494
496
|
});
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"*.css"
|
|
12
12
|
],
|
|
13
13
|
"type": "module",
|
|
14
|
-
"version": "2.3.
|
|
14
|
+
"version": "2.3.6",
|
|
15
15
|
"description": "React component for rich text markdown editing",
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "vite build",
|
|
@@ -80,6 +80,8 @@
|
|
|
80
80
|
"micromark-extension-mdx-jsx": "^3.0.0",
|
|
81
81
|
"micromark-extension-mdx-md": "^2.0.0",
|
|
82
82
|
"micromark-extension-mdxjs": "^3.0.0",
|
|
83
|
+
"micromark-factory-space": "^2.0.0",
|
|
84
|
+
"micromark-util-symbol": "^2.0.0",
|
|
83
85
|
"react-hook-form": "^7.44.2",
|
|
84
86
|
"unidiff": "^1.0.2"
|
|
85
87
|
},
|