• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

marekdedic / prosemirror-remark / 14286065237

05 Apr 2025 09:44PM UTC coverage: 86.92% (+5.3%) from 81.604%
14286065237

push

github

web-flow
Merge pull request #509 from marekdedic/vitest

Switched to vitest

197 of 211 branches covered (93.36%)

1442 of 1659 relevant lines covered (86.92%)

9.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.44
/src/syntax-extensions/UnorderedListExtension.ts
1
import type { List, ListContent } from "mdast";
2
import type {
3
  DOMOutputSpec,
4
  NodeSpec,
5
  Node as ProseMirrorNode,
6
  Schema,
7
} from "prosemirror-model";
8
import type { Command } from "prosemirror-state";
9
import type { Node as UnistNode } from "unist";
10

11
import { type InputRule, wrappingInputRule } from "prosemirror-inputrules";
1✔
12
import { wrapInList } from "prosemirror-schema-list";
1✔
13
import {
1✔
14
  createProseMirrorNode,
15
  type Extension,
16
  NodeExtension,
17
} from "prosemirror-unified";
18

19
import { ListItemExtension } from "./ListItemExtension";
1✔
20

21
/**
22
 * @public
23
 */
24
export class UnorderedListExtension extends NodeExtension<List> {
1✔
25
  public override dependencies(): Array<Extension> {
1✔
26
    return [new ListItemExtension()];
6✔
27
  }
6✔
28

29
  public override proseMirrorInputRules(
1✔
30
    proseMirrorSchema: Schema<string, string>,
6✔
31
  ): Array<InputRule> {
6✔
32
    return [
6✔
33
      wrappingInputRule(
6✔
34
        /^\s{0,3}([-+*])\s$/u,
6✔
35
        proseMirrorSchema.nodes[this.proseMirrorNodeName()],
6✔
36
      ),
6✔
37
    ];
6✔
38
  }
6✔
39

40
  public override proseMirrorKeymap(
1✔
41
    proseMirrorSchema: Schema<string, string>,
6✔
42
  ): Record<string, Command> {
6✔
43
    return {
6✔
44
      "Shift-Mod-8": wrapInList(
6✔
45
        proseMirrorSchema.nodes[this.proseMirrorNodeName()],
6✔
46
      ),
6✔
47
    };
6✔
48
  }
6✔
49

50
  public override proseMirrorNodeName(): string {
1✔
51
    return "bullet_list";
224✔
52
  }
224✔
53

54
  public override proseMirrorNodeSpec(): NodeSpec {
1✔
55
    return {
6✔
56
      attrs: { spread: { default: false } },
6✔
57
      content: "list_item+",
6✔
58
      group: "block",
6✔
59
      parseDOM: [
6✔
60
        {
6✔
61
          getAttrs(dom: Node | string): { spread: boolean } {
6✔
62
            return {
×
63
              spread:
×
64
                (dom as HTMLElement).getAttribute("data-spread") === "true",
×
65
            };
×
66
          },
×
67
          tag: "ul",
6✔
68
        },
6✔
69
      ],
6✔
70
      toDOM(node: ProseMirrorNode): DOMOutputSpec {
6✔
71
        return ["ul", { "data-spread": node.attrs["spread"] as boolean }, 0];
10✔
72
      },
10✔
73
    };
6✔
74
  }
6✔
75

76
  public override proseMirrorNodeToUnistNodes(
1✔
77
    node: ProseMirrorNode,
24✔
78
    convertedChildren: Array<ListContent>,
24✔
79
  ): Array<List> {
24✔
80
    const spread = node.attrs["spread"] as boolean;
24✔
81
    return [
24✔
82
      {
24✔
83
        children: convertedChildren.map((child) => {
24✔
84
          child.spread = spread;
27✔
85
          return child;
27✔
86
        }),
24✔
87
        ordered: false,
24✔
88
        spread,
24✔
89
        type: this.unistNodeName(),
24✔
90
      },
24✔
91
    ];
24✔
92
  }
24✔
93

94
  public override unistNodeName(): "list" {
1✔
95
    return "list";
65✔
96
  }
65✔
97

98
  public override unistNodeToProseMirrorNodes(
1✔
99
    node: List,
15✔
100
    proseMirrorSchema: Schema<string, string>,
15✔
101
    convertedChildren: Array<ProseMirrorNode>,
15✔
102
  ): Array<ProseMirrorNode> {
15✔
103
    return createProseMirrorNode(
15✔
104
      this.proseMirrorNodeName(),
15✔
105
      proseMirrorSchema,
15✔
106
      convertedChildren,
15✔
107
      {
15✔
108
        spread: node.spread,
15✔
109
      },
15✔
110
    );
15✔
111
  }
15✔
112

113
  public override unistToProseMirrorTest(node: UnistNode): boolean {
1✔
114
    return (
39✔
115
      node.type === this.unistNodeName() && (node as List).ordered !== true
39✔
116
    );
117
  }
39✔
118
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc