• 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

92.31
/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";
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 OrderedListExtension extends NodeExtension<List> {
1✔
25
  public override dependencies(): Array<Extension> {
1✔
26
    return [new ListItemExtension()];
5✔
27
  }
5✔
28

29
  public override proseMirrorInputRules(
1✔
30
    proseMirrorSchema: Schema<string, string>,
5✔
31
  ): Array<InputRule> {
5✔
32
    return [
5✔
33
      wrappingInputRule(
5✔
34
        /^\s{0,3}(\d+)\.\s$/u,
5✔
35
        proseMirrorSchema.nodes[this.proseMirrorNodeName()],
5✔
36
        (match) => ({ start: +match[1] }),
5✔
37
        (match, node) =>
5✔
38
          node.childCount + (node.attrs["start"] as number) === +match[1],
×
39
      ),
5✔
40
    ];
5✔
41
  }
5✔
42

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

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

57
  public override proseMirrorNodeSpec(): NodeSpec {
1✔
58
    return {
5✔
59
      attrs: { spread: { default: false }, start: { default: 1 } },
5✔
60
      content: "list_item+",
5✔
61
      group: "block",
5✔
62
      parseDOM: [
5✔
63
        {
5✔
64
          getAttrs(dom: Node | string): { spread: boolean; start: number } {
5✔
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",
5✔
73
        },
5✔
74
      ],
5✔
75
      toDOM(node: ProseMirrorNode): DOMOutputSpec {
5✔
76
        return [
8✔
77
          "ol",
8✔
78
          {
8✔
79
            "data-spread": node.attrs["spread"] as boolean,
8✔
80
            start: node.attrs["start"] as number,
8✔
81
          },
8✔
82
          0,
8✔
83
        ];
8✔
84
      },
8✔
85
    };
5✔
86
  }
5✔
87

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

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

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

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

© 2026 Coveralls, Inc