• 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

89.83
/src/syntax-extensions/LinkReferenceExtension.ts
1
import type { LinkReference } from "mdast";
2
import type { Mark, Node as ProseMirrorNode, Schema } from "prosemirror-model";
3

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

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

12
/**
13
 * @public
14
 */
15
export interface LinkReferenceExtensionContext {
16
  marks: Record<string, Mark>;
17
}
18

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

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

56
  public override processConvertedUnistNode(
1✔
57
    convertedNode: LinkReference,
×
58
  ): LinkReference {
×
59
    return convertedNode;
×
60
  }
×
61

62
  public override proseMirrorMarkName(): null {
1✔
63
    return null;
17✔
64
  }
17✔
65

66
  public override proseMirrorMarkSpec(): null {
1✔
67
    return null;
5✔
68
  }
5✔
69

70
  public override unistNodeName(): "linkReference" {
1✔
71
    return "linkReference";
13✔
72
  }
13✔
73

74
  public override unistNodeToProseMirrorNodes(
1✔
75
    node: LinkReference,
7✔
76
    proseMirrorSchema: Schema<string, string>,
7✔
77
    convertedChildren: Array<ProseMirrorNode>,
7✔
78
    context: Partial<{
7✔
79
      LinkReferenceExtension: LinkReferenceExtensionContext;
80
    }>,
81
  ): Array<ProseMirrorNode> {
7✔
82
    const mark = proseMirrorSchema.marks["link"].create({
7✔
83
      href: null,
7✔
84
      title: null,
7✔
85
    });
7✔
86
    context.LinkReferenceExtension ??= { marks: {} };
7✔
87
    context.LinkReferenceExtension.marks[node.identifier] = mark;
7✔
88
    return convertedChildren.map((child) =>
7✔
89
      child.mark(child.marks.concat([mark])),
7✔
90
    );
7✔
91
  }
7✔
92
}
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