• 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

77.27
/src/syntax-extensions/OrderedListExtension.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 OrderedListExtension 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}(\d+)\.\s$/u,
35
        proseMirrorSchema.nodes[this.proseMirrorNodeName()],
36
        (match) => ({ start: +match[1] }),
×
37
        (match, node) =>
38
          node.childCount + (node.attrs["start"] as number) === +match[1],
×
39
      ),
40
    ];
41
  }
42

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

53
  public override proseMirrorNodeName(): string {
54
    return "ordered_list";
190✔
55
  }
56

57
  public override proseMirrorNodeSpec(): NodeSpec {
58
    return {
8✔
59
      attrs: { spread: { default: false }, start: { default: 1 } },
60
      content: "list_item+",
61
      group: "block",
62
      parseDOM: [
63
        {
64
          getAttrs(dom: Node | string): { spread: boolean; start: number } {
65
            const start = (dom as HTMLElement).getAttribute("start");
×
66
            return {
×
67
              spread:
68
                (dom as HTMLElement).getAttribute("data-spread") === "true",
69
              start: start !== null ? parseInt(start, 10) : 1,
×
70
            };
71
          },
72
          tag: "ol",
73
        },
74
      ],
75
      toDOM(node: ProseMirrorNode): DOMOutputSpec {
76
        return [
×
77
          "ol",
78
          {
79
            "data-spread": node.attrs["spread"] as boolean,
80
            start: node.attrs["start"] as number,
81
          },
82
          0,
83
        ];
84
      },
85
    };
86
  }
87

88
  public override proseMirrorNodeToUnistNodes(
89
    node: ProseMirrorNode,
90
    convertedChildren: Array<ListContent>,
91
  ): Array<List> {
92
    const spread = node.attrs["spread"] as boolean;
4✔
93
    return [
4✔
94
      {
95
        children: convertedChildren.map((child) => {
96
          child.spread = spread;
4✔
97
          return child;
4✔
98
        }),
99
        ordered: true,
100
        spread,
101
        start: node.attrs["start"] as number,
102
        type: this.unistNodeName(),
103
      },
104
    ];
105
  }
106

107
  public override unistNodeName(): "list" {
108
    return "list";
42✔
109
  }
110

111
  public override unistNodeToProseMirrorNodes(
112
    node: List,
113
    proseMirrorSchema: Schema<string, string>,
114
    convertedChildren: Array<ProseMirrorNode>,
115
  ): Array<ProseMirrorNode> {
116
    return createProseMirrorNode(
4✔
117
      this.proseMirrorNodeName(),
118
      proseMirrorSchema,
119
      convertedChildren,
120
      {
121
        spread: node.spread,
122
        start: node.start ?? 1,
6!
123
      },
124
    );
125
  }
126

127
  public override unistToProseMirrorTest(node: UnistNode): boolean {
128
    return (
38✔
129
      node.type === this.unistNodeName() && (node as List).ordered === true
23✔
130
    );
131
  }
132
}
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