• 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

90.0
/src/syntax-extensions/ImageReferenceExtension.ts
1
import type { ImageReference } from "mdast";
2
import type { Node as ProseMirrorNode, Schema } from "prosemirror-model";
3

4
import { type Extension, NodeExtension } from "prosemirror-unified";
1✔
5

6
import {
1✔
7
  DefinitionExtension,
8
  type DefinitionExtensionContext,
9
} from "./DefinitionExtension";
10
import { ImageExtension } from "./ImageExtension";
1✔
11

12
/**
13
 * @public
14
 */
15
export interface ImageReferenceExtensionContext {
16
  proseMirrorNodes: Record<string, ProseMirrorNode>;
17
}
18

19
/**
20
 * @public
21
 */
22
export class ImageReferenceExtension extends NodeExtension<ImageReference> {
1✔
23
  public override dependencies(): Array<Extension> {
1✔
24
    return [new DefinitionExtension(), new ImageExtension()];
5✔
25
  }
5✔
26

27
  public override postUnistToProseMirrorHook(
1✔
28
    context: Partial<{
7✔
29
      DefinitionExtension: DefinitionExtensionContext;
30
      ImageReferenceExtension: ImageReferenceExtensionContext;
31
    }>,
32
  ): void {
7✔
33
    if (
7✔
34
      context.ImageReferenceExtension === undefined ||
7✔
35
      context.DefinitionExtension === undefined
7✔
36
    ) {
7✔
37
      return;
1✔
38
    }
1✔
39
    for (const id in context.ImageReferenceExtension.proseMirrorNodes) {
6✔
40
      if (!(id in context.DefinitionExtension.definitions)) {
6!
41
        continue;
×
42
      }
×
43
      const definition = context.DefinitionExtension.definitions[id];
6✔
44
      const attrs = context.ImageReferenceExtension.proseMirrorNodes[id]
6✔
45
        .attrs as Record<
6✔
46
        string,
47
        // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Attrs can be any
48
        any
49
      >;
50
      attrs["src"] = definition.url;
6✔
51
      if (definition.title !== undefined) {
6✔
52
        attrs["title"] = definition.title;
3✔
53
      }
3✔
54
    }
6✔
55
  }
7✔
56

57
  public override proseMirrorNodeName(): null {
1✔
58
    return null;
88✔
59
  }
88✔
60

61
  public override proseMirrorNodeSpec(): null {
1✔
62
    return null;
5✔
63
  }
5✔
64

65
  public override proseMirrorNodeToUnistNodes(): Array<ImageReference> {
1✔
66
    return [];
×
67
  }
×
68

69
  public override unistNodeName(): "imageReference" {
1✔
70
    return "imageReference";
35✔
71
  }
35✔
72

73
  public override unistNodeToProseMirrorNodes(
1✔
74
    node: ImageReference,
7✔
75
    proseMirrorSchema: Schema<string, string>,
7✔
76
    convertedChildren: Array<ProseMirrorNode>,
7✔
77
    context: Partial<{
7✔
78
      ImageReferenceExtension: ImageReferenceExtensionContext;
79
    }>,
80
  ): Array<ProseMirrorNode> {
7✔
81
    const proseMirrorNode = proseMirrorSchema.nodes["image"].createAndFill(
7✔
82
      { alt: node.alt, src: "", title: node.label },
7✔
83
      convertedChildren,
7✔
84
    );
7✔
85
    if (proseMirrorNode === null) {
7!
86
      return [];
×
87
    }
×
88
    context.ImageReferenceExtension ??= { proseMirrorNodes: {} };
7✔
89
    context.ImageReferenceExtension.proseMirrorNodes[node.identifier] =
7✔
90
      proseMirrorNode;
7✔
91
    return [proseMirrorNode];
7✔
92
  }
7✔
93
}
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