• 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

66.67
/src/syntax-extensions/HorizontalRuleExtension.ts
1
import type { ThematicBreak } 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

10
import { InputRule } from "prosemirror-inputrules";
4✔
11
import { createProseMirrorNode, NodeExtension } from "prosemirror-unified";
4✔
12

13
/**
14
 * @public
15
 */
16
export class HorizontalRuleExtension extends NodeExtension<ThematicBreak> {
4✔
17
  public override proseMirrorInputRules(
18
    proseMirrorSchema: Schema<string, string>,
19
  ): Array<InputRule> {
20
    return [
8✔
21
      new InputRule(/^\s{0,3}(?:\*\*\*|---|___)\n$/u, (state, _, start, end) =>
22
        state.tr.replaceWith(
×
23
          start,
24
          end,
25
          createProseMirrorNode(
26
            this.proseMirrorNodeName(),
27
            proseMirrorSchema,
28
            [],
29
          ),
30
        ),
31
      ),
32
    ];
33
  }
34

35
  public override proseMirrorKeymap(
36
    proseMirrorSchema: Schema<string, string>,
37
  ): Record<string, Command> {
38
    return {
8✔
39
      "Mod-_": (state, dispatch): true => {
40
        if (dispatch) {
×
41
          dispatch(
×
42
            state.tr
43
              .replaceSelectionWith(
44
                proseMirrorSchema.nodes[this.proseMirrorNodeName()].create(),
45
              )
46
              .scrollIntoView(),
47
          );
48
        }
49
        return true;
×
50
      },
51
    };
52
  }
53

54
  public override proseMirrorNodeName(): string {
55
    return "horizontal_rule";
174✔
56
  }
57

58
  public override proseMirrorNodeSpec(): NodeSpec {
59
    return {
8✔
60
      group: "block",
61
      parseDOM: [{ tag: "hr" }],
62
      toDOM(): DOMOutputSpec {
63
        return ["div", ["hr"]];
×
64
      },
65
    };
66
  }
67

68
  public override proseMirrorNodeToUnistNodes(): Array<ThematicBreak> {
69
    return [
4✔
70
      {
71
        type: this.unistNodeName(),
72
      },
73
    ];
74
  }
75

76
  public override unistNodeName(): "thematicBreak" {
77
    return "thematicBreak";
62✔
78
  }
79

80
  public override unistNodeToProseMirrorNodes(
81
    _node: ThematicBreak,
82
    proseMirrorSchema: Schema<string, string>,
83
    convertedChildren: Array<ProseMirrorNode>,
84
  ): Array<ProseMirrorNode> {
85
    return createProseMirrorNode(
4✔
86
      this.proseMirrorNodeName(),
87
      proseMirrorSchema,
88
      convertedChildren,
89
    );
90
  }
91
}
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