@milkdown/preset-commonmark 7.15.1 → 7.15.2
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/lib/__test__/html.spec.d.ts +2 -0
- package/lib/__test__/html.spec.d.ts.map +1 -0
- package/lib/index.js +53 -49
- package/lib/index.js.map +1 -1
- package/lib/mark/strong.d.ts.map +1 -1
- package/lib/plugin/remark-html-transformer.d.ts.map +1 -1
- package/lib/plugin/sync-list-order-plugin.d.ts.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/__test__/html.spec.ts +46 -0
- package/src/mark/emphasis.ts +1 -1
- package/src/mark/strong.ts +14 -7
- package/src/plugin/remark-html-transformer.ts +7 -1
- package/src/plugin/sync-list-order-plugin.ts +64 -45
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.spec.d.ts","sourceRoot":"","sources":["../../src/__test__/html.spec.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAA"}
|
package/lib/index.js
CHANGED
|
@@ -97,7 +97,7 @@ withMeta(emphasisStarInputRule, {
|
|
|
97
97
|
group: "Emphasis"
|
|
98
98
|
});
|
|
99
99
|
const emphasisUnderscoreInputRule = $inputRule((ctx) => {
|
|
100
|
-
return markRule(
|
|
100
|
+
return markRule(/\b_(?![_\s])(.*?[^_\s])_\b/, emphasisSchema.type(ctx), {
|
|
101
101
|
getAttr: () => ({
|
|
102
102
|
marker: "_"
|
|
103
103
|
}),
|
|
@@ -187,13 +187,17 @@ withMeta(toggleStrongCommand, {
|
|
|
187
187
|
group: "Strong"
|
|
188
188
|
});
|
|
189
189
|
const strongInputRule = $inputRule((ctx) => {
|
|
190
|
-
return markRule(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
190
|
+
return markRule(
|
|
191
|
+
new RegExp("(?<![\\w:/])(?:\\*\\*|__)([^*_]+?)(?:\\*\\*|__)(?![\\w/])$"),
|
|
192
|
+
strongSchema.type(ctx),
|
|
193
|
+
{
|
|
194
|
+
getAttr: (match) => {
|
|
195
|
+
return {
|
|
196
|
+
marker: match[0].startsWith("*") ? "*" : "_"
|
|
197
|
+
};
|
|
198
|
+
}
|
|
195
199
|
}
|
|
196
|
-
|
|
200
|
+
);
|
|
197
201
|
});
|
|
198
202
|
withMeta(strongInputRule, {
|
|
199
203
|
displayName: "InputRule<strong>",
|
|
@@ -1909,12 +1913,13 @@ function flatMapWithDepth(ast, fn) {
|
|
|
1909
1913
|
return fn(node, index, parent);
|
|
1910
1914
|
}
|
|
1911
1915
|
}
|
|
1916
|
+
const BLOCK_CONTAINER_TYPES = ["root", "blockquote", "listItem"];
|
|
1912
1917
|
const remarkHtmlTransformer = $remark(
|
|
1913
1918
|
"remarkHTMLTransformer",
|
|
1914
1919
|
() => () => (tree) => {
|
|
1915
1920
|
flatMapWithDepth(tree, (node, _index, parent) => {
|
|
1916
1921
|
if (!isHTML(node)) return [node];
|
|
1917
|
-
if (parent
|
|
1922
|
+
if (parent && BLOCK_CONTAINER_TYPES.includes(parent.type)) {
|
|
1918
1923
|
node.children = [{ ...node }];
|
|
1919
1924
|
delete node.value;
|
|
1920
1925
|
node.type = "paragraph";
|
|
@@ -2159,12 +2164,14 @@ withMeta(syncHeadingIdPlugin, {
|
|
|
2159
2164
|
group: "Prose"
|
|
2160
2165
|
});
|
|
2161
2166
|
const syncListOrderPlugin = $prose((ctx) => {
|
|
2162
|
-
const syncOrderLabel = (
|
|
2163
|
-
if (
|
|
2167
|
+
const syncOrderLabel = (transactions, _oldState, newState) => {
|
|
2168
|
+
if (!newState.selection || transactions.some(
|
|
2169
|
+
(tr2) => tr2.getMeta("addToHistory") === false || !tr2.isGeneric
|
|
2170
|
+
))
|
|
2171
|
+
return null;
|
|
2164
2172
|
const orderedListType = orderedListSchema.type(ctx);
|
|
2165
2173
|
const bulletListType = bulletListSchema.type(ctx);
|
|
2166
2174
|
const listItemType = listItemSchema.type(ctx);
|
|
2167
|
-
const state = view.state;
|
|
2168
2175
|
const handleNodeItem = (attrs, index) => {
|
|
2169
2176
|
let changed = false;
|
|
2170
2177
|
const expectedLabel = `${index + 1}.`;
|
|
@@ -2174,50 +2181,47 @@ const syncListOrderPlugin = $prose((ctx) => {
|
|
|
2174
2181
|
}
|
|
2175
2182
|
return changed;
|
|
2176
2183
|
};
|
|
2177
|
-
let tr =
|
|
2184
|
+
let tr = newState.tr;
|
|
2178
2185
|
let needDispatch = false;
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
if (
|
|
2198
|
-
attrs
|
|
2199
|
-
changed =
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2186
|
+
newState.doc.descendants(
|
|
2187
|
+
(node, pos, parent, index) => {
|
|
2188
|
+
if (node.type === bulletListType) {
|
|
2189
|
+
const base = node.maybeChild(0);
|
|
2190
|
+
if (base?.type === listItemType && base.attrs.listType === "ordered") {
|
|
2191
|
+
needDispatch = true;
|
|
2192
|
+
tr.setNodeMarkup(pos, orderedListType, { spread: "true" });
|
|
2193
|
+
node.descendants(
|
|
2194
|
+
(child, pos2, _parent, index2) => {
|
|
2195
|
+
if (child.type === listItemType) {
|
|
2196
|
+
const attrs = { ...child.attrs };
|
|
2197
|
+
const changed = handleNodeItem(attrs, index2);
|
|
2198
|
+
if (changed) tr = tr.setNodeMarkup(pos2, void 0, attrs);
|
|
2199
|
+
}
|
|
2200
|
+
return false;
|
|
2201
|
+
}
|
|
2202
|
+
);
|
|
2203
|
+
}
|
|
2204
|
+
} else if (node.type === listItemType && parent?.type === orderedListType) {
|
|
2205
|
+
const attrs = { ...node.attrs };
|
|
2206
|
+
let changed = false;
|
|
2207
|
+
if (attrs.listType !== "ordered") {
|
|
2208
|
+
attrs.listType = "ordered";
|
|
2209
|
+
changed = true;
|
|
2210
|
+
}
|
|
2211
|
+
const base = parent?.maybeChild(0);
|
|
2212
|
+
if (base) changed = handleNodeItem(attrs, index);
|
|
2213
|
+
if (changed) {
|
|
2214
|
+
tr = tr.setNodeMarkup(pos, void 0, attrs);
|
|
2215
|
+
needDispatch = true;
|
|
2216
|
+
}
|
|
2206
2217
|
}
|
|
2207
2218
|
}
|
|
2208
|
-
|
|
2209
|
-
|
|
2219
|
+
);
|
|
2220
|
+
return needDispatch ? tr.setMeta("addToHistory", false) : null;
|
|
2210
2221
|
};
|
|
2211
2222
|
return new Plugin({
|
|
2212
2223
|
key: new PluginKey("MILKDOWN_KEEP_LIST_ORDER"),
|
|
2213
|
-
|
|
2214
|
-
syncOrderLabel(view);
|
|
2215
|
-
return {
|
|
2216
|
-
update: (view2) => {
|
|
2217
|
-
syncOrderLabel(view2);
|
|
2218
|
-
}
|
|
2219
|
-
};
|
|
2220
|
-
}
|
|
2224
|
+
appendTransaction: syncOrderLabel
|
|
2221
2225
|
});
|
|
2222
2226
|
});
|
|
2223
2227
|
withMeta(syncListOrderPlugin, {
|