@milkdown/preset-commonmark 7.9.0 → 7.10.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/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { $markAttr, $markSchema, $inputRule, $command, $useKeymap, $node, $remark, $nodeAttr, $nodeSchema, $ctx, $prose } from "@milkdown/utils";
2
2
  import { remarkStringifyOptionsCtx, commandsCtx, editorViewCtx } from "@milkdown/core";
3
3
  import { toggleMark, setBlockType, wrapIn } from "@milkdown/prose/commands";
4
- import { visit } from "unist-util-visit";
4
+ import { visitParents } from "unist-util-visit-parents";
5
5
  import { Fragment } from "@milkdown/prose/model";
6
6
  import { expectDomTypeError } from "@milkdown/exception";
7
7
  import { textblockTypeInputRule, wrappingInputRule, InputRule } from "@milkdown/prose/inputrules";
@@ -10,6 +10,7 @@ import { markRule, findSelectedNodeOfType } from "@milkdown/prose";
10
10
  import { sinkListItem, splitListItem, liftListItem } from "@milkdown/prose/schema-list";
11
11
  import { ReplaceStep, AddMarkStep } from "@milkdown/prose/transform";
12
12
  import { Decoration, DecorationSet } from "@milkdown/prose/view";
13
+ import { visit } from "unist-util-visit";
13
14
  import remarkInlineLinks from "remark-inline-links";
14
15
  function serializeText(state, node) {
15
16
  var _a;
@@ -408,17 +409,24 @@ withMeta(docSchema, {
408
409
  group: "Doc"
409
410
  });
410
411
  function visitEmptyLine(ast) {
411
- return visit(ast, (node) => {
412
- var _a, _b;
413
- if (((_a = node.children) == null ? void 0 : _a.length) !== 1) return;
414
- const firstChild = (_b = node.children) == null ? void 0 : _b[0];
415
- if (!firstChild || firstChild.type !== "html") return;
416
- const { value } = firstChild;
417
- if (!["<br />", "<br>", "<br/>"].includes(value)) {
418
- return;
419
- }
420
- node.children.splice(0, 1);
421
- });
412
+ return visitParents(
413
+ ast,
414
+ (node) => {
415
+ var _a;
416
+ return node.type === "html" && ["<br />", "<br>", "<br >", "<br/>"].includes(
417
+ (_a = node.value) == null ? void 0 : _a.trim()
418
+ );
419
+ },
420
+ (node, parents) => {
421
+ if (!parents.length) return;
422
+ const parent = parents[parents.length - 1];
423
+ if (!parent) return;
424
+ const index = parent.children.indexOf(node);
425
+ if (index === -1) return;
426
+ parent.children.splice(index, 1);
427
+ },
428
+ true
429
+ );
422
430
  }
423
431
  const remarkPreserveEmptyLinePlugin = $remark(
424
432
  "remark-preserve-empty-line",