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
@@ -0,0 +1,7 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/shared/line-ending.ts
3
+ const LINE_ENDING_PATTERN = /\r\n|\n|\r/;
4
+ const ESCAPED_HARD_BREAK_PATTERN = new RegExp(`\\\\(?:${LINE_ENDING_PATTERN.source})`, "g");
5
+ //#endregion
6
+ exports.ESCAPED_HARD_BREAK_PATTERN = ESCAPED_HARD_BREAK_PATTERN;
7
+ exports.LINE_ENDING_PATTERN = LINE_ENDING_PATTERN;
@@ -0,0 +1,5 @@
1
+ //#region src/shared/line-ending.d.ts
2
+ declare const LINE_ENDING_PATTERN: RegExp;
3
+ declare const ESCAPED_HARD_BREAK_PATTERN: RegExp;
4
+ //#endregion
5
+ export { ESCAPED_HARD_BREAK_PATTERN, LINE_ENDING_PATTERN };
@@ -0,0 +1,5 @@
1
+ //#region src/shared/line-ending.d.ts
2
+ declare const LINE_ENDING_PATTERN: RegExp;
3
+ declare const ESCAPED_HARD_BREAK_PATTERN: RegExp;
4
+ //#endregion
5
+ export { ESCAPED_HARD_BREAK_PATTERN, LINE_ENDING_PATTERN };
@@ -0,0 +1,5 @@
1
+ //#region src/shared/line-ending.ts
2
+ const LINE_ENDING_PATTERN = /\r\n|\n|\r/;
3
+ const ESCAPED_HARD_BREAK_PATTERN = new RegExp(`\\\\(?:${LINE_ENDING_PATTERN.source})`, "g");
4
+ //#endregion
5
+ export { ESCAPED_HARD_BREAK_PATTERN, LINE_ENDING_PATTERN };
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region src/shared/list-id.ts
3
- const NUMID_PATTERN = /^md(\d+):(bullet|ordered)(?:@(\d+))?(\+task)?(\+loose)?$/;
3
+ const NUMID_PATTERN = /^md(\d+):(bullet|ordered)(?:@(\d+))?(\+task)?(\+loose)?(?:\+owner=(md-i\d+))?$/;
4
4
  const DEFAULT_ORDERED_START = 1;
5
5
  function createNumIdMintState() {
6
6
  return { next: 1 };
@@ -11,7 +11,8 @@ function mintListNumId(state, options) {
11
11
  const startSuffix = options.type === "ordered" && options.start !== void 0 && options.start !== DEFAULT_ORDERED_START ? `@${String(options.start)}` : "";
12
12
  const taskSuffix = options.task ? "+task" : "";
13
13
  const looseSuffix = options.loose ? "+loose" : "";
14
- return `md${String(id)}:${options.type}${startSuffix}${taskSuffix}${looseSuffix}`;
14
+ const ownerSuffix = options.ownerItemId !== void 0 ? `+owner=${options.ownerItemId}` : "";
15
+ return `md${String(id)}:${options.type}${startSuffix}${taskSuffix}${looseSuffix}${ownerSuffix}`;
15
16
  }
16
17
  function parseListNumId(numId) {
17
18
  const match = NUMID_PATTERN.exec(numId);
@@ -23,14 +24,21 @@ function parseListNumId(numId) {
23
24
  type,
24
25
  start: type === "ordered" && startText !== void 0 ? Number.parseInt(startText, 10) : void 0,
25
26
  task: match[4] !== void 0,
26
- loose: match[5] !== void 0
27
+ loose: match[5] !== void 0,
28
+ ownerItemId: match[6]
27
29
  };
28
30
  }
29
31
  function mintedListType(numId) {
30
32
  return parseListNumId(numId)?.type;
31
33
  }
34
+ function mintListItemId(state) {
35
+ const id = state.next;
36
+ state.next += 1;
37
+ return `md-i${String(id)}`;
38
+ }
32
39
  //#endregion
33
40
  exports.createNumIdMintState = createNumIdMintState;
41
+ exports.mintListItemId = mintListItemId;
34
42
  exports.mintListNumId = mintListNumId;
35
43
  exports.mintedListType = mintedListType;
36
44
  exports.parseListNumId = parseListNumId;
@@ -1,15 +1,17 @@
1
1
  //#region src/shared/list-id.d.ts
2
2
  interface ListNumIdInfo {
3
- readonly type: 'bullet' | 'ordered';
3
+ readonly type: "bullet" | "ordered";
4
4
  readonly start?: number;
5
5
  readonly task: boolean;
6
6
  readonly loose: boolean;
7
+ readonly ownerItemId?: string;
7
8
  }
8
9
  interface ListNumIdMintOptions {
9
- readonly type: 'bullet' | 'ordered';
10
+ readonly type: "bullet" | "ordered";
10
11
  readonly start?: number;
11
12
  readonly task: boolean;
12
13
  readonly loose: boolean;
14
+ readonly ownerItemId?: string;
13
15
  }
14
16
  interface NumIdMintState {
15
17
  next: number;
@@ -17,6 +19,7 @@ interface NumIdMintState {
17
19
  declare function createNumIdMintState(): NumIdMintState;
18
20
  declare function mintListNumId(state: NumIdMintState, options: ListNumIdMintOptions): string;
19
21
  declare function parseListNumId(numId: string): ListNumIdInfo | undefined;
20
- declare function mintedListType(numId: string): 'bullet' | 'ordered' | undefined;
22
+ declare function mintedListType(numId: string): "bullet" | "ordered" | undefined;
23
+ declare function mintListItemId(state: NumIdMintState): string;
21
24
  //#endregion
22
- export { ListNumIdInfo, ListNumIdMintOptions, NumIdMintState, createNumIdMintState, mintListNumId, mintedListType, parseListNumId };
25
+ export { ListNumIdInfo, ListNumIdMintOptions, NumIdMintState, createNumIdMintState, mintListItemId, mintListNumId, mintedListType, parseListNumId };
@@ -1,15 +1,17 @@
1
1
  //#region src/shared/list-id.d.ts
2
2
  interface ListNumIdInfo {
3
- readonly type: 'bullet' | 'ordered';
3
+ readonly type: "bullet" | "ordered";
4
4
  readonly start?: number;
5
5
  readonly task: boolean;
6
6
  readonly loose: boolean;
7
+ readonly ownerItemId?: string;
7
8
  }
8
9
  interface ListNumIdMintOptions {
9
- readonly type: 'bullet' | 'ordered';
10
+ readonly type: "bullet" | "ordered";
10
11
  readonly start?: number;
11
12
  readonly task: boolean;
12
13
  readonly loose: boolean;
14
+ readonly ownerItemId?: string;
13
15
  }
14
16
  interface NumIdMintState {
15
17
  next: number;
@@ -17,6 +19,7 @@ interface NumIdMintState {
17
19
  declare function createNumIdMintState(): NumIdMintState;
18
20
  declare function mintListNumId(state: NumIdMintState, options: ListNumIdMintOptions): string;
19
21
  declare function parseListNumId(numId: string): ListNumIdInfo | undefined;
20
- declare function mintedListType(numId: string): 'bullet' | 'ordered' | undefined;
22
+ declare function mintedListType(numId: string): "bullet" | "ordered" | undefined;
23
+ declare function mintListItemId(state: NumIdMintState): string;
21
24
  //#endregion
22
- export { ListNumIdInfo, ListNumIdMintOptions, NumIdMintState, createNumIdMintState, mintListNumId, mintedListType, parseListNumId };
25
+ export { ListNumIdInfo, ListNumIdMintOptions, NumIdMintState, createNumIdMintState, mintListItemId, mintListNumId, mintedListType, parseListNumId };
@@ -1,5 +1,5 @@
1
1
  //#region src/shared/list-id.ts
2
- const NUMID_PATTERN = /^md(\d+):(bullet|ordered)(?:@(\d+))?(\+task)?(\+loose)?$/;
2
+ const NUMID_PATTERN = /^md(\d+):(bullet|ordered)(?:@(\d+))?(\+task)?(\+loose)?(?:\+owner=(md-i\d+))?$/;
3
3
  const DEFAULT_ORDERED_START = 1;
4
4
  function createNumIdMintState() {
5
5
  return { next: 1 };
@@ -10,7 +10,8 @@ function mintListNumId(state, options) {
10
10
  const startSuffix = options.type === "ordered" && options.start !== void 0 && options.start !== DEFAULT_ORDERED_START ? `@${String(options.start)}` : "";
11
11
  const taskSuffix = options.task ? "+task" : "";
12
12
  const looseSuffix = options.loose ? "+loose" : "";
13
- return `md${String(id)}:${options.type}${startSuffix}${taskSuffix}${looseSuffix}`;
13
+ const ownerSuffix = options.ownerItemId !== void 0 ? `+owner=${options.ownerItemId}` : "";
14
+ return `md${String(id)}:${options.type}${startSuffix}${taskSuffix}${looseSuffix}${ownerSuffix}`;
14
15
  }
15
16
  function parseListNumId(numId) {
16
17
  const match = NUMID_PATTERN.exec(numId);
@@ -22,11 +23,17 @@ function parseListNumId(numId) {
22
23
  type,
23
24
  start: type === "ordered" && startText !== void 0 ? Number.parseInt(startText, 10) : void 0,
24
25
  task: match[4] !== void 0,
25
- loose: match[5] !== void 0
26
+ loose: match[5] !== void 0,
27
+ ownerItemId: match[6]
26
28
  };
27
29
  }
28
30
  function mintedListType(numId) {
29
31
  return parseListNumId(numId)?.type;
30
32
  }
33
+ function mintListItemId(state) {
34
+ const id = state.next;
35
+ state.next += 1;
36
+ return `md-i${String(id)}`;
37
+ }
31
38
  //#endregion
32
- export { createNumIdMintState, mintListNumId, mintedListType, parseListNumId };
39
+ export { createNumIdMintState, mintListItemId, mintListNumId, mintedListType, parseListNumId };
@@ -19,13 +19,11 @@ const HTML_PREFORMATTED_STYLE_ID = "HTMLPreformatted";
19
19
  const MATH_BLOCK_STYLE_ID = "MathBlock";
20
20
  const MONOSPACE_FONT_FAMILY = "Courier New";
21
21
  const MATH_INLINE_FONT_MARKER = "Cambria Math";
22
- const FOOTNOTE_REFERENCE_FONT_MARKER = "Footnote Reference";
23
22
  const QUOTE_INDENT_PT = 36;
24
23
  const TASK_CHECKBOX_UNCHECKED = "☐";
25
24
  const TASK_CHECKBOX_CHECKED = "☒";
26
25
  //#endregion
27
26
  exports.CODE_BLOCK_STYLE_ID = CODE_BLOCK_STYLE_ID;
28
- exports.FOOTNOTE_REFERENCE_FONT_MARKER = FOOTNOTE_REFERENCE_FONT_MARKER;
29
27
  exports.HORIZONTAL_RULE_STYLE_ID = HORIZONTAL_RULE_STYLE_ID;
30
28
  exports.HTML_PREFORMATTED_STYLE_ID = HTML_PREFORMATTED_STYLE_ID;
31
29
  exports.MATH_BLOCK_STYLE_ID = MATH_BLOCK_STYLE_ID;
@@ -9,9 +9,8 @@ declare const HTML_PREFORMATTED_STYLE_ID = "HTMLPreformatted";
9
9
  declare const MATH_BLOCK_STYLE_ID = "MathBlock";
10
10
  declare const MONOSPACE_FONT_FAMILY = "Courier New";
11
11
  declare const MATH_INLINE_FONT_MARKER = "Cambria Math";
12
- declare const FOOTNOTE_REFERENCE_FONT_MARKER = "Footnote Reference";
13
12
  declare const QUOTE_INDENT_PT = 36;
14
13
  declare const TASK_CHECKBOX_UNCHECKED = "☐";
15
14
  declare const TASK_CHECKBOX_CHECKED = "☒";
16
15
  //#endregion
17
- export { CODE_BLOCK_STYLE_ID, FOOTNOTE_REFERENCE_FONT_MARKER, HORIZONTAL_RULE_STYLE_ID, HTML_PREFORMATTED_STYLE_ID, MATH_BLOCK_STYLE_ID, MATH_INLINE_FONT_MARKER, MAX_HEADING_STYLE_LEVEL, MONOSPACE_FONT_FAMILY, QUOTE_INDENT_PT, QUOTE_STYLE_ID, TASK_CHECKBOX_CHECKED, TASK_CHECKBOX_UNCHECKED, headingStyleId, parseHeadingStyleId };
16
+ export { CODE_BLOCK_STYLE_ID, HORIZONTAL_RULE_STYLE_ID, HTML_PREFORMATTED_STYLE_ID, MATH_BLOCK_STYLE_ID, MATH_INLINE_FONT_MARKER, MAX_HEADING_STYLE_LEVEL, MONOSPACE_FONT_FAMILY, QUOTE_INDENT_PT, QUOTE_STYLE_ID, TASK_CHECKBOX_CHECKED, TASK_CHECKBOX_UNCHECKED, headingStyleId, parseHeadingStyleId };
@@ -9,9 +9,8 @@ declare const HTML_PREFORMATTED_STYLE_ID = "HTMLPreformatted";
9
9
  declare const MATH_BLOCK_STYLE_ID = "MathBlock";
10
10
  declare const MONOSPACE_FONT_FAMILY = "Courier New";
11
11
  declare const MATH_INLINE_FONT_MARKER = "Cambria Math";
12
- declare const FOOTNOTE_REFERENCE_FONT_MARKER = "Footnote Reference";
13
12
  declare const QUOTE_INDENT_PT = 36;
14
13
  declare const TASK_CHECKBOX_UNCHECKED = "☐";
15
14
  declare const TASK_CHECKBOX_CHECKED = "☒";
16
15
  //#endregion
17
- export { CODE_BLOCK_STYLE_ID, FOOTNOTE_REFERENCE_FONT_MARKER, HORIZONTAL_RULE_STYLE_ID, HTML_PREFORMATTED_STYLE_ID, MATH_BLOCK_STYLE_ID, MATH_INLINE_FONT_MARKER, MAX_HEADING_STYLE_LEVEL, MONOSPACE_FONT_FAMILY, QUOTE_INDENT_PT, QUOTE_STYLE_ID, TASK_CHECKBOX_CHECKED, TASK_CHECKBOX_UNCHECKED, headingStyleId, parseHeadingStyleId };
16
+ export { CODE_BLOCK_STYLE_ID, HORIZONTAL_RULE_STYLE_ID, HTML_PREFORMATTED_STYLE_ID, MATH_BLOCK_STYLE_ID, MATH_INLINE_FONT_MARKER, MAX_HEADING_STYLE_LEVEL, MONOSPACE_FONT_FAMILY, QUOTE_INDENT_PT, QUOTE_STYLE_ID, TASK_CHECKBOX_CHECKED, TASK_CHECKBOX_UNCHECKED, headingStyleId, parseHeadingStyleId };
@@ -18,9 +18,8 @@ const HTML_PREFORMATTED_STYLE_ID = "HTMLPreformatted";
18
18
  const MATH_BLOCK_STYLE_ID = "MathBlock";
19
19
  const MONOSPACE_FONT_FAMILY = "Courier New";
20
20
  const MATH_INLINE_FONT_MARKER = "Cambria Math";
21
- const FOOTNOTE_REFERENCE_FONT_MARKER = "Footnote Reference";
22
21
  const QUOTE_INDENT_PT = 36;
23
22
  const TASK_CHECKBOX_UNCHECKED = "☐";
24
23
  const TASK_CHECKBOX_CHECKED = "☒";
25
24
  //#endregion
26
- export { CODE_BLOCK_STYLE_ID, FOOTNOTE_REFERENCE_FONT_MARKER, HORIZONTAL_RULE_STYLE_ID, HTML_PREFORMATTED_STYLE_ID, MATH_BLOCK_STYLE_ID, MATH_INLINE_FONT_MARKER, MAX_HEADING_STYLE_LEVEL, MONOSPACE_FONT_FAMILY, QUOTE_INDENT_PT, QUOTE_STYLE_ID, TASK_CHECKBOX_CHECKED, TASK_CHECKBOX_UNCHECKED, headingStyleId, parseHeadingStyleId };
25
+ export { CODE_BLOCK_STYLE_ID, HORIZONTAL_RULE_STYLE_ID, HTML_PREFORMATTED_STYLE_ID, MATH_BLOCK_STYLE_ID, MATH_INLINE_FONT_MARKER, MAX_HEADING_STYLE_LEVEL, MONOSPACE_FONT_FAMILY, QUOTE_INDENT_PT, QUOTE_STYLE_ID, TASK_CHECKBOX_CHECKED, TASK_CHECKBOX_UNCHECKED, headingStyleId, parseHeadingStyleId };
package/dist/write.cjs CHANGED
@@ -1,11 +1,29 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_diagnostics_diagnostics = require("./diagnostics/diagnostics.cjs");
3
+ const require_emit_front_matter = require("./emit/front-matter.cjs");
4
+ const require_emit_inline = require("./emit/inline.cjs");
3
5
  const require_emit_emit = require("./emit/emit.cjs");
4
6
  let document_schema_js = require("document-schema.js");
5
7
  //#region src/write.ts
6
- function reportDroppedPackageTables(documentPackage, sink) {
8
+ function renderLinkDefinition(label, entry) {
9
+ const destination = entry.destination;
10
+ const title = entry.title;
11
+ if (typeof destination !== "string") return;
12
+ if (title !== void 0 && typeof title !== "string") return;
13
+ return `[${label}]: ${require_emit_inline.escapeLinkDestination(destination)}${title === void 0 ? "" : ` "${require_emit_inline.renderLinkTitle(title)}"`}`;
14
+ }
15
+ function renderLinkDefinitions(definitions) {
16
+ const lines = [];
17
+ for (const [label, entry] of Object.entries(definitions)) {
18
+ const line = renderLinkDefinition(label, entry);
19
+ if (line !== void 0) lines.push(line);
20
+ }
21
+ return lines.length > 0 ? lines.join("\n") : void 0;
22
+ }
23
+ function reportDroppedPackageTables(documentPackage, definitionsRendered, sink) {
24
+ const definitions = documentPackage.definitions;
7
25
  const tables = [
8
- ["definitions", documentPackage.definitions !== void 0 && Object.keys(documentPackage.definitions).length > 0],
26
+ ["definitions", definitions !== void 0 && !definitionsRendered && Object.keys(definitions).length > 0],
9
27
  ["layers", documentPackage.layers !== void 0 && Object.keys(documentPackage.layers).length > 0],
10
28
  ["attachments", documentPackage.attachments !== void 0 && Object.keys(documentPackage.attachments).length > 0],
11
29
  ["destinations", documentPackage.destinations !== void 0 && Object.keys(documentPackage.destinations).length > 0],
@@ -16,21 +34,30 @@ function reportDroppedPackageTables(documentPackage, sink) {
16
34
  sink({
17
35
  code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.PACKAGE_TABLE_DROPPED,
18
36
  severity: "info",
19
- message: `the package's own "${name}" table has no markdown representation; flattenPackage's envelope carries forward only metadata and symbolTable, so "${name}" is dropped rather than rendered`
37
+ message: `the package's own "${name}" table has no markdown representation; flattenTree's envelope carries forward only metadata and symbolTable, so "${name}" is dropped rather than rendered`
20
38
  });
21
39
  }
22
40
  }
23
41
  function writeMarkdown(documentPackage, options = {}) {
24
42
  options.signal?.throwIfAborted();
25
43
  if (documentPackage.kind !== "wordprocessing") throw new require_diagnostics_diagnostics.MarkdownUnsupportedDocumentKindError(documentPackage.kind);
26
- reportDroppedPackageTables(documentPackage, options.sink ?? require_diagnostics_diagnostics.NOOP_MARKDOWN_DIAGNOSTIC_SINK);
44
+ const sink = options.sink ?? require_diagnostics_diagnostics.NOOP_MARKDOWN_DIAGNOSTIC_SINK;
45
+ const definitionsBlock = documentPackage.definitions === void 0 ? void 0 : renderLinkDefinitions(documentPackage.definitions);
46
+ reportDroppedPackageTables(documentPackage, definitionsBlock !== void 0, sink);
27
47
  let flattened;
28
48
  try {
29
- flattened = (0, document_schema_js.flattenPackage)(documentPackage);
49
+ flattened = (0, document_schema_js.flattenTree)(documentPackage);
30
50
  } catch (error) {
31
51
  throw new require_diagnostics_diagnostics.MarkdownPackageFlattenError(error);
32
52
  }
33
- return writeMarkdownContent(flattened, options);
53
+ const body = writeMarkdownContent(flattened, {
54
+ ...options,
55
+ frontMatter: false
56
+ });
57
+ const frontMatterResidue = documentPackage.source?.frontmatter;
58
+ const frontMatter = options.frontMatter === true ? frontMatterResidue?.format === "markdown" ? frontMatterResidue.xml : require_emit_front_matter.emitFrontMatter(flattened.metadata) : void 0;
59
+ const withFrontMatter = frontMatter === void 0 ? body : `${frontMatter}\n\n${body}`;
60
+ return definitionsBlock === void 0 ? withFrontMatter : withFrontMatter.length > 0 ? `${withFrontMatter}\n\n${definitionsBlock}` : definitionsBlock;
34
61
  }
35
62
  function writeMarkdownContent(document, options = {}) {
36
63
  options.signal?.throwIfAborted();
package/dist/write.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { WriteMarkdownOptions } from "./options/options.cjs";
2
- import { ContentDocument, DocumentPackage } from "document-schema.js";
2
+ import { ContentDocument, DocumentTree } from "document-schema.js";
3
3
  //#region src/write.d.ts
4
- declare function writeMarkdown(documentPackage: DocumentPackage, options?: WriteMarkdownOptions): string;
4
+ declare function writeMarkdown(documentPackage: DocumentTree, options?: WriteMarkdownOptions): string;
5
5
  declare function writeMarkdownContent(document: ContentDocument, options?: WriteMarkdownOptions): string;
6
6
  //#endregion
7
7
  export { writeMarkdown, writeMarkdownContent };
package/dist/write.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { WriteMarkdownOptions } from "./options/options.js";
2
- import { ContentDocument, DocumentPackage } from "document-schema.js";
2
+ import { ContentDocument, DocumentTree } from "document-schema.js";
3
3
  //#region src/write.d.ts
4
- declare function writeMarkdown(documentPackage: DocumentPackage, options?: WriteMarkdownOptions): string;
4
+ declare function writeMarkdown(documentPackage: DocumentTree, options?: WriteMarkdownOptions): string;
5
5
  declare function writeMarkdownContent(document: ContentDocument, options?: WriteMarkdownOptions): string;
6
6
  //#endregion
7
7
  export { writeMarkdown, writeMarkdownContent };
package/dist/write.js CHANGED
@@ -1,10 +1,28 @@
1
1
  import { MarkdownDiagnosticCodes, MarkdownPackageFlattenError, MarkdownUnsupportedDocumentKindError, NOOP_MARKDOWN_DIAGNOSTIC_SINK } from "./diagnostics/diagnostics.js";
2
+ import { emitFrontMatter } from "./emit/front-matter.js";
3
+ import { escapeLinkDestination, renderLinkTitle } from "./emit/inline.js";
2
4
  import { emitMarkdown } from "./emit/emit.js";
3
- import { flattenPackage } from "document-schema.js";
5
+ import { flattenTree } from "document-schema.js";
4
6
  //#region src/write.ts
5
- function reportDroppedPackageTables(documentPackage, sink) {
7
+ function renderLinkDefinition(label, entry) {
8
+ const destination = entry.destination;
9
+ const title = entry.title;
10
+ if (typeof destination !== "string") return;
11
+ if (title !== void 0 && typeof title !== "string") return;
12
+ return `[${label}]: ${escapeLinkDestination(destination)}${title === void 0 ? "" : ` "${renderLinkTitle(title)}"`}`;
13
+ }
14
+ function renderLinkDefinitions(definitions) {
15
+ const lines = [];
16
+ for (const [label, entry] of Object.entries(definitions)) {
17
+ const line = renderLinkDefinition(label, entry);
18
+ if (line !== void 0) lines.push(line);
19
+ }
20
+ return lines.length > 0 ? lines.join("\n") : void 0;
21
+ }
22
+ function reportDroppedPackageTables(documentPackage, definitionsRendered, sink) {
23
+ const definitions = documentPackage.definitions;
6
24
  const tables = [
7
- ["definitions", documentPackage.definitions !== void 0 && Object.keys(documentPackage.definitions).length > 0],
25
+ ["definitions", definitions !== void 0 && !definitionsRendered && Object.keys(definitions).length > 0],
8
26
  ["layers", documentPackage.layers !== void 0 && Object.keys(documentPackage.layers).length > 0],
9
27
  ["attachments", documentPackage.attachments !== void 0 && Object.keys(documentPackage.attachments).length > 0],
10
28
  ["destinations", documentPackage.destinations !== void 0 && Object.keys(documentPackage.destinations).length > 0],
@@ -15,21 +33,30 @@ function reportDroppedPackageTables(documentPackage, sink) {
15
33
  sink({
16
34
  code: MarkdownDiagnosticCodes.PACKAGE_TABLE_DROPPED,
17
35
  severity: "info",
18
- message: `the package's own "${name}" table has no markdown representation; flattenPackage's envelope carries forward only metadata and symbolTable, so "${name}" is dropped rather than rendered`
36
+ message: `the package's own "${name}" table has no markdown representation; flattenTree's envelope carries forward only metadata and symbolTable, so "${name}" is dropped rather than rendered`
19
37
  });
20
38
  }
21
39
  }
22
40
  function writeMarkdown(documentPackage, options = {}) {
23
41
  options.signal?.throwIfAborted();
24
42
  if (documentPackage.kind !== "wordprocessing") throw new MarkdownUnsupportedDocumentKindError(documentPackage.kind);
25
- reportDroppedPackageTables(documentPackage, options.sink ?? NOOP_MARKDOWN_DIAGNOSTIC_SINK);
43
+ const sink = options.sink ?? NOOP_MARKDOWN_DIAGNOSTIC_SINK;
44
+ const definitionsBlock = documentPackage.definitions === void 0 ? void 0 : renderLinkDefinitions(documentPackage.definitions);
45
+ reportDroppedPackageTables(documentPackage, definitionsBlock !== void 0, sink);
26
46
  let flattened;
27
47
  try {
28
- flattened = flattenPackage(documentPackage);
48
+ flattened = flattenTree(documentPackage);
29
49
  } catch (error) {
30
50
  throw new MarkdownPackageFlattenError(error);
31
51
  }
32
- return writeMarkdownContent(flattened, options);
52
+ const body = writeMarkdownContent(flattened, {
53
+ ...options,
54
+ frontMatter: false
55
+ });
56
+ const frontMatterResidue = documentPackage.source?.frontmatter;
57
+ const frontMatter = options.frontMatter === true ? frontMatterResidue?.format === "markdown" ? frontMatterResidue.xml : emitFrontMatter(flattened.metadata) : void 0;
58
+ const withFrontMatter = frontMatter === void 0 ? body : `${frontMatter}\n\n${body}`;
59
+ return definitionsBlock === void 0 ? withFrontMatter : withFrontMatter.length > 0 ? `${withFrontMatter}\n\n${definitionsBlock}` : definitionsBlock;
33
60
  }
34
61
  function writeMarkdownContent(document, options = {}) {
35
62
  options.signal?.throwIfAborted();
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "mrkdwn.js",
3
- "version": "4.0.6",
4
- "description": "Hand-written CommonMark+GFM <-> DocumentPackage codec, built on document-schema.js",
3
+ "version": "6.6.2",
4
+ "description": "Hand-written CommonMark+GFM <-> DocumentTree codec, built on document-schema.js",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git+https://github.com/ExaDev/markdown-codec.git"
8
+ "url": "git+https://github.com/ExaDev/documents.js.git",
9
+ "directory": "packages/markdown-codec"
9
10
  },
10
- "homepage": "https://github.com/ExaDev/markdown-codec#readme",
11
+ "homepage": "https://github.com/ExaDev/documents.js/tree/main/packages/markdown-codec",
11
12
  "bugs": {
12
- "url": "https://github.com/ExaDev/markdown-codec/issues"
13
+ "url": "https://github.com/ExaDev/documents.js/issues"
13
14
  },
14
15
  "exports": {
15
16
  ".": {
@@ -55,40 +56,36 @@
55
56
  ],
56
57
  "license": "MIT",
57
58
  "dependencies": {
58
- "document-schema.js": "^4.3.3",
59
- "zod": "^4.4.3"
59
+ "document-schema.js": "7.6.1",
60
+ "zod": "4.4.3"
60
61
  },
61
62
  "devDependencies": {
62
- "@arethetypeswrong/cli": "^0.18.5",
63
- "@cloudflare/vitest-pool-workers": "^0.21.2",
64
- "@commitlint/cli": "^21.2.1",
65
- "@commitlint/config-conventional": "^21.2.0",
66
- "@eslint/js": "^10.0.1",
67
- "@exadev/eslint-config": "^2.1.0",
68
- "@semantic-release/changelog": "^7.0.0",
69
- "@semantic-release/git": "^11.0.1",
70
- "@types/node": "^26.1.1",
71
- "@vitest/coverage-v8": "^4.1.10",
72
- "eslint": "^10.8.0",
73
- "globals": "^17.8.0",
74
- "husky": "^9.1.7",
75
- "lint-staged": "^17.2.0",
76
- "publint": "^0.3.21",
77
- "semantic-release": "^25.0.8",
78
- "tsdown": "^0.22.13",
79
- "turbo": "^2.10.8",
80
- "typescript": "^6.0.3",
81
- "typescript-eslint": "^8.65.0",
82
- "vitest": "^4.1.10"
63
+ "@arethetypeswrong/cli": "0.18.5",
64
+ "@cloudflare/vitest-pool-workers": "0.21.2",
65
+ "@stryker-mutator/core": "10.0.0",
66
+ "@stryker-mutator/typescript-checker": "10.0.0",
67
+ "@stryker-mutator/vitest-runner": "10.0.0",
68
+ "@types/node": "26.2.0",
69
+ "@vitest/coverage-v8": "4.1.11",
70
+ "eslint": "10.8.1",
71
+ "husky": "9.1.7",
72
+ "jiti": "2.7.0",
73
+ "publint": "0.3.22",
74
+ "semantic-release": "25.0.9",
75
+ "tsdown": "0.22.14",
76
+ "turbo": "2.10.8",
77
+ "typescript": "6.0.3",
78
+ "vitest": "4.1.11"
83
79
  },
84
80
  "scripts": {
85
81
  "build": "turbo run _build",
86
82
  "_build": "tsdown",
87
83
  "lint": "turbo run _lint",
88
84
  "_lint": "eslint . --fix --cache --max-warnings 0",
89
- "typecheck": "turbo run _typecheck _typecheck:node",
85
+ "typecheck": "turbo run _typecheck _typecheck:node _typecheck:attw",
90
86
  "_typecheck": "tsc -p tsconfig.json",
91
87
  "_typecheck:node": "tsc -p tsconfig.node.json",
88
+ "_typecheck:attw": "attw --pack",
92
89
  "test": "turbo run _test",
93
90
  "_test": "vitest run --project unit",
94
91
  "test:workers": "turbo run _test:workers",
@@ -96,10 +93,12 @@
96
93
  "test:watch": "vitest --project unit",
97
94
  "test:coverage": "turbo run _test:coverage",
98
95
  "_test:coverage": "vitest run --project unit --coverage",
96
+ "test:mutation": "turbo run _test:mutation",
97
+ "_test:mutation": "stryker run stryker.config.mjs",
99
98
  "test:corpus": "turbo run _test:corpus",
100
99
  "_test:corpus": "vitest run --project corpus",
101
100
  "test:smoke": "turbo run _test:smoke",
102
- "_test:smoke": "tsdown && vitest run --project smoke",
101
+ "_test:smoke": "vitest run --project smoke",
103
102
  "release": "semantic-release"
104
103
  }
105
104
  }
@@ -1,18 +0,0 @@
1
- //#region src/inline/link.d.ts
2
- interface LinkReferenceDefinition {
3
- readonly destination: string;
4
- readonly title?: string;
5
- }
6
- type LinkReferenceMap = ReadonlyMap<string, LinkReferenceDefinition>;
7
- declare function normalizeLinkLabel(labelWithBrackets: string): string;
8
- declare function matchLinkLabel(text: string, start: number): number;
9
- interface ParsedSpan {
10
- readonly value: string;
11
- readonly end: number;
12
- }
13
- declare function parseLinkDestination(text: string, start: number): ParsedSpan | undefined;
14
- declare function parseLinkTitle(text: string, start: number): ParsedSpan | undefined;
15
- declare function skipInlineWhitespace(text: string, start: number): number;
16
- declare function isBlankRemainderOfLine(text: string, start: number): boolean;
17
- //#endregion
18
- export { matchLinkLabel as a, parseLinkTitle as c, isBlankRemainderOfLine as i, skipInlineWhitespace as l, LinkReferenceMap as n, normalizeLinkLabel as o, ParsedSpan as r, parseLinkDestination as s, LinkReferenceDefinition as t };
@@ -1,18 +0,0 @@
1
- //#region src/inline/link.d.ts
2
- interface LinkReferenceDefinition {
3
- readonly destination: string;
4
- readonly title?: string;
5
- }
6
- type LinkReferenceMap = ReadonlyMap<string, LinkReferenceDefinition>;
7
- declare function normalizeLinkLabel(labelWithBrackets: string): string;
8
- declare function matchLinkLabel(text: string, start: number): number;
9
- interface ParsedSpan {
10
- readonly value: string;
11
- readonly end: number;
12
- }
13
- declare function parseLinkDestination(text: string, start: number): ParsedSpan | undefined;
14
- declare function parseLinkTitle(text: string, start: number): ParsedSpan | undefined;
15
- declare function skipInlineWhitespace(text: string, start: number): number;
16
- declare function isBlankRemainderOfLine(text: string, start: number): boolean;
17
- //#endregion
18
- export { matchLinkLabel as a, parseLinkTitle as c, isBlankRemainderOfLine as i, skipInlineWhitespace as l, LinkReferenceMap as n, normalizeLinkLabel as o, ParsedSpan as r, parseLinkDestination as s, LinkReferenceDefinition as t };