markdown-codec 0.0.0 → 1.0.0

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 (171) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +215 -0
  3. package/dist/ast/ast.cjs +25 -0
  4. package/dist/ast/ast.d.cts +2 -0
  5. package/dist/ast/ast.d.ts +2 -0
  6. package/dist/ast/ast.js +23 -0
  7. package/dist/ast-BXYwy08e.d.cts +160 -0
  8. package/dist/ast-BXYwy08e.d.ts +160 -0
  9. package/dist/block/block.cjs +530 -0
  10. package/dist/block/block.d.cts +18 -0
  11. package/dist/block/block.d.ts +18 -0
  12. package/dist/block/block.js +529 -0
  13. package/dist/block/definitions.cjs +59 -0
  14. package/dist/block/definitions.d.cts +6 -0
  15. package/dist/block/definitions.d.ts +6 -0
  16. package/dist/block/definitions.js +58 -0
  17. package/dist/block/line.cjs +76 -0
  18. package/dist/block/line.d.cts +28 -0
  19. package/dist/block/line.d.ts +28 -0
  20. package/dist/block/line.js +74 -0
  21. package/dist/block/list.cjs +110 -0
  22. package/dist/block/list.d.cts +8 -0
  23. package/dist/block/list.d.ts +8 -0
  24. package/dist/block/list.js +107 -0
  25. package/dist/block/node.cjs +68 -0
  26. package/dist/block/node.d.cts +45 -0
  27. package/dist/block/node.d.ts +45 -0
  28. package/dist/block/node.js +65 -0
  29. package/dist/block/table.cjs +64 -0
  30. package/dist/block/table.d.cts +7 -0
  31. package/dist/block/table.d.ts +7 -0
  32. package/dist/block/table.js +61 -0
  33. package/dist/codec.cjs +22 -0
  34. package/dist/codec.d.cts +361 -0
  35. package/dist/codec.d.ts +361 -0
  36. package/dist/codec.js +20 -0
  37. package/dist/defaults/defaults.cjs +31 -0
  38. package/dist/defaults/defaults.d.cts +16 -0
  39. package/dist/defaults/defaults.d.ts +16 -0
  40. package/dist/defaults/defaults.js +20 -0
  41. package/dist/diagnostics/diagnostics.cjs +85 -0
  42. package/dist/diagnostics/diagnostics.d.cts +2 -0
  43. package/dist/diagnostics/diagnostics.d.ts +2 -0
  44. package/dist/diagnostics/diagnostics.js +77 -0
  45. package/dist/diagnostics-DmuWc7d8.d.cts +61 -0
  46. package/dist/diagnostics-DmuWc7d8.d.ts +61 -0
  47. package/dist/emit/emit.cjs +228 -0
  48. package/dist/emit/emit.d.cts +6 -0
  49. package/dist/emit/emit.d.ts +6 -0
  50. package/dist/emit/emit.js +227 -0
  51. package/dist/emit/front-matter.cjs +24 -0
  52. package/dist/emit/front-matter.d.cts +5 -0
  53. package/dist/emit/front-matter.d.ts +5 -0
  54. package/dist/emit/front-matter.js +23 -0
  55. package/dist/emit/image.cjs +10 -0
  56. package/dist/emit/image.d.cts +5 -0
  57. package/dist/emit/image.d.ts +5 -0
  58. package/dist/emit/image.js +9 -0
  59. package/dist/emit/inline.cjs +183 -0
  60. package/dist/emit/inline.d.cts +12 -0
  61. package/dist/emit/inline.d.ts +12 -0
  62. package/dist/emit/inline.js +180 -0
  63. package/dist/emit/table.cjs +73 -0
  64. package/dist/emit/table.d.cts +10 -0
  65. package/dist/emit/table.d.ts +10 -0
  66. package/dist/emit/table.js +72 -0
  67. package/dist/html/html.cjs +116 -0
  68. package/dist/html/html.d.cts +2 -0
  69. package/dist/html/html.d.ts +2 -0
  70. package/dist/html/html.js +113 -0
  71. package/dist/html/render.cjs +193 -0
  72. package/dist/html/render.d.cts +8 -0
  73. package/dist/html/render.d.ts +8 -0
  74. package/dist/html/render.js +189 -0
  75. package/dist/html-bkz2QTuq.d.cts +7 -0
  76. package/dist/html-bkz2QTuq.d.ts +7 -0
  77. package/dist/image/image.cjs +129 -0
  78. package/dist/image/image.d.cts +2 -0
  79. package/dist/image/image.d.ts +2 -0
  80. package/dist/image/image.js +125 -0
  81. package/dist/image-C4KYmz_L.d.cts +19 -0
  82. package/dist/image-Cm3hT5PS.d.ts +19 -0
  83. package/dist/image-DescdRgq.d.cts +12 -0
  84. package/dist/image-DescdRgq.d.ts +12 -0
  85. package/dist/index.cjs +17 -0
  86. package/dist/index.d.cts +7 -0
  87. package/dist/index.d.ts +7 -0
  88. package/dist/index.js +5 -0
  89. package/dist/inline/chars.cjs +50 -0
  90. package/dist/inline/chars.d.cts +11 -0
  91. package/dist/inline/chars.d.ts +11 -0
  92. package/dist/inline/chars.js +42 -0
  93. package/dist/inline/delimiter.cjs +136 -0
  94. package/dist/inline/delimiter.d.cts +29 -0
  95. package/dist/inline/delimiter.d.ts +29 -0
  96. package/dist/inline/delimiter.js +132 -0
  97. package/dist/inline/entity.cjs +67 -0
  98. package/dist/inline/entity.d.cts +9 -0
  99. package/dist/inline/entity.d.ts +9 -0
  100. package/dist/inline/entity.js +65 -0
  101. package/dist/inline/gfm-autolink.cjs +156 -0
  102. package/dist/inline/gfm-autolink.d.cts +5 -0
  103. package/dist/inline/gfm-autolink.d.ts +5 -0
  104. package/dist/inline/gfm-autolink.js +155 -0
  105. package/dist/inline/inline.cjs +457 -0
  106. package/dist/inline/inline.d.cts +2 -0
  107. package/dist/inline/inline.d.ts +2 -0
  108. package/dist/inline/inline.js +456 -0
  109. package/dist/inline/link.cjs +130 -0
  110. package/dist/inline/link.d.cts +2 -0
  111. package/dist/inline/link.d.ts +2 -0
  112. package/dist/inline/link.js +124 -0
  113. package/dist/inline/node.cjs +57 -0
  114. package/dist/inline/node.d.cts +23 -0
  115. package/dist/inline/node.d.ts +23 -0
  116. package/dist/inline/node.js +55 -0
  117. package/dist/inline-B50cM6cn.d.ts +10 -0
  118. package/dist/inline-C9YEGDV5.d.cts +10 -0
  119. package/dist/link-Dv4kxVjk.d.cts +18 -0
  120. package/dist/link-Dv4kxVjk.d.ts +18 -0
  121. package/dist/lower/front-matter.cjs +75 -0
  122. package/dist/lower/front-matter.d.cts +10 -0
  123. package/dist/lower/front-matter.d.ts +10 -0
  124. package/dist/lower/front-matter.js +74 -0
  125. package/dist/lower/image.cjs +29 -0
  126. package/dist/lower/image.d.cts +2 -0
  127. package/dist/lower/image.d.ts +2 -0
  128. package/dist/lower/image.js +28 -0
  129. package/dist/lower/inline.cjs +96 -0
  130. package/dist/lower/inline.d.cts +19 -0
  131. package/dist/lower/inline.d.ts +19 -0
  132. package/dist/lower/inline.js +93 -0
  133. package/dist/lower/lower.cjs +293 -0
  134. package/dist/lower/lower.d.cts +8 -0
  135. package/dist/lower/lower.d.ts +8 -0
  136. package/dist/lower/lower.js +291 -0
  137. package/dist/lower/table.cjs +27 -0
  138. package/dist/lower/table.d.cts +7 -0
  139. package/dist/lower/table.d.ts +7 -0
  140. package/dist/lower/table.js +26 -0
  141. package/dist/options/options.cjs +0 -0
  142. package/dist/options/options.d.cts +43 -0
  143. package/dist/options/options.d.ts +43 -0
  144. package/dist/options/options.js +0 -0
  145. package/dist/read.cjs +20 -0
  146. package/dist/read.d.cts +11 -0
  147. package/dist/read.d.ts +11 -0
  148. package/dist/read.js +19 -0
  149. package/dist/scan/entity-table.cjs +2131 -0
  150. package/dist/scan/entity-table.d.cts +4 -0
  151. package/dist/scan/entity-table.d.ts +4 -0
  152. package/dist/scan/entity-table.js +2130 -0
  153. package/dist/scan/scan.cjs +80 -0
  154. package/dist/scan/scan.d.cts +2 -0
  155. package/dist/scan/scan.d.ts +2 -0
  156. package/dist/scan/scan.js +78 -0
  157. package/dist/scan-DeBxgG-r.d.cts +30 -0
  158. package/dist/scan-DeBxgG-r.d.ts +30 -0
  159. package/dist/shared/list-id.cjs +36 -0
  160. package/dist/shared/list-id.d.cts +22 -0
  161. package/dist/shared/list-id.d.ts +22 -0
  162. package/dist/shared/list-id.js +32 -0
  163. package/dist/shared/style-constants.cjs +34 -0
  164. package/dist/shared/style-constants.d.cts +14 -0
  165. package/dist/shared/style-constants.d.ts +14 -0
  166. package/dist/shared/style-constants.js +23 -0
  167. package/dist/write.cjs +9 -0
  168. package/dist/write.d.cts +6 -0
  169. package/dist/write.d.ts +6 -0
  170. package/dist/write.js +8 -0
  171. package/package.json +92 -2
@@ -0,0 +1,125 @@
1
+ //#region src/image/image.ts
2
+ const BASE64_TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
3
+ const BASE64_DECODE = (() => {
4
+ const map = (/* @__PURE__ */ new Uint8Array(256)).fill(255);
5
+ for (let index = 0; index < 64; index += 1) map[BASE64_TABLE.charCodeAt(index)] = index;
6
+ return map;
7
+ })();
8
+ const BASE64_PADDING_CODE = 61;
9
+ function bytesToBase64(bytes) {
10
+ let out = "";
11
+ const { length } = bytes;
12
+ for (let index = 0; index < length; index += 3) {
13
+ const b0 = bytes[index];
14
+ const b1 = index + 1 < length ? bytes[index + 1] : 0;
15
+ const b2 = index + 2 < length ? bytes[index + 2] : 0;
16
+ out += BASE64_TABLE[b0 >> 2];
17
+ out += BASE64_TABLE[(b0 & 3) << 4 | b1 >> 4];
18
+ out += index + 1 < length ? BASE64_TABLE[(b1 & 15) << 2 | b2 >> 6] : "=";
19
+ out += index + 2 < length ? BASE64_TABLE[b2 & 63] : "=";
20
+ }
21
+ return out;
22
+ }
23
+ function base64ToBytes(base64) {
24
+ const clean = base64.replace(/[^A-Za-z0-9+/=]/g, "");
25
+ const { length } = clean;
26
+ const out = new Uint8Array(Math.floor(length * 3 / 4));
27
+ let position = 0;
28
+ for (let index = 0; index < length; index += 4) {
29
+ const c0 = BASE64_DECODE[clean.charCodeAt(index)];
30
+ const c1 = BASE64_DECODE[clean.charCodeAt(index + 1)];
31
+ const code2 = clean.charCodeAt(index + 2);
32
+ const code3 = clean.charCodeAt(index + 3);
33
+ if (c0 === 255 || c1 === 255) throw new Error("invalid base64 input");
34
+ out[position] = c0 << 2 | c1 >> 4;
35
+ position += 1;
36
+ if (code2 !== BASE64_PADDING_CODE) {
37
+ const d2 = BASE64_DECODE[code2];
38
+ out[position] = (c1 & 15) << 4 | d2 >> 2;
39
+ position += 1;
40
+ if (code3 !== BASE64_PADDING_CODE) {
41
+ const d3 = BASE64_DECODE[code3];
42
+ out[position] = (d2 & 3) << 6 | d3;
43
+ position += 1;
44
+ }
45
+ }
46
+ }
47
+ return out.subarray(0, position);
48
+ }
49
+ function readUint16BE(bytes, offset) {
50
+ return (bytes[offset] << 8 | bytes[offset + 1]) & 65535;
51
+ }
52
+ function readUint32BE(bytes, offset) {
53
+ return (bytes[offset] << 24 | bytes[offset + 1] << 16 | bytes[offset + 2] << 8 | bytes[offset + 3]) >>> 0;
54
+ }
55
+ const PNG_SIGNATURE = [
56
+ 137,
57
+ 80,
58
+ 78,
59
+ 71,
60
+ 13,
61
+ 10,
62
+ 26,
63
+ 10
64
+ ];
65
+ const PNG_HEADER_BYTES = 24;
66
+ function isPng(bytes) {
67
+ if (bytes.length < PNG_SIGNATURE.length) return false;
68
+ return PNG_SIGNATURE.every((byte, index) => bytes[index] === byte);
69
+ }
70
+ function readPngDimensions(bytes) {
71
+ if (bytes.length < PNG_HEADER_BYTES) return;
72
+ if (bytes[12] !== 73 || bytes[13] !== 72 || bytes[14] !== 68 || bytes[15] !== 82) return;
73
+ return {
74
+ widthPx: readUint32BE(bytes, 16),
75
+ heightPx: readUint32BE(bytes, 20)
76
+ };
77
+ }
78
+ function isStartOfFrameMarker(marker) {
79
+ if (marker < 192 || marker > 207) return false;
80
+ return marker !== 196 && marker !== 200 && marker !== 204;
81
+ }
82
+ function hasNoLengthField(marker) {
83
+ return marker === 216 || marker === 217 || marker === 1 || marker >= 208 && marker <= 215;
84
+ }
85
+ function readJpegDimensions(bytes) {
86
+ if (bytes.length < 4 || bytes[0] !== 255 || bytes[1] !== 216) return;
87
+ let offset = 2;
88
+ while (offset < bytes.length) {
89
+ if (bytes[offset] !== 255) {
90
+ offset += 1;
91
+ continue;
92
+ }
93
+ let markerOffset = offset + 1;
94
+ while (bytes[markerOffset] === 255) markerOffset += 1;
95
+ const marker = bytes[markerOffset];
96
+ if (marker === void 0) return;
97
+ offset = markerOffset + 1;
98
+ if (hasNoLengthField(marker)) continue;
99
+ if (offset + 2 > bytes.length) return;
100
+ const length = readUint16BE(bytes, offset);
101
+ if (isStartOfFrameMarker(marker)) {
102
+ if (offset + 7 > bytes.length) return;
103
+ const heightPx = readUint16BE(bytes, offset + 3);
104
+ return {
105
+ widthPx: readUint16BE(bytes, offset + 5),
106
+ heightPx
107
+ };
108
+ }
109
+ if (marker === 218) return;
110
+ offset += length;
111
+ }
112
+ }
113
+ function isJpeg(bytes) {
114
+ return bytes.length >= 2 && bytes[0] === 255 && bytes[1] === 216;
115
+ }
116
+ function detectImageFormat(bytes) {
117
+ if (isPng(bytes)) return "png";
118
+ return isJpeg(bytes) ? "jpeg" : void 0;
119
+ }
120
+ function readImageDimensions(bytes) {
121
+ if (isPng(bytes)) return readPngDimensions(bytes);
122
+ return readJpegDimensions(bytes);
123
+ }
124
+ //#endregion
125
+ export { base64ToBytes, bytesToBase64, detectImageFormat, readImageDimensions };
@@ -0,0 +1,19 @@
1
+ import { n as ImageFormat } from "./image-DescdRgq.cjs";
2
+ //#region src/lower/image.d.ts
3
+ interface MarkdownImageResolveContext {
4
+ readonly alt: string;
5
+ readonly title?: string;
6
+ }
7
+ interface MarkdownResolvedImageBytes {
8
+ readonly bytes: Uint8Array;
9
+ }
10
+ type MarkdownImageResolver = (destination: string, context: MarkdownImageResolveContext) => MarkdownResolvedImageBytes | undefined;
11
+ interface ResolvedMarkdownImage {
12
+ readonly format: ImageFormat;
13
+ readonly base64: string;
14
+ readonly widthPt: number;
15
+ readonly heightPt: number;
16
+ }
17
+ declare function resolveMarkdownImage(destination: string, context: MarkdownImageResolveContext, resolver: MarkdownImageResolver | undefined): ResolvedMarkdownImage | undefined;
18
+ //#endregion
19
+ export { resolveMarkdownImage as a, ResolvedMarkdownImage as i, MarkdownImageResolver as n, MarkdownResolvedImageBytes as r, MarkdownImageResolveContext as t };
@@ -0,0 +1,19 @@
1
+ import { n as ImageFormat } from "./image-DescdRgq.js";
2
+ //#region src/lower/image.d.ts
3
+ interface MarkdownImageResolveContext {
4
+ readonly alt: string;
5
+ readonly title?: string;
6
+ }
7
+ interface MarkdownResolvedImageBytes {
8
+ readonly bytes: Uint8Array;
9
+ }
10
+ type MarkdownImageResolver = (destination: string, context: MarkdownImageResolveContext) => MarkdownResolvedImageBytes | undefined;
11
+ interface ResolvedMarkdownImage {
12
+ readonly format: ImageFormat;
13
+ readonly base64: string;
14
+ readonly widthPt: number;
15
+ readonly heightPt: number;
16
+ }
17
+ declare function resolveMarkdownImage(destination: string, context: MarkdownImageResolveContext, resolver: MarkdownImageResolver | undefined): ResolvedMarkdownImage | undefined;
18
+ //#endregion
19
+ export { resolveMarkdownImage as a, ResolvedMarkdownImage as i, MarkdownImageResolver as n, MarkdownResolvedImageBytes as r, MarkdownImageResolveContext as t };
@@ -0,0 +1,12 @@
1
+ //#region src/image/image.d.ts
2
+ interface ImageDimensions {
3
+ readonly widthPx: number;
4
+ readonly heightPx: number;
5
+ }
6
+ type ImageFormat = 'png' | 'jpeg';
7
+ declare function bytesToBase64(bytes: Uint8Array): string;
8
+ declare function base64ToBytes(base64: string): Uint8Array;
9
+ declare function detectImageFormat(bytes: Uint8Array): ImageFormat | undefined;
10
+ declare function readImageDimensions(bytes: Uint8Array): ImageDimensions | undefined;
11
+ //#endregion
12
+ export { detectImageFormat as a, bytesToBase64 as i, ImageFormat as n, readImageDimensions as o, base64ToBytes as r, ImageDimensions as t };
@@ -0,0 +1,12 @@
1
+ //#region src/image/image.d.ts
2
+ interface ImageDimensions {
3
+ readonly widthPx: number;
4
+ readonly heightPx: number;
5
+ }
6
+ type ImageFormat = 'png' | 'jpeg';
7
+ declare function bytesToBase64(bytes: Uint8Array): string;
8
+ declare function base64ToBytes(base64: string): Uint8Array;
9
+ declare function detectImageFormat(bytes: Uint8Array): ImageFormat | undefined;
10
+ declare function readImageDimensions(bytes: Uint8Array): ImageDimensions | undefined;
11
+ //#endregion
12
+ export { detectImageFormat as a, bytesToBase64 as i, ImageFormat as n, readImageDimensions as o, base64ToBytes as r, ImageDimensions as t };
package/dist/index.cjs ADDED
@@ -0,0 +1,17 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_diagnostics_diagnostics = require("./diagnostics/diagnostics.cjs");
3
+ const require_read = require("./read.cjs");
4
+ const require_write = require("./write.cjs");
5
+ const require_codec = require("./codec.cjs");
6
+ exports.MarkdownBytesSchema = require_codec.MarkdownBytesSchema;
7
+ exports.MarkdownDiagnosticCodes = require_diagnostics_diagnostics.MarkdownDiagnosticCodes;
8
+ exports.MarkdownInputTooLargeError = require_diagnostics_diagnostics.MarkdownInputTooLargeError;
9
+ exports.MarkdownInvalidUtf8Error = require_diagnostics_diagnostics.MarkdownInvalidUtf8Error;
10
+ exports.MarkdownNestingLimitExceededError = require_diagnostics_diagnostics.MarkdownNestingLimitExceededError;
11
+ exports.MarkdownParseError = require_diagnostics_diagnostics.MarkdownParseError;
12
+ exports.MarkdownUnsupportedDocumentKindError = require_diagnostics_diagnostics.MarkdownUnsupportedDocumentKindError;
13
+ exports.MarkdownWriteError = require_diagnostics_diagnostics.MarkdownWriteError;
14
+ exports.NOOP_MARKDOWN_DIAGNOSTIC_SINK = require_diagnostics_diagnostics.NOOP_MARKDOWN_DIAGNOSTIC_SINK;
15
+ exports.markdownCodec = require_codec.markdownCodec;
16
+ exports.readMarkdown = require_read.readMarkdown;
17
+ exports.writeMarkdown = require_write.writeMarkdown;
@@ -0,0 +1,7 @@
1
+ import { a as MarkdownInputTooLargeError, c as MarkdownParseError, d as NOOP_MARKDOWN_DIAGNOSTIC_SINK, i as MarkdownDiagnosticSink, l as MarkdownUnsupportedDocumentKindError, n as MarkdownDiagnosticCodes, o as MarkdownInvalidUtf8Error, r as MarkdownDiagnosticSeverity, s as MarkdownNestingLimitExceededError, t as MarkdownDiagnostic, u as MarkdownWriteError } from "./diagnostics-DmuWc7d8.cjs";
2
+ import { MarkdownBytesSchema, markdownCodec } from "./codec.cjs";
3
+ import { n as MarkdownImageResolver, r as MarkdownResolvedImageBytes, t as MarkdownImageResolveContext } from "./image-C4KYmz_L.cjs";
4
+ import { MarkdownBulletListMarker, MarkdownCodeFenceChar, MarkdownEmphasisMarker, MarkdownHeadingStyle, MarkdownLineEnding, MarkdownOrderedListDelimiter, MarkdownThematicBreakChar, ReadMarkdownOptions, WriteMarkdownOptions, WriteMarkdownStyleOptions } from "./options/options.cjs";
5
+ import { ReadMarkdownResult, readMarkdown } from "./read.cjs";
6
+ import { writeMarkdown } from "./write.cjs";
7
+ export { type MarkdownBulletListMarker, MarkdownBytesSchema, type MarkdownCodeFenceChar, type MarkdownDiagnostic, MarkdownDiagnosticCodes, type MarkdownDiagnosticSeverity, type MarkdownDiagnosticSink, type MarkdownEmphasisMarker, type MarkdownHeadingStyle, type MarkdownImageResolveContext, type MarkdownImageResolver, MarkdownInputTooLargeError, MarkdownInvalidUtf8Error, type MarkdownLineEnding, MarkdownNestingLimitExceededError, type MarkdownOrderedListDelimiter, MarkdownParseError, type MarkdownResolvedImageBytes, type MarkdownThematicBreakChar, MarkdownUnsupportedDocumentKindError, MarkdownWriteError, NOOP_MARKDOWN_DIAGNOSTIC_SINK, type ReadMarkdownOptions, type ReadMarkdownResult, type WriteMarkdownOptions, type WriteMarkdownStyleOptions, markdownCodec, readMarkdown, writeMarkdown };
@@ -0,0 +1,7 @@
1
+ import { a as MarkdownInputTooLargeError, c as MarkdownParseError, d as NOOP_MARKDOWN_DIAGNOSTIC_SINK, i as MarkdownDiagnosticSink, l as MarkdownUnsupportedDocumentKindError, n as MarkdownDiagnosticCodes, o as MarkdownInvalidUtf8Error, r as MarkdownDiagnosticSeverity, s as MarkdownNestingLimitExceededError, t as MarkdownDiagnostic, u as MarkdownWriteError } from "./diagnostics-DmuWc7d8.js";
2
+ import { MarkdownBytesSchema, markdownCodec } from "./codec.js";
3
+ import { n as MarkdownImageResolver, r as MarkdownResolvedImageBytes, t as MarkdownImageResolveContext } from "./image-Cm3hT5PS.js";
4
+ import { MarkdownBulletListMarker, MarkdownCodeFenceChar, MarkdownEmphasisMarker, MarkdownHeadingStyle, MarkdownLineEnding, MarkdownOrderedListDelimiter, MarkdownThematicBreakChar, ReadMarkdownOptions, WriteMarkdownOptions, WriteMarkdownStyleOptions } from "./options/options.js";
5
+ import { ReadMarkdownResult, readMarkdown } from "./read.js";
6
+ import { writeMarkdown } from "./write.js";
7
+ export { type MarkdownBulletListMarker, MarkdownBytesSchema, type MarkdownCodeFenceChar, type MarkdownDiagnostic, MarkdownDiagnosticCodes, type MarkdownDiagnosticSeverity, type MarkdownDiagnosticSink, type MarkdownEmphasisMarker, type MarkdownHeadingStyle, type MarkdownImageResolveContext, type MarkdownImageResolver, MarkdownInputTooLargeError, MarkdownInvalidUtf8Error, type MarkdownLineEnding, MarkdownNestingLimitExceededError, type MarkdownOrderedListDelimiter, MarkdownParseError, type MarkdownResolvedImageBytes, type MarkdownThematicBreakChar, MarkdownUnsupportedDocumentKindError, MarkdownWriteError, NOOP_MARKDOWN_DIAGNOSTIC_SINK, type ReadMarkdownOptions, type ReadMarkdownResult, type WriteMarkdownOptions, type WriteMarkdownStyleOptions, markdownCodec, readMarkdown, writeMarkdown };
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { MarkdownDiagnosticCodes, MarkdownInputTooLargeError, MarkdownInvalidUtf8Error, MarkdownNestingLimitExceededError, MarkdownParseError, MarkdownUnsupportedDocumentKindError, MarkdownWriteError, NOOP_MARKDOWN_DIAGNOSTIC_SINK } from "./diagnostics/diagnostics.js";
2
+ import { readMarkdown } from "./read.js";
3
+ import { writeMarkdown } from "./write.js";
4
+ import { MarkdownBytesSchema, markdownCodec } from "./codec.js";
5
+ export { MarkdownBytesSchema, MarkdownDiagnosticCodes, MarkdownInputTooLargeError, MarkdownInvalidUtf8Error, MarkdownNestingLimitExceededError, MarkdownParseError, MarkdownUnsupportedDocumentKindError, MarkdownWriteError, NOOP_MARKDOWN_DIAGNOSTIC_SINK, markdownCodec, readMarkdown, writeMarkdown };
@@ -0,0 +1,50 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/inline/chars.ts
3
+ const ASCII_PUNCTUATION = new Set("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~".split(""));
4
+ function isAsciiPunctuation(char) {
5
+ return ASCII_PUNCTUATION.has(char);
6
+ }
7
+ const UNICODE_WHITESPACE_PATTERN = /^[\p{Zs}\t\n\f\r]$/u;
8
+ function isUnicodeWhitespace(char) {
9
+ return UNICODE_WHITESPACE_PATTERN.test(char);
10
+ }
11
+ const UNICODE_PUNCTUATION_PATTERN = /^[\p{P}\p{S}]$/u;
12
+ function isUnicodePunctuation(char) {
13
+ return UNICODE_PUNCTUATION_PATTERN.test(char);
14
+ }
15
+ function isAsciiControl(char) {
16
+ const code = char.codePointAt(0);
17
+ if (code === void 0) return false;
18
+ return code <= 31 || code === 127;
19
+ }
20
+ function containsAsciiControlOrSpace(text) {
21
+ for (let index = 0; index < text.length; index += 1) if (isAsciiControl(text.charAt(index)) || text.charAt(index) === " ") return true;
22
+ return false;
23
+ }
24
+ function isMarkdownSpace(char) {
25
+ return char === " " || char === " " || char === "\n" || char === "\r";
26
+ }
27
+ function codePointBefore(text, index) {
28
+ if (index <= 0) return "\n";
29
+ const low = text.charCodeAt(index - 1);
30
+ if (index >= 2 && low >= 56320 && low <= 57343) {
31
+ const high = text.charCodeAt(index - 2);
32
+ if (high >= 55296 && high <= 56319) return text.slice(index - 2, index);
33
+ }
34
+ return text.slice(index - 1, index);
35
+ }
36
+ function codePointAt(text, index) {
37
+ if (index >= text.length) return "\n";
38
+ const code = text.codePointAt(index);
39
+ if (code === void 0) return "\n";
40
+ return String.fromCodePoint(code);
41
+ }
42
+ //#endregion
43
+ exports.codePointAt = codePointAt;
44
+ exports.codePointBefore = codePointBefore;
45
+ exports.containsAsciiControlOrSpace = containsAsciiControlOrSpace;
46
+ exports.isAsciiControl = isAsciiControl;
47
+ exports.isAsciiPunctuation = isAsciiPunctuation;
48
+ exports.isMarkdownSpace = isMarkdownSpace;
49
+ exports.isUnicodePunctuation = isUnicodePunctuation;
50
+ exports.isUnicodeWhitespace = isUnicodeWhitespace;
@@ -0,0 +1,11 @@
1
+ //#region src/inline/chars.d.ts
2
+ declare function isAsciiPunctuation(char: string): boolean;
3
+ declare function isUnicodeWhitespace(char: string): boolean;
4
+ declare function isUnicodePunctuation(char: string): boolean;
5
+ declare function isAsciiControl(char: string): boolean;
6
+ declare function containsAsciiControlOrSpace(text: string): boolean;
7
+ declare function isMarkdownSpace(char: string): boolean;
8
+ declare function codePointBefore(text: string, index: number): string;
9
+ declare function codePointAt(text: string, index: number): string;
10
+ //#endregion
11
+ export { codePointAt, codePointBefore, containsAsciiControlOrSpace, isAsciiControl, isAsciiPunctuation, isMarkdownSpace, isUnicodePunctuation, isUnicodeWhitespace };
@@ -0,0 +1,11 @@
1
+ //#region src/inline/chars.d.ts
2
+ declare function isAsciiPunctuation(char: string): boolean;
3
+ declare function isUnicodeWhitespace(char: string): boolean;
4
+ declare function isUnicodePunctuation(char: string): boolean;
5
+ declare function isAsciiControl(char: string): boolean;
6
+ declare function containsAsciiControlOrSpace(text: string): boolean;
7
+ declare function isMarkdownSpace(char: string): boolean;
8
+ declare function codePointBefore(text: string, index: number): string;
9
+ declare function codePointAt(text: string, index: number): string;
10
+ //#endregion
11
+ export { codePointAt, codePointBefore, containsAsciiControlOrSpace, isAsciiControl, isAsciiPunctuation, isMarkdownSpace, isUnicodePunctuation, isUnicodeWhitespace };
@@ -0,0 +1,42 @@
1
+ //#region src/inline/chars.ts
2
+ const ASCII_PUNCTUATION = new Set("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~".split(""));
3
+ function isAsciiPunctuation(char) {
4
+ return ASCII_PUNCTUATION.has(char);
5
+ }
6
+ const UNICODE_WHITESPACE_PATTERN = /^[\p{Zs}\t\n\f\r]$/u;
7
+ function isUnicodeWhitespace(char) {
8
+ return UNICODE_WHITESPACE_PATTERN.test(char);
9
+ }
10
+ const UNICODE_PUNCTUATION_PATTERN = /^[\p{P}\p{S}]$/u;
11
+ function isUnicodePunctuation(char) {
12
+ return UNICODE_PUNCTUATION_PATTERN.test(char);
13
+ }
14
+ function isAsciiControl(char) {
15
+ const code = char.codePointAt(0);
16
+ if (code === void 0) return false;
17
+ return code <= 31 || code === 127;
18
+ }
19
+ function containsAsciiControlOrSpace(text) {
20
+ for (let index = 0; index < text.length; index += 1) if (isAsciiControl(text.charAt(index)) || text.charAt(index) === " ") return true;
21
+ return false;
22
+ }
23
+ function isMarkdownSpace(char) {
24
+ return char === " " || char === " " || char === "\n" || char === "\r";
25
+ }
26
+ function codePointBefore(text, index) {
27
+ if (index <= 0) return "\n";
28
+ const low = text.charCodeAt(index - 1);
29
+ if (index >= 2 && low >= 56320 && low <= 57343) {
30
+ const high = text.charCodeAt(index - 2);
31
+ if (high >= 55296 && high <= 56319) return text.slice(index - 2, index);
32
+ }
33
+ return text.slice(index - 1, index);
34
+ }
35
+ function codePointAt(text, index) {
36
+ if (index >= text.length) return "\n";
37
+ const code = text.codePointAt(index);
38
+ if (code === void 0) return "\n";
39
+ return String.fromCodePoint(code);
40
+ }
41
+ //#endregion
42
+ export { codePointAt, codePointBefore, containsAsciiControlOrSpace, isAsciiControl, isAsciiPunctuation, isMarkdownSpace, isUnicodePunctuation, isUnicodeWhitespace };
@@ -0,0 +1,136 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_inline_chars = require("./chars.cjs");
3
+ //#region src/inline/delimiter.ts
4
+ function isDelimiterChar(char) {
5
+ return char === "*" || char === "_" || char === "~";
6
+ }
7
+ const MAX_STRIKETHROUGH_RUN = 2;
8
+ function scanDelimiterRun(text, start, char) {
9
+ let count = 0;
10
+ while (text.charAt(start + count) === char) count += 1;
11
+ if (count === 0) return;
12
+ if (char === "~" && count > MAX_STRIKETHROUGH_RUN) return;
13
+ const before = require_inline_chars.codePointBefore(text, start);
14
+ const after = require_inline_chars.codePointAt(text, start + count);
15
+ const beforeIsWhitespace = require_inline_chars.isUnicodeWhitespace(before);
16
+ const beforeIsPunctuation = require_inline_chars.isUnicodePunctuation(before);
17
+ const afterIsWhitespace = require_inline_chars.isUnicodeWhitespace(after);
18
+ const afterIsPunctuation = require_inline_chars.isUnicodePunctuation(after);
19
+ const leftFlanking = !afterIsWhitespace && (!afterIsPunctuation || beforeIsWhitespace || beforeIsPunctuation);
20
+ const rightFlanking = !beforeIsWhitespace && (!beforeIsPunctuation || afterIsWhitespace || afterIsPunctuation);
21
+ if (char === "_") return {
22
+ count,
23
+ canOpen: leftFlanking && (!rightFlanking || beforeIsPunctuation),
24
+ canClose: rightFlanking && (!leftFlanking || afterIsPunctuation)
25
+ };
26
+ return {
27
+ count,
28
+ canOpen: leftFlanking,
29
+ canClose: rightFlanking
30
+ };
31
+ }
32
+ var DelimiterStack = class {
33
+ top;
34
+ push(char, run, node) {
35
+ const delimiter = {
36
+ char,
37
+ count: run.count,
38
+ origCount: run.count,
39
+ canOpen: run.canOpen,
40
+ canClose: run.canClose,
41
+ node,
42
+ previous: this.top,
43
+ next: void 0
44
+ };
45
+ if (this.top !== void 0) this.top.next = delimiter;
46
+ this.top = delimiter;
47
+ }
48
+ remove(delimiter) {
49
+ if (delimiter.previous !== void 0) delimiter.previous.next = delimiter.next;
50
+ if (delimiter.next === void 0) this.top = delimiter.previous;
51
+ else delimiter.next.previous = delimiter.previous;
52
+ }
53
+ };
54
+ function closerSignature(closer) {
55
+ return `${closer.char}${closer.canOpen ? "1" : "0"}${String(closer.origCount % 3)}`;
56
+ }
57
+ function isRuleOfThreeBlocked(opener, closer) {
58
+ return (closer.canOpen || opener.canClose) && closer.origCount % 3 !== 0 && (opener.origCount + closer.origCount) % 3 === 0;
59
+ }
60
+ function canMatch(opener, closer) {
61
+ if (opener.char !== closer.char || !opener.canOpen) return false;
62
+ if (closer.char === "~") return opener.count === closer.count;
63
+ return !isRuleOfThreeBlocked(opener, closer);
64
+ }
65
+ function delimitersConsumedByMatch(opener, closer) {
66
+ if (closer.char === "~") return closer.count;
67
+ return closer.count >= 2 && opener.count >= 2 ? 2 : 1;
68
+ }
69
+ function wrapperKindFor(closer, used) {
70
+ if (closer.char === "~") return "strikethrough";
71
+ return used === 1 ? "emphasis" : "strong";
72
+ }
73
+ function processEmphasis(stack, stackBottom, createWrapper) {
74
+ const openersFloor = /* @__PURE__ */ new Map();
75
+ let closer = stack.top;
76
+ while (closer !== void 0 && closer.previous !== stackBottom) closer = closer.previous;
77
+ while (closer !== void 0) {
78
+ if (!closer.canClose) {
79
+ closer = closer.next;
80
+ continue;
81
+ }
82
+ const signature = closerSignature(closer);
83
+ const floor = openersFloor.has(signature) ? openersFloor.get(signature) : stackBottom;
84
+ let opener = closer.previous;
85
+ let matchedOpener;
86
+ while (opener !== void 0 && opener !== stackBottom && opener !== floor) {
87
+ if (canMatch(opener, closer)) {
88
+ matchedOpener = opener;
89
+ break;
90
+ }
91
+ opener = opener.previous;
92
+ }
93
+ const failedCloser = closer;
94
+ if (matchedOpener === void 0) {
95
+ closer = closer.next;
96
+ openersFloor.set(signature, failedCloser.previous);
97
+ if (!failedCloser.canOpen) stack.remove(failedCloser);
98
+ continue;
99
+ }
100
+ const used = delimitersConsumedByMatch(matchedOpener, closer);
101
+ const openerNode = matchedOpener.node;
102
+ const closerNode = closer.node;
103
+ matchedOpener.count -= used;
104
+ closer.count -= used;
105
+ openerNode.literal = openerNode.literal.slice(0, openerNode.literal.length - used);
106
+ closerNode.literal = closerNode.literal.slice(0, closerNode.literal.length - used);
107
+ const wrapper = createWrapper(wrapperKindFor(closer, used), closer.char);
108
+ let moving = openerNode.next;
109
+ while (moving !== void 0 && moving !== closerNode) {
110
+ const following = moving.next;
111
+ wrapper.appendChild(moving);
112
+ moving = following;
113
+ }
114
+ openerNode.insertAfter(wrapper);
115
+ if (matchedOpener.next !== closer) {
116
+ matchedOpener.next = closer;
117
+ closer.previous = matchedOpener;
118
+ }
119
+ if (matchedOpener.count === 0) {
120
+ openerNode.unlink();
121
+ stack.remove(matchedOpener);
122
+ }
123
+ if (closer.count === 0) {
124
+ closerNode.unlink();
125
+ const following = closer.next;
126
+ stack.remove(closer);
127
+ closer = following;
128
+ }
129
+ }
130
+ while (stack.top !== void 0 && stack.top !== stackBottom) stack.remove(stack.top);
131
+ }
132
+ //#endregion
133
+ exports.DelimiterStack = DelimiterStack;
134
+ exports.isDelimiterChar = isDelimiterChar;
135
+ exports.processEmphasis = processEmphasis;
136
+ exports.scanDelimiterRun = scanDelimiterRun;
@@ -0,0 +1,29 @@
1
+ import { InlineNode } from "./node.cjs";
2
+ //#region src/inline/delimiter.d.ts
3
+ type DelimiterChar = '*' | '_' | '~';
4
+ declare function isDelimiterChar(char: string): char is DelimiterChar;
5
+ interface Delimiter {
6
+ readonly char: DelimiterChar;
7
+ count: number;
8
+ readonly origCount: number;
9
+ readonly canOpen: boolean;
10
+ readonly canClose: boolean;
11
+ readonly node: InlineNode;
12
+ previous: Delimiter | undefined;
13
+ next: Delimiter | undefined;
14
+ }
15
+ interface DelimiterRun {
16
+ readonly count: number;
17
+ readonly canOpen: boolean;
18
+ readonly canClose: boolean;
19
+ }
20
+ declare function scanDelimiterRun(text: string, start: number, char: DelimiterChar): DelimiterRun | undefined;
21
+ declare class DelimiterStack {
22
+ top: Delimiter | undefined;
23
+ push(char: DelimiterChar, run: DelimiterRun, node: InlineNode): void;
24
+ remove(delimiter: Delimiter): void;
25
+ }
26
+ type EmphasisWrapperFactory = (kind: 'emphasis' | 'strong' | 'strikethrough', marker: DelimiterChar) => InlineNode;
27
+ declare function processEmphasis(stack: DelimiterStack, stackBottom: Delimiter | undefined, createWrapper: EmphasisWrapperFactory): void;
28
+ //#endregion
29
+ export { Delimiter, DelimiterChar, DelimiterRun, DelimiterStack, EmphasisWrapperFactory, isDelimiterChar, processEmphasis, scanDelimiterRun };
@@ -0,0 +1,29 @@
1
+ import { InlineNode } from "./node.js";
2
+ //#region src/inline/delimiter.d.ts
3
+ type DelimiterChar = '*' | '_' | '~';
4
+ declare function isDelimiterChar(char: string): char is DelimiterChar;
5
+ interface Delimiter {
6
+ readonly char: DelimiterChar;
7
+ count: number;
8
+ readonly origCount: number;
9
+ readonly canOpen: boolean;
10
+ readonly canClose: boolean;
11
+ readonly node: InlineNode;
12
+ previous: Delimiter | undefined;
13
+ next: Delimiter | undefined;
14
+ }
15
+ interface DelimiterRun {
16
+ readonly count: number;
17
+ readonly canOpen: boolean;
18
+ readonly canClose: boolean;
19
+ }
20
+ declare function scanDelimiterRun(text: string, start: number, char: DelimiterChar): DelimiterRun | undefined;
21
+ declare class DelimiterStack {
22
+ top: Delimiter | undefined;
23
+ push(char: DelimiterChar, run: DelimiterRun, node: InlineNode): void;
24
+ remove(delimiter: Delimiter): void;
25
+ }
26
+ type EmphasisWrapperFactory = (kind: 'emphasis' | 'strong' | 'strikethrough', marker: DelimiterChar) => InlineNode;
27
+ declare function processEmphasis(stack: DelimiterStack, stackBottom: Delimiter | undefined, createWrapper: EmphasisWrapperFactory): void;
28
+ //#endregion
29
+ export { Delimiter, DelimiterChar, DelimiterRun, DelimiterStack, EmphasisWrapperFactory, isDelimiterChar, processEmphasis, scanDelimiterRun };