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

marekdedic / prosemirror-remark / 14286002573

05 Apr 2025 09:34PM UTC coverage: 73.113% (-8.5%) from 81.604%
14286002573

Pull #509

github

marekdedic
Migrated syntax extension tests to vitest
Pull Request #509: Switched to vitest

54 of 125 branches covered (43.2%)

310 of 424 relevant lines covered (73.11%)

14.41 hits per line

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

89.47
/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";
4✔
12
import { wrapInList } from "prosemirror-schema-list";
4✔
13
import {
4✔
14
  createProseMirrorNode,
15
  type Extension,
16
  NodeExtension,
17
} from "prosemirror-unified";
18

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

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

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

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

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

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

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

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

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

113
  public override unistToProseMirrorTest(node: UnistNode): boolean {
114
    return (
30✔
115
      node.type === this.unistNodeName() && (node as List).ordered !== true
17✔
116
    );
117
  }
118
}
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

© 2026 Coveralls, Inc