mrkdwn.js 4.0.6 → 6.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +85 -66
  2. package/dist/ast/ast.d.cts +1 -1
  3. package/dist/ast/ast.d.ts +1 -1
  4. package/dist/{ast-8XCbjRQT.d.cts → ast-CNfTgS0N.d.cts} +35 -35
  5. package/dist/{ast-8XCbjRQT.d.ts → ast-CNfTgS0N.d.ts} +35 -35
  6. package/dist/block/block.cjs +12 -4
  7. package/dist/block/block.d.cts +9 -5
  8. package/dist/block/block.d.ts +9 -5
  9. package/dist/block/block.js +8 -4
  10. package/dist/block/definitions.d.cts +2 -2
  11. package/dist/block/definitions.d.ts +2 -2
  12. package/dist/block/node.d.cts +4 -4
  13. package/dist/block/node.d.ts +4 -4
  14. package/dist/block/table.d.cts +1 -1
  15. package/dist/block/table.d.ts +1 -1
  16. package/dist/codec.cjs +1 -1
  17. package/dist/codec.d.cts +1631 -29
  18. package/dist/codec.d.ts +1631 -29
  19. package/dist/codec.js +2 -2
  20. package/dist/defaults/defaults.d.cts +1 -1
  21. package/dist/defaults/defaults.d.ts +1 -1
  22. package/dist/diagnostics/diagnostics.cjs +17 -7
  23. package/dist/diagnostics/diagnostics.d.cts +2 -2
  24. package/dist/diagnostics/diagnostics.d.ts +2 -2
  25. package/dist/diagnostics/diagnostics.js +17 -8
  26. package/dist/{diagnostics-BWK1iGy7.d.cts → diagnostics-CjfBoW4K.d.cts} +14 -10
  27. package/dist/{diagnostics-BWK1iGy7.d.ts → diagnostics-CjfBoW4K.d.ts} +14 -10
  28. package/dist/emit/emit.cjs +378 -42
  29. package/dist/emit/emit.js +381 -45
  30. package/dist/emit/front-matter.cjs +22 -5
  31. package/dist/emit/front-matter.js +22 -5
  32. package/dist/emit/html-table.cjs +104 -0
  33. package/dist/emit/html-table.d.cts +7 -0
  34. package/dist/emit/html-table.d.ts +7 -0
  35. package/dist/emit/html-table.js +102 -0
  36. package/dist/emit/inline.cjs +69 -26
  37. package/dist/emit/inline.d.cts +2 -12
  38. package/dist/emit/inline.d.ts +2 -12
  39. package/dist/emit/inline.js +68 -27
  40. package/dist/emit/table.cjs +18 -11
  41. package/dist/emit/table.d.cts +3 -2
  42. package/dist/emit/table.d.ts +3 -2
  43. package/dist/emit/table.js +18 -11
  44. package/dist/html/html-table.cjs +243 -0
  45. package/dist/html/html-table.d.cts +5 -0
  46. package/dist/html/html-table.d.ts +5 -0
  47. package/dist/html/html-table.js +242 -0
  48. package/dist/html/render.d.cts +1 -1
  49. package/dist/html/render.d.ts +1 -1
  50. package/dist/image/image.cjs +4 -4
  51. package/dist/image/image.d.cts +1 -1
  52. package/dist/image/image.d.ts +1 -1
  53. package/dist/image/image.js +4 -4
  54. package/dist/{image-C4KYmz_L.d.cts → image-B5L0HpAJ.d.cts} +1 -1
  55. package/dist/{image-DescdRgq.d.cts → image-BtmTG4_a.d.cts} +1 -1
  56. package/dist/{image-DescdRgq.d.ts → image-BtmTG4_a.d.ts} +1 -1
  57. package/dist/{image-Cm3hT5PS.d.ts → image-C390OIB3.d.ts} +1 -1
  58. package/dist/index.cjs +2 -2
  59. package/dist/index.d.cts +4 -4
  60. package/dist/index.d.ts +4 -4
  61. package/dist/index.js +3 -3
  62. package/dist/inline/delimiter.d.cts +2 -2
  63. package/dist/inline/delimiter.d.ts +2 -2
  64. package/dist/inline/inline.d.cts +1 -1
  65. package/dist/inline/inline.d.ts +1 -1
  66. package/dist/inline/link.d.cts +17 -1
  67. package/dist/inline/link.d.ts +17 -1
  68. package/dist/inline/node.d.cts +2 -2
  69. package/dist/inline/node.d.ts +2 -2
  70. package/dist/{inline-CXVQWQnW.d.cts → inline-CnO86zMw.d.cts} +2 -2
  71. package/dist/inline-DCIKQ83j.d.cts +14 -0
  72. package/dist/{inline-B_V7bs5j.d.ts → inline-DItZ-VVw.d.ts} +2 -2
  73. package/dist/inline-INoDAG37.d.ts +14 -0
  74. package/dist/lower/front-matter.cjs +73 -26
  75. package/dist/lower/front-matter.d.cts +2 -1
  76. package/dist/lower/front-matter.d.ts +2 -1
  77. package/dist/lower/front-matter.js +72 -25
  78. package/dist/lower/image.d.cts +1 -1
  79. package/dist/lower/image.d.ts +1 -1
  80. package/dist/lower/inline.cjs +87 -33
  81. package/dist/lower/inline.d.cts +9 -12
  82. package/dist/lower/inline.d.ts +9 -12
  83. package/dist/lower/inline.js +89 -34
  84. package/dist/lower/lower.cjs +143 -113
  85. package/dist/lower/lower.d.cts +8 -1
  86. package/dist/lower/lower.d.ts +8 -1
  87. package/dist/lower/lower.js +144 -115
  88. package/dist/lower/table.cjs +3 -2
  89. package/dist/lower/table.d.cts +1 -1
  90. package/dist/lower/table.d.ts +1 -1
  91. package/dist/lower/table.js +3 -2
  92. package/dist/options/options.d.cts +10 -10
  93. package/dist/options/options.d.ts +10 -10
  94. package/dist/read.cjs +45 -9
  95. package/dist/read.d.cts +3 -3
  96. package/dist/read.d.ts +3 -3
  97. package/dist/read.js +47 -11
  98. package/dist/scan/entity-table.cjs +2125 -2125
  99. package/dist/scan/entity-table.js +2125 -2125
  100. package/dist/shared/line-ending.cjs +7 -0
  101. package/dist/shared/line-ending.d.cts +5 -0
  102. package/dist/shared/line-ending.d.ts +5 -0
  103. package/dist/shared/line-ending.js +5 -0
  104. package/dist/shared/list-id.cjs +11 -3
  105. package/dist/shared/list-id.d.cts +7 -4
  106. package/dist/shared/list-id.d.ts +7 -4
  107. package/dist/shared/list-id.js +11 -4
  108. package/dist/shared/style-constants.cjs +0 -2
  109. package/dist/shared/style-constants.d.cts +1 -2
  110. package/dist/shared/style-constants.d.ts +1 -2
  111. package/dist/shared/style-constants.js +1 -2
  112. package/dist/write.cjs +33 -6
  113. package/dist/write.d.cts +2 -2
  114. package/dist/write.d.ts +2 -2
  115. package/dist/write.js +34 -7
  116. package/package.json +29 -30
  117. package/dist/link-Dv4kxVjk.d.cts +0 -18
  118. package/dist/link-Dv4kxVjk.d.ts +0 -18
@@ -12,7 +12,7 @@ function buildRun(text, style, fontFamily) {
12
12
  ...fontFamily !== void 0 ? { fontFamily } : {}
13
13
  };
14
14
  }
15
- function lowerNestedEmphasisLike(kind, node, style, context) {
15
+ function lowerNestedEmphasisLike(kind, node, style, context, runs, extents) {
16
16
  if (style[kind] === true) context.sink({
17
17
  code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.NESTED_EMPHASIS_FLATTENED,
18
18
  severity: "info",
@@ -22,15 +22,31 @@ function lowerNestedEmphasisLike(kind, node, style, context) {
22
22
  ...style,
23
23
  [kind]: true
24
24
  };
25
- return node.children.flatMap((child) => lowerInlineNode(child, childStyle, context));
25
+ lowerNodesInto(node.children, childStyle, context, runs, extents);
26
26
  }
27
- function lowerInlineNode(node, style, context) {
27
+ function lowerInlineNodeInto(node, style, context, runs, extents) {
28
28
  switch (node.type) {
29
- case "text": return node.value.length === 0 ? [] : [buildRun(node.value, style)];
30
- case "entity": return node.value.length === 0 ? [] : [buildRun(node.value, style)];
31
- case "softBreak": return [buildRun(" ", style)];
32
- case "hardBreak": return [buildRun("\n", style)];
33
- case "codeSpan": return [buildRun(node.literal, style, require_shared_style_constants.MONOSPACE_FONT_FAMILY)];
29
+ case "text":
30
+ if (node.value.length > 0) runs.push(buildRun(node.value, style));
31
+ return;
32
+ case "entity":
33
+ if (node.value.length > 0) runs.push(buildRun(node.value, style));
34
+ return;
35
+ case "softBreak":
36
+ runs.push({
37
+ ...buildRun(" ", style),
38
+ source: {
39
+ format: "markdown",
40
+ xml: "\n"
41
+ }
42
+ });
43
+ return;
44
+ case "hardBreak":
45
+ runs.push(buildRun("\n", style));
46
+ return;
47
+ case "codeSpan":
48
+ runs.push(buildRun(node.literal, style, require_shared_style_constants.MONOSPACE_FONT_FAMILY));
49
+ return;
34
50
  case "rawHtml":
35
51
  if (context.rawHtml === "drop") {
36
52
  context.sink({
@@ -38,47 +54,70 @@ function lowerInlineNode(node, style, context) {
38
54
  severity: "info",
39
55
  message: "inline raw HTML was dropped per the rawHtml: \"drop\" option"
40
56
  });
41
- return [];
57
+ return;
42
58
  }
43
59
  context.sink({
44
60
  code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.RAW_HTML_PRESERVED_AS_TEXT,
45
61
  severity: "info",
46
- message: "inline raw HTML was preserved as literal text; it will not be rendered as HTML by any consumer of the resulting ContentDocument"
62
+ message: "inline raw HTML was preserved as literal text; it will not be rendered as HTML by any consumer of the resulting ContentDocument, and its verbatim original rides the run's own markdown residue for this package's writer to re-emit as-is"
63
+ });
64
+ if (node.literal.length > 0) runs.push({
65
+ ...buildRun(node.literal, style),
66
+ source: {
67
+ format: "markdown",
68
+ xml: node.literal
69
+ }
47
70
  });
48
- return node.literal.length === 0 ? [] : [buildRun(node.literal, style)];
71
+ return;
49
72
  case "mathInline":
50
73
  context.sink({
51
74
  code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.MATH_INLINE_PRESERVED_AS_TEXT,
52
75
  severity: "info",
53
76
  message: "inline math (\\( \\)) was preserved as literal raw LaTeX text; it is not parsed as LaTeX or converted to MathML by this package"
54
77
  });
55
- return [buildRun(node.literal, style, require_shared_style_constants.MATH_INLINE_FONT_MARKER)];
78
+ runs.push(buildRun(node.literal, style, require_shared_style_constants.MATH_INLINE_FONT_MARKER));
79
+ return;
56
80
  case "footnoteReference":
57
- context.sink({
58
- code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.FOOTNOTE_REFERENCE_PRESERVED_AS_TEXT,
59
- severity: "info",
60
- message: `footnote reference "[^${node.label}]" is preserved as a marked text run rather than an anchor construct: a construct's extent is block-scoped, and a reference site sits between two runs inside a paragraph, which no block-level boundary marker can bracket`
81
+ runs.push(buildRun(`[^${node.label}]`, style));
82
+ extents.push({
83
+ descriptor: {
84
+ kind: "anchor",
85
+ anchorType: "footnote",
86
+ name: node.label
87
+ },
88
+ startRun: runs.length - 1,
89
+ endRun: runs.length - 1
61
90
  });
62
- return [buildRun(`[^${node.label}]`, style, require_shared_style_constants.FOOTNOTE_REFERENCE_FONT_MARKER)];
91
+ return;
63
92
  case "autolink": {
64
93
  const destination = node.email ? `mailto:${node.destination}` : node.destination;
65
- return [buildRun(node.destination, {
94
+ runs.push(buildRun(node.destination, {
66
95
  ...style,
67
96
  hyperlink: destination
68
- })];
97
+ }));
98
+ return;
69
99
  }
70
100
  case "link": {
71
- if (node.title !== void 0) context.sink({
72
- code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.LINK_TITLE_DROPPED,
73
- severity: "info",
74
- message: `link title "${node.title}" has no ContentRun equivalent and was dropped`
75
- });
76
101
  const childStyle = {
77
102
  ...style,
78
103
  hyperlink: node.destination
79
104
  };
80
- const runs = node.children.flatMap((child) => lowerInlineNode(child, childStyle, context));
81
- return runs.length > 0 ? runs : [buildRun("", childStyle)];
105
+ const startRun = runs.length;
106
+ lowerNodesInto(node.children, childStyle, context, runs, extents);
107
+ if (runs.length === startRun) runs.push(buildRun("", childStyle));
108
+ if (node.title !== void 0) extents.push({
109
+ descriptor: {
110
+ kind: "link",
111
+ target: {
112
+ kind: "external",
113
+ uri: node.destination
114
+ },
115
+ title: node.title
116
+ },
117
+ startRun,
118
+ endRun: runs.length
119
+ });
120
+ return;
82
121
  }
83
122
  case "image":
84
123
  if (node.title !== void 0) context.sink({
@@ -86,17 +125,33 @@ function lowerInlineNode(node, style, context) {
86
125
  severity: "info",
87
126
  message: `image title "${node.title}" has no ContentRun equivalent and was dropped`
88
127
  });
89
- return [buildRun(node.alt, {
128
+ runs.push(buildRun(node.alt, {
90
129
  ...style,
91
130
  hyperlink: node.destination
92
- })];
93
- case "emphasis": return lowerNestedEmphasisLike("italic", node, style, context);
94
- case "strong": return lowerNestedEmphasisLike("bold", node, style, context);
95
- case "strikethrough": return lowerNestedEmphasisLike("strike", node, style, context);
131
+ }));
132
+ return;
133
+ case "emphasis":
134
+ lowerNestedEmphasisLike("italic", node, style, context, runs, extents);
135
+ return;
136
+ case "strong":
137
+ lowerNestedEmphasisLike("bold", node, style, context, runs, extents);
138
+ return;
139
+ case "strikethrough":
140
+ lowerNestedEmphasisLike("strike", node, style, context, runs, extents);
141
+ return;
96
142
  }
97
143
  }
144
+ function lowerNodesInto(nodes, style, context, runs, extents) {
145
+ for (const node of nodes) lowerInlineNodeInto(node, style, context, runs, extents);
146
+ }
98
147
  function lowerInlineNodes(nodes, context) {
99
- return nodes.flatMap((node) => lowerInlineNode(node, {}, context));
148
+ const runs = [];
149
+ const extents = [];
150
+ lowerNodesInto(nodes, {}, context, runs, extents);
151
+ return {
152
+ runs,
153
+ runConstructExtents: extents
154
+ };
100
155
  }
101
156
  function lowerCodeBlockRun(literal) {
102
157
  return {
@@ -106,5 +161,4 @@ function lowerCodeBlockRun(literal) {
106
161
  }
107
162
  //#endregion
108
163
  exports.lowerCodeBlockRun = lowerCodeBlockRun;
109
- exports.lowerInlineNode = lowerInlineNode;
110
164
  exports.lowerInlineNodes = lowerInlineNodes;
@@ -1,19 +1,16 @@
1
- import { v as MarkdownInlineNode } from "../ast-8XCbjRQT.cjs";
2
- import { i as MarkdownDiagnosticSink } from "../diagnostics-BWK1iGy7.cjs";
3
- import { ContentRun } from "document-schema.js";
1
+ import { v as MarkdownInlineNode } from "../ast-CNfTgS0N.cjs";
2
+ import { i as MarkdownDiagnosticSink } from "../diagnostics-CjfBoW4K.cjs";
3
+ import { ContentRun, RunConstructExtent } from "document-schema.js";
4
4
  //#region src/lower/inline.d.ts
5
5
  interface InlineLowerContext {
6
6
  readonly sink: MarkdownDiagnosticSink;
7
- readonly rawHtml: 'preserve' | 'drop';
7
+ readonly rawHtml: "preserve" | "drop";
8
8
  }
9
- interface RunStyle {
10
- readonly bold?: boolean;
11
- readonly italic?: boolean;
12
- readonly strike?: boolean;
13
- readonly hyperlink?: string;
9
+ interface InlineLowerResult {
10
+ readonly runs: ContentRun[];
11
+ readonly runConstructExtents: readonly RunConstructExtent[];
14
12
  }
15
- declare function lowerInlineNode(node: MarkdownInlineNode, style: RunStyle, context: InlineLowerContext): ContentRun[];
16
- declare function lowerInlineNodes(nodes: readonly MarkdownInlineNode[], context: InlineLowerContext): ContentRun[];
13
+ declare function lowerInlineNodes(nodes: readonly MarkdownInlineNode[], context: InlineLowerContext): InlineLowerResult;
17
14
  declare function lowerCodeBlockRun(literal: string): ContentRun;
18
15
  //#endregion
19
- export { InlineLowerContext, lowerCodeBlockRun, lowerInlineNode, lowerInlineNodes };
16
+ export { InlineLowerContext, InlineLowerResult, lowerCodeBlockRun, lowerInlineNodes };
@@ -1,19 +1,16 @@
1
- import { v as MarkdownInlineNode } from "../ast-8XCbjRQT.js";
2
- import { i as MarkdownDiagnosticSink } from "../diagnostics-BWK1iGy7.js";
3
- import { ContentRun } from "document-schema.js";
1
+ import { v as MarkdownInlineNode } from "../ast-CNfTgS0N.js";
2
+ import { i as MarkdownDiagnosticSink } from "../diagnostics-CjfBoW4K.js";
3
+ import { ContentRun, RunConstructExtent } from "document-schema.js";
4
4
  //#region src/lower/inline.d.ts
5
5
  interface InlineLowerContext {
6
6
  readonly sink: MarkdownDiagnosticSink;
7
- readonly rawHtml: 'preserve' | 'drop';
7
+ readonly rawHtml: "preserve" | "drop";
8
8
  }
9
- interface RunStyle {
10
- readonly bold?: boolean;
11
- readonly italic?: boolean;
12
- readonly strike?: boolean;
13
- readonly hyperlink?: string;
9
+ interface InlineLowerResult {
10
+ readonly runs: ContentRun[];
11
+ readonly runConstructExtents: readonly RunConstructExtent[];
14
12
  }
15
- declare function lowerInlineNode(node: MarkdownInlineNode, style: RunStyle, context: InlineLowerContext): ContentRun[];
16
- declare function lowerInlineNodes(nodes: readonly MarkdownInlineNode[], context: InlineLowerContext): ContentRun[];
13
+ declare function lowerInlineNodes(nodes: readonly MarkdownInlineNode[], context: InlineLowerContext): InlineLowerResult;
17
14
  declare function lowerCodeBlockRun(literal: string): ContentRun;
18
15
  //#endregion
19
- export { InlineLowerContext, lowerCodeBlockRun, lowerInlineNode, lowerInlineNodes };
16
+ export { InlineLowerContext, InlineLowerResult, lowerCodeBlockRun, lowerInlineNodes };
@@ -1,5 +1,5 @@
1
1
  import { MarkdownDiagnosticCodes } from "../diagnostics/diagnostics.js";
2
- import { FOOTNOTE_REFERENCE_FONT_MARKER, MATH_INLINE_FONT_MARKER, MONOSPACE_FONT_FAMILY } from "../shared/style-constants.js";
2
+ import { MATH_INLINE_FONT_MARKER, MONOSPACE_FONT_FAMILY } from "../shared/style-constants.js";
3
3
  //#region src/lower/inline.ts
4
4
  function buildRun(text, style, fontFamily) {
5
5
  return {
@@ -11,7 +11,7 @@ function buildRun(text, style, fontFamily) {
11
11
  ...fontFamily !== void 0 ? { fontFamily } : {}
12
12
  };
13
13
  }
14
- function lowerNestedEmphasisLike(kind, node, style, context) {
14
+ function lowerNestedEmphasisLike(kind, node, style, context, runs, extents) {
15
15
  if (style[kind] === true) context.sink({
16
16
  code: MarkdownDiagnosticCodes.NESTED_EMPHASIS_FLATTENED,
17
17
  severity: "info",
@@ -21,15 +21,31 @@ function lowerNestedEmphasisLike(kind, node, style, context) {
21
21
  ...style,
22
22
  [kind]: true
23
23
  };
24
- return node.children.flatMap((child) => lowerInlineNode(child, childStyle, context));
24
+ lowerNodesInto(node.children, childStyle, context, runs, extents);
25
25
  }
26
- function lowerInlineNode(node, style, context) {
26
+ function lowerInlineNodeInto(node, style, context, runs, extents) {
27
27
  switch (node.type) {
28
- case "text": return node.value.length === 0 ? [] : [buildRun(node.value, style)];
29
- case "entity": return node.value.length === 0 ? [] : [buildRun(node.value, style)];
30
- case "softBreak": return [buildRun(" ", style)];
31
- case "hardBreak": return [buildRun("\n", style)];
32
- case "codeSpan": return [buildRun(node.literal, style, MONOSPACE_FONT_FAMILY)];
28
+ case "text":
29
+ if (node.value.length > 0) runs.push(buildRun(node.value, style));
30
+ return;
31
+ case "entity":
32
+ if (node.value.length > 0) runs.push(buildRun(node.value, style));
33
+ return;
34
+ case "softBreak":
35
+ runs.push({
36
+ ...buildRun(" ", style),
37
+ source: {
38
+ format: "markdown",
39
+ xml: "\n"
40
+ }
41
+ });
42
+ return;
43
+ case "hardBreak":
44
+ runs.push(buildRun("\n", style));
45
+ return;
46
+ case "codeSpan":
47
+ runs.push(buildRun(node.literal, style, MONOSPACE_FONT_FAMILY));
48
+ return;
33
49
  case "rawHtml":
34
50
  if (context.rawHtml === "drop") {
35
51
  context.sink({
@@ -37,47 +53,70 @@ function lowerInlineNode(node, style, context) {
37
53
  severity: "info",
38
54
  message: "inline raw HTML was dropped per the rawHtml: \"drop\" option"
39
55
  });
40
- return [];
56
+ return;
41
57
  }
42
58
  context.sink({
43
59
  code: MarkdownDiagnosticCodes.RAW_HTML_PRESERVED_AS_TEXT,
44
60
  severity: "info",
45
- message: "inline raw HTML was preserved as literal text; it will not be rendered as HTML by any consumer of the resulting ContentDocument"
61
+ message: "inline raw HTML was preserved as literal text; it will not be rendered as HTML by any consumer of the resulting ContentDocument, and its verbatim original rides the run's own markdown residue for this package's writer to re-emit as-is"
62
+ });
63
+ if (node.literal.length > 0) runs.push({
64
+ ...buildRun(node.literal, style),
65
+ source: {
66
+ format: "markdown",
67
+ xml: node.literal
68
+ }
46
69
  });
47
- return node.literal.length === 0 ? [] : [buildRun(node.literal, style)];
70
+ return;
48
71
  case "mathInline":
49
72
  context.sink({
50
73
  code: MarkdownDiagnosticCodes.MATH_INLINE_PRESERVED_AS_TEXT,
51
74
  severity: "info",
52
75
  message: "inline math (\\( \\)) was preserved as literal raw LaTeX text; it is not parsed as LaTeX or converted to MathML by this package"
53
76
  });
54
- return [buildRun(node.literal, style, MATH_INLINE_FONT_MARKER)];
77
+ runs.push(buildRun(node.literal, style, MATH_INLINE_FONT_MARKER));
78
+ return;
55
79
  case "footnoteReference":
56
- context.sink({
57
- code: MarkdownDiagnosticCodes.FOOTNOTE_REFERENCE_PRESERVED_AS_TEXT,
58
- severity: "info",
59
- message: `footnote reference "[^${node.label}]" is preserved as a marked text run rather than an anchor construct: a construct's extent is block-scoped, and a reference site sits between two runs inside a paragraph, which no block-level boundary marker can bracket`
80
+ runs.push(buildRun(`[^${node.label}]`, style));
81
+ extents.push({
82
+ descriptor: {
83
+ kind: "anchor",
84
+ anchorType: "footnote",
85
+ name: node.label
86
+ },
87
+ startRun: runs.length - 1,
88
+ endRun: runs.length - 1
60
89
  });
61
- return [buildRun(`[^${node.label}]`, style, FOOTNOTE_REFERENCE_FONT_MARKER)];
90
+ return;
62
91
  case "autolink": {
63
92
  const destination = node.email ? `mailto:${node.destination}` : node.destination;
64
- return [buildRun(node.destination, {
93
+ runs.push(buildRun(node.destination, {
65
94
  ...style,
66
95
  hyperlink: destination
67
- })];
96
+ }));
97
+ return;
68
98
  }
69
99
  case "link": {
70
- if (node.title !== void 0) context.sink({
71
- code: MarkdownDiagnosticCodes.LINK_TITLE_DROPPED,
72
- severity: "info",
73
- message: `link title "${node.title}" has no ContentRun equivalent and was dropped`
74
- });
75
100
  const childStyle = {
76
101
  ...style,
77
102
  hyperlink: node.destination
78
103
  };
79
- const runs = node.children.flatMap((child) => lowerInlineNode(child, childStyle, context));
80
- return runs.length > 0 ? runs : [buildRun("", childStyle)];
104
+ const startRun = runs.length;
105
+ lowerNodesInto(node.children, childStyle, context, runs, extents);
106
+ if (runs.length === startRun) runs.push(buildRun("", childStyle));
107
+ if (node.title !== void 0) extents.push({
108
+ descriptor: {
109
+ kind: "link",
110
+ target: {
111
+ kind: "external",
112
+ uri: node.destination
113
+ },
114
+ title: node.title
115
+ },
116
+ startRun,
117
+ endRun: runs.length
118
+ });
119
+ return;
81
120
  }
82
121
  case "image":
83
122
  if (node.title !== void 0) context.sink({
@@ -85,17 +124,33 @@ function lowerInlineNode(node, style, context) {
85
124
  severity: "info",
86
125
  message: `image title "${node.title}" has no ContentRun equivalent and was dropped`
87
126
  });
88
- return [buildRun(node.alt, {
127
+ runs.push(buildRun(node.alt, {
89
128
  ...style,
90
129
  hyperlink: node.destination
91
- })];
92
- case "emphasis": return lowerNestedEmphasisLike("italic", node, style, context);
93
- case "strong": return lowerNestedEmphasisLike("bold", node, style, context);
94
- case "strikethrough": return lowerNestedEmphasisLike("strike", node, style, context);
130
+ }));
131
+ return;
132
+ case "emphasis":
133
+ lowerNestedEmphasisLike("italic", node, style, context, runs, extents);
134
+ return;
135
+ case "strong":
136
+ lowerNestedEmphasisLike("bold", node, style, context, runs, extents);
137
+ return;
138
+ case "strikethrough":
139
+ lowerNestedEmphasisLike("strike", node, style, context, runs, extents);
140
+ return;
95
141
  }
96
142
  }
143
+ function lowerNodesInto(nodes, style, context, runs, extents) {
144
+ for (const node of nodes) lowerInlineNodeInto(node, style, context, runs, extents);
145
+ }
97
146
  function lowerInlineNodes(nodes, context) {
98
- return nodes.flatMap((node) => lowerInlineNode(node, {}, context));
147
+ const runs = [];
148
+ const extents = [];
149
+ lowerNodesInto(nodes, {}, context, runs, extents);
150
+ return {
151
+ runs,
152
+ runConstructExtents: extents
153
+ };
99
154
  }
100
155
  function lowerCodeBlockRun(literal) {
101
156
  return {
@@ -104,4 +159,4 @@ function lowerCodeBlockRun(literal) {
104
159
  };
105
160
  }
106
161
  //#endregion
107
- export { lowerCodeBlockRun, lowerInlineNode, lowerInlineNodes };
162
+ export { lowerCodeBlockRun, lowerInlineNodes };