• 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

84.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";
4✔
5

6
import {
4✔
7
  DefinitionExtension,
8
  type DefinitionExtensionContext,
9
} from "./DefinitionExtension";
10
import { ImageExtension } from "./ImageExtension";
4✔
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> {
4✔
23
  public override dependencies(): Array<Extension> {
24
    return [new DefinitionExtension(), new ImageExtension()];
8✔
25
  }
26

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

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

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

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

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

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