• 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

87.32
/src/syntax-extensions/ImageExtension.ts
1
import type { Image } from "mdast";
2
import type {
3
  DOMOutputSpec,
4
  NodeSpec,
5
  Node as ProseMirrorNode,
6
  Schema,
7
} from "prosemirror-model";
8

9
import {
1✔
10
  createProseMirrorNode,
11
  type Extension,
12
  NodeExtension,
13
} from "prosemirror-unified";
14

15
import { ParagraphExtension } from "./ParagraphExtension";
1✔
16

17
/**
18
 * @public
19
 */
20
export class ImageExtension extends NodeExtension<Image> {
1✔
21
  public override dependencies(): Array<Extension> {
1✔
22
    return [new ParagraphExtension()];
10✔
23
  }
10✔
24

25
  public override proseMirrorNodeName(): string {
1✔
26
    return "image";
101✔
27
  }
101✔
28

29
  public override proseMirrorNodeSpec(): NodeSpec {
1✔
30
    return {
6✔
31
      attrs: {
6✔
32
        alt: { default: null },
6✔
33
        src: {},
6✔
34
        title: { default: null },
6✔
35
      },
6✔
36
      draggable: true,
6✔
37
      group: "inline",
6✔
38
      inline: true,
6✔
39
      parseDOM: [
6✔
40
        {
6✔
41
          getAttrs(dom: Node | string): {
6✔
42
            alt: string | null;
43
            src: string | null;
44
            title: string | null;
45
          } {
×
46
            return {
×
47
              alt: (dom as HTMLElement).getAttribute("alt"),
×
48
              src: (dom as HTMLElement).getAttribute("src"),
×
49
              title: (dom as HTMLElement).getAttribute("title"),
×
50
            };
×
51
          },
×
52
          tag: "img[src]",
6✔
53
        },
6✔
54
      ],
6✔
55
      toDOM(node: ProseMirrorNode): DOMOutputSpec {
6✔
56
        return ["img", node.attrs];
×
57
      },
×
58
    };
6✔
59
  }
6✔
60

61
  public override proseMirrorNodeToUnistNodes(
1✔
62
    node: ProseMirrorNode,
6✔
63
  ): Array<Image> {
6✔
64
    return [
6✔
65
      {
6✔
66
        type: this.unistNodeName(),
6✔
67
        url: node.attrs["src"] as string,
6✔
68
        ...(node.attrs["alt"] !== null && { alt: node.attrs["alt"] as string }),
6✔
69
        ...(node.attrs["title"] !== null && {
6✔
70
          title: node.attrs["title"] as string,
1✔
71
        }),
1✔
72
      },
6✔
73
    ];
6✔
74
  }
6✔
75

76
  public override unistNodeName(): "image" {
1✔
77
    return "image";
46✔
78
  }
46✔
79

80
  public override unistNodeToProseMirrorNodes(
1✔
81
    node: Image,
5✔
82
    proseMirrorSchema: Schema<string, string>,
5✔
83
    convertedChildren: Array<ProseMirrorNode>,
5✔
84
  ): Array<ProseMirrorNode> {
5✔
85
    return createProseMirrorNode(
5✔
86
      this.proseMirrorNodeName(),
5✔
87
      proseMirrorSchema,
5✔
88
      convertedChildren,
5✔
89
      {
5✔
90
        alt: node.alt,
5✔
91
        src: node.url,
5✔
92
        title: node.title,
5✔
93
      },
5✔
94
    );
5✔
95
  }
5✔
96
}
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