markdown-codec 6.7.4 → 6.7.6
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.
- package/README.md +2 -1
- package/dist/block/block.cjs +19 -37
- package/dist/block/block.js +20 -38
- package/dist/block/definitions.cjs +1 -5
- package/dist/block/definitions.js +1 -5
- package/dist/block/line.cjs +2 -2
- package/dist/block/line.js +2 -2
- package/dist/block/list.cjs +7 -14
- package/dist/block/list.js +7 -14
- package/dist/block/node.cjs +3 -3
- package/dist/block/node.d.cts +2 -2
- package/dist/block/node.d.ts +2 -2
- package/dist/block/node.js +3 -3
- package/dist/block/table.cjs +3 -4
- package/dist/block/table.js +3 -4
- package/dist/codec.d.cts +36 -36
- package/dist/codec.d.ts +36 -36
- package/dist/emit/emit.cjs +58 -62
- package/dist/emit/emit.js +58 -62
- package/dist/emit/inline.cjs +18 -12
- package/dist/emit/inline.js +18 -12
- package/dist/emit/table.cjs +2 -2
- package/dist/emit/table.js +2 -2
- package/dist/html/html-table.cjs +14 -22
- package/dist/html/html-table.js +14 -22
- package/dist/html/html.cjs +0 -2
- package/dist/html/html.js +0 -2
- package/dist/html/render.cjs +3 -11
- package/dist/html/render.js +3 -11
- package/dist/image/image.cjs +8 -57
- package/dist/image/image.d.cts +2 -2
- package/dist/image/image.d.ts +2 -2
- package/dist/image/image.js +9 -56
- package/dist/{image-BtmTG4_a.d.cts → image-83yql5ES.d.cts} +1 -3
- package/dist/{image-BtmTG4_a.d.ts → image-83yql5ES.d.ts} +1 -3
- package/dist/{image-B5L0HpAJ.d.cts → image-B6p0Ovgy.d.cts} +1 -1
- package/dist/{image-C390OIB3.d.ts → image-gR1vISI0.d.ts} +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/inline/chars.cjs +3 -6
- package/dist/inline/chars.js +3 -6
- package/dist/inline/delimiter.cjs +5 -16
- package/dist/inline/delimiter.d.cts +2 -2
- package/dist/inline/delimiter.d.ts +2 -2
- package/dist/inline/delimiter.js +5 -16
- package/dist/inline/entity.cjs +6 -10
- package/dist/inline/entity.js +6 -10
- package/dist/inline/gfm-autolink.cjs +20 -19
- package/dist/inline/gfm-autolink.js +20 -19
- package/dist/inline/inline.cjs +29 -39
- package/dist/inline/inline.js +30 -40
- package/dist/inline/link.cjs +4 -5
- package/dist/inline/link.js +4 -5
- package/dist/lower/front-matter.cjs +4 -8
- package/dist/lower/front-matter.js +4 -8
- package/dist/lower/image.cjs +3 -2
- package/dist/lower/image.d.cts +1 -1
- package/dist/lower/image.d.ts +1 -1
- package/dist/lower/image.js +2 -1
- package/dist/lower/inline.cjs +0 -2
- package/dist/lower/inline.js +0 -2
- package/dist/lower/lower.cjs +7 -10
- package/dist/lower/lower.js +7 -10
- package/dist/options/options.d.cts +1 -1
- package/dist/options/options.d.ts +1 -1
- package/dist/read.cjs +2 -2
- package/dist/read.js +2 -2
- package/dist/scan/scan.cjs +1 -3
- package/dist/scan/scan.js +1 -3
- package/dist/shared/list-id.cjs +1 -1
- package/dist/shared/list-id.js +1 -1
- package/package.json +2 -1
package/dist/html/html-table.js
CHANGED
|
@@ -4,25 +4,21 @@ import { rgbHexToColor } from "document-schema.js";
|
|
|
4
4
|
//#region src/html/html-table.ts
|
|
5
5
|
function findBalancedClose(text, openEnd, tagNames) {
|
|
6
6
|
const names = tagNames.join("|");
|
|
7
|
-
const
|
|
8
|
-
const closePattern = new RegExp(`</(?:${names})\\s*>`, "gi");
|
|
7
|
+
const tagPattern = new RegExp(`</(?:${names})\\s*>|<(?:${names})(?=[\\s/>])`, "gi");
|
|
9
8
|
let depth = 1;
|
|
10
9
|
let pos = openEnd;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
if (openMatch !== null && openMatch.index < closeMatch.index) {
|
|
10
|
+
for (;;) {
|
|
11
|
+
tagPattern.lastIndex = pos;
|
|
12
|
+
const match = tagPattern.exec(text);
|
|
13
|
+
if (match === null) return;
|
|
14
|
+
pos = match.index + match[0].length;
|
|
15
|
+
if (!match[0].startsWith("</")) {
|
|
18
16
|
depth += 1;
|
|
19
|
-
pos = openMatch.index + openMatch[0].length;
|
|
20
17
|
continue;
|
|
21
18
|
}
|
|
22
19
|
depth -= 1;
|
|
23
|
-
pos = closeMatch.index + closeMatch[0].length;
|
|
24
20
|
if (depth === 0) return {
|
|
25
|
-
start:
|
|
21
|
+
start: match.index,
|
|
26
22
|
end: pos
|
|
27
23
|
};
|
|
28
24
|
}
|
|
@@ -36,7 +32,7 @@ function extractTopLevelElements(text, tagNames) {
|
|
|
36
32
|
const match = openPattern.exec(text);
|
|
37
33
|
if (match === null) break;
|
|
38
34
|
if (text.slice(pos, match.index).trim().length > 0) return;
|
|
39
|
-
const attrs = match[1]
|
|
35
|
+
const attrs = match[1];
|
|
40
36
|
const openEnd = match.index + match[0].length;
|
|
41
37
|
const close = findBalancedClose(text, openEnd, tagNames);
|
|
42
38
|
if (close === void 0) return;
|
|
@@ -135,15 +131,15 @@ function parseInlineHtml(text, style) {
|
|
|
135
131
|
pushPlainRun(runs, rest, style);
|
|
136
132
|
return runs;
|
|
137
133
|
}
|
|
138
|
-
pushPlainRun(runs, rest.slice(0, match.index), style);
|
|
139
134
|
const tagName = match[1].toLowerCase();
|
|
140
|
-
const attrs = match[2]
|
|
135
|
+
const attrs = match[2];
|
|
141
136
|
const openEnd = pos + match.index + match[0].length;
|
|
142
137
|
const close = findBalancedClose(text, openEnd, [tagName]);
|
|
143
138
|
if (close === void 0) {
|
|
144
139
|
pushPlainRun(runs, rest, style);
|
|
145
140
|
return runs;
|
|
146
141
|
}
|
|
142
|
+
pushPlainRun(runs, rest.slice(0, match.index), style);
|
|
147
143
|
runs.push(...parseInlineHtml(text.slice(openEnd, close.start), applyTagStyle(style, tagName, attrs)));
|
|
148
144
|
pos = close.end;
|
|
149
145
|
}
|
|
@@ -167,12 +163,10 @@ function parseHtmlImage(piece) {
|
|
|
167
163
|
};
|
|
168
164
|
}
|
|
169
165
|
function parseCellBlocks(inner, contentWidthPt) {
|
|
170
|
-
const
|
|
171
|
-
if (trimmed.length === 0) return [];
|
|
172
|
-
const nestedTable = parseWholeTable(trimmed, contentWidthPt);
|
|
166
|
+
const nestedTable = parseWholeTable(inner, contentWidthPt);
|
|
173
167
|
if (nestedTable !== void 0) return [nestedTable];
|
|
174
168
|
const blocks = [];
|
|
175
|
-
for (const segment of
|
|
169
|
+
for (const segment of inner.split(/<br\s*\/?>/i)) {
|
|
176
170
|
const piece = segment.trim();
|
|
177
171
|
if (piece.length === 0) continue;
|
|
178
172
|
const image = parseHtmlImage(piece);
|
|
@@ -234,9 +228,7 @@ function parseWholeTable(text, contentWidthPt) {
|
|
|
234
228
|
return rows === void 0 ? void 0 : buildContentTable(rows, contentWidthPt);
|
|
235
229
|
}
|
|
236
230
|
function parseHtmlTable(literal, contentWidthPt) {
|
|
237
|
-
|
|
238
|
-
if (!/^<table\b/i.test(trimmed)) return;
|
|
239
|
-
return parseWholeTable(trimmed, contentWidthPt);
|
|
231
|
+
return parseWholeTable(literal, contentWidthPt);
|
|
240
232
|
}
|
|
241
233
|
//#endregion
|
|
242
234
|
export { parseHtmlTable };
|
package/dist/html/html.cjs
CHANGED
|
@@ -5,7 +5,6 @@ const OPEN_TAG = `<${TAG_NAME}(?:\\s+[a-zA-Z_:][a-zA-Z0-9:._-]*(?:\\s*=\\s*(?:[^
|
|
|
5
5
|
const CLOSING_TAG = `</${TAG_NAME}\\s*>`;
|
|
6
6
|
const HTML_TAG_PATTERN = new RegExp(`^(?:${OPEN_TAG}|${CLOSING_TAG}|<!-->|<!--->|<!--[\\s\\S]*?-->|<\\?[\\s\\S]*?\\?>|<![A-Za-z][^>]*>|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>)`);
|
|
7
7
|
function matchHtmlTag(text, start) {
|
|
8
|
-
if (text.charAt(start) !== "<") return;
|
|
9
8
|
const match = HTML_TAG_PATTERN.exec(text.slice(start));
|
|
10
9
|
return match === null ? void 0 : match[0];
|
|
11
10
|
}
|
|
@@ -101,7 +100,6 @@ const HTML_BLOCK_TYPES = [
|
|
|
101
100
|
];
|
|
102
101
|
const LAST_HTML_BLOCK_TYPE = 7;
|
|
103
102
|
function matchHtmlBlockStart(line, interruptsParagraph) {
|
|
104
|
-
if (!line.startsWith("<")) return;
|
|
105
103
|
for (const type of HTML_BLOCK_TYPES) {
|
|
106
104
|
if (type === LAST_HTML_BLOCK_TYPE && interruptsParagraph) continue;
|
|
107
105
|
if (HTML_BLOCK_START_PATTERNS[type]?.test(line) === true) return type;
|
package/dist/html/html.js
CHANGED
|
@@ -4,7 +4,6 @@ const OPEN_TAG = `<${TAG_NAME}(?:\\s+[a-zA-Z_:][a-zA-Z0-9:._-]*(?:\\s*=\\s*(?:[^
|
|
|
4
4
|
const CLOSING_TAG = `</${TAG_NAME}\\s*>`;
|
|
5
5
|
const HTML_TAG_PATTERN = new RegExp(`^(?:${OPEN_TAG}|${CLOSING_TAG}|<!-->|<!--->|<!--[\\s\\S]*?-->|<\\?[\\s\\S]*?\\?>|<![A-Za-z][^>]*>|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>)`);
|
|
6
6
|
function matchHtmlTag(text, start) {
|
|
7
|
-
if (text.charAt(start) !== "<") return;
|
|
8
7
|
const match = HTML_TAG_PATTERN.exec(text.slice(start));
|
|
9
8
|
return match === null ? void 0 : match[0];
|
|
10
9
|
}
|
|
@@ -100,7 +99,6 @@ const HTML_BLOCK_TYPES = [
|
|
|
100
99
|
];
|
|
101
100
|
const LAST_HTML_BLOCK_TYPE = 7;
|
|
102
101
|
function matchHtmlBlockStart(line, interruptsParagraph) {
|
|
103
|
-
if (!line.startsWith("<")) return;
|
|
104
102
|
for (const type of HTML_BLOCK_TYPES) {
|
|
105
103
|
if (type === LAST_HTML_BLOCK_TYPE && interruptsParagraph) continue;
|
|
106
104
|
if (HTML_BLOCK_START_PATTERNS[type]?.test(line) === true) return type;
|
package/dist/html/render.cjs
CHANGED
|
@@ -40,7 +40,7 @@ function escapeHref(href) {
|
|
|
40
40
|
let result = "";
|
|
41
41
|
for (const byte of bytes) {
|
|
42
42
|
const char = String.fromCharCode(byte);
|
|
43
|
-
if (
|
|
43
|
+
if (ALPHANUMERIC_PATTERN.test(char) || HREF_SAFE_PUNCTUATION.has(char)) {
|
|
44
44
|
result += char;
|
|
45
45
|
continue;
|
|
46
46
|
}
|
|
@@ -67,7 +67,7 @@ function renderTaskCheckbox(checked) {
|
|
|
67
67
|
}
|
|
68
68
|
function renderInline(node) {
|
|
69
69
|
switch (node.type) {
|
|
70
|
-
case "text":
|
|
70
|
+
case "text":
|
|
71
71
|
case "entity": return escapeHtml(node.value);
|
|
72
72
|
case "codeSpan": return `<code>${escapeHtml(node.literal)}</code>`;
|
|
73
73
|
case "emphasis": return `<em>${renderInlines(node.children)}</em>`;
|
|
@@ -127,7 +127,6 @@ var HtmlRenderer = class {
|
|
|
127
127
|
this.cr();
|
|
128
128
|
this.out += "<blockquote>\n";
|
|
129
129
|
this.render(node.children, false);
|
|
130
|
-
this.cr();
|
|
131
130
|
this.out += "</blockquote>\n";
|
|
132
131
|
return;
|
|
133
132
|
case "list":
|
|
@@ -139,23 +138,17 @@ var HtmlRenderer = class {
|
|
|
139
138
|
case "mathBlock":
|
|
140
139
|
this.cr();
|
|
141
140
|
this.out += `$$\n${escapeHtml(node.literal)}\n$$\n`;
|
|
142
|
-
this.cr();
|
|
143
141
|
return;
|
|
144
142
|
case "footnoteDefinition":
|
|
145
143
|
this.cr();
|
|
146
144
|
this.out += `${escapeHtml(`[^${node.label}]:`)}\n`;
|
|
147
145
|
this.render(node.children, false);
|
|
148
|
-
this.cr();
|
|
149
146
|
return;
|
|
150
|
-
case "document":
|
|
151
|
-
case "listItem":
|
|
152
|
-
case "tableRow":
|
|
153
|
-
case "tableCell": return;
|
|
154
147
|
}
|
|
155
148
|
}
|
|
156
149
|
renderCodeBlock(infoString, literal) {
|
|
157
150
|
this.cr();
|
|
158
|
-
const language = infoString === void 0 ? "" : infoString.split(/[ \t]/)[0]
|
|
151
|
+
const language = infoString === void 0 ? "" : infoString.split(/[ \t]/)[0];
|
|
159
152
|
const attribute = language.length === 0 ? "" : ` class="language-${escapeHtml(language)}"`;
|
|
160
153
|
this.out += `<pre><code${attribute}>${escapeHtml(literal)}</code></pre>\n`;
|
|
161
154
|
}
|
|
@@ -165,7 +158,6 @@ var HtmlRenderer = class {
|
|
|
165
158
|
const orderedOpenTag = start === DEFAULT_ORDERED_LIST_START ? "<ol>" : `<ol start="${String(start)}">`;
|
|
166
159
|
this.out += `${node.markerType === "bullet" ? "<ul>" : orderedOpenTag}\n`;
|
|
167
160
|
for (const item of node.children) {
|
|
168
|
-
this.cr();
|
|
169
161
|
this.out += "<li>";
|
|
170
162
|
if (item.checked !== void 0) this.out += renderTaskCheckbox(item.checked);
|
|
171
163
|
this.render(item.children, node.tight);
|
package/dist/html/render.js
CHANGED
|
@@ -39,7 +39,7 @@ function escapeHref(href) {
|
|
|
39
39
|
let result = "";
|
|
40
40
|
for (const byte of bytes) {
|
|
41
41
|
const char = String.fromCharCode(byte);
|
|
42
|
-
if (
|
|
42
|
+
if (ALPHANUMERIC_PATTERN.test(char) || HREF_SAFE_PUNCTUATION.has(char)) {
|
|
43
43
|
result += char;
|
|
44
44
|
continue;
|
|
45
45
|
}
|
|
@@ -66,7 +66,7 @@ function renderTaskCheckbox(checked) {
|
|
|
66
66
|
}
|
|
67
67
|
function renderInline(node) {
|
|
68
68
|
switch (node.type) {
|
|
69
|
-
case "text":
|
|
69
|
+
case "text":
|
|
70
70
|
case "entity": return escapeHtml(node.value);
|
|
71
71
|
case "codeSpan": return `<code>${escapeHtml(node.literal)}</code>`;
|
|
72
72
|
case "emphasis": return `<em>${renderInlines(node.children)}</em>`;
|
|
@@ -126,7 +126,6 @@ var HtmlRenderer = class {
|
|
|
126
126
|
this.cr();
|
|
127
127
|
this.out += "<blockquote>\n";
|
|
128
128
|
this.render(node.children, false);
|
|
129
|
-
this.cr();
|
|
130
129
|
this.out += "</blockquote>\n";
|
|
131
130
|
return;
|
|
132
131
|
case "list":
|
|
@@ -138,23 +137,17 @@ var HtmlRenderer = class {
|
|
|
138
137
|
case "mathBlock":
|
|
139
138
|
this.cr();
|
|
140
139
|
this.out += `$$\n${escapeHtml(node.literal)}\n$$\n`;
|
|
141
|
-
this.cr();
|
|
142
140
|
return;
|
|
143
141
|
case "footnoteDefinition":
|
|
144
142
|
this.cr();
|
|
145
143
|
this.out += `${escapeHtml(`[^${node.label}]:`)}\n`;
|
|
146
144
|
this.render(node.children, false);
|
|
147
|
-
this.cr();
|
|
148
145
|
return;
|
|
149
|
-
case "document":
|
|
150
|
-
case "listItem":
|
|
151
|
-
case "tableRow":
|
|
152
|
-
case "tableCell": return;
|
|
153
146
|
}
|
|
154
147
|
}
|
|
155
148
|
renderCodeBlock(infoString, literal) {
|
|
156
149
|
this.cr();
|
|
157
|
-
const language = infoString === void 0 ? "" : infoString.split(/[ \t]/)[0]
|
|
150
|
+
const language = infoString === void 0 ? "" : infoString.split(/[ \t]/)[0];
|
|
158
151
|
const attribute = language.length === 0 ? "" : ` class="language-${escapeHtml(language)}"`;
|
|
159
152
|
this.out += `<pre><code${attribute}>${escapeHtml(literal)}</code></pre>\n`;
|
|
160
153
|
}
|
|
@@ -164,7 +157,6 @@ var HtmlRenderer = class {
|
|
|
164
157
|
const orderedOpenTag = start === DEFAULT_ORDERED_LIST_START ? "<ol>" : `<ol start="${String(start)}">`;
|
|
165
158
|
this.out += `${node.markerType === "bullet" ? "<ul>" : orderedOpenTag}\n`;
|
|
166
159
|
for (const item of node.children) {
|
|
167
|
-
this.cr();
|
|
168
160
|
this.out += "<li>";
|
|
169
161
|
if (item.checked !== void 0) this.out += renderTaskCheckbox(item.checked);
|
|
170
162
|
this.render(item.children, node.tight);
|
package/dist/image/image.cjs
CHANGED
|
@@ -1,52 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/image/image.ts
|
|
3
|
-
const BASE64_TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
4
|
-
const BASE64_DECODE = (() => {
|
|
5
|
-
const map = (/* @__PURE__ */ new Uint8Array(256)).fill(255);
|
|
6
|
-
for (let index = 0; index < 64; index += 1) map[BASE64_TABLE.charCodeAt(index)] = index;
|
|
7
|
-
return map;
|
|
8
|
-
})();
|
|
9
|
-
const BASE64_PADDING_CODE = 61;
|
|
10
|
-
function bytesToBase64(bytes) {
|
|
11
|
-
let out = "";
|
|
12
|
-
const { length } = bytes;
|
|
13
|
-
for (let index = 0; index < length; index += 3) {
|
|
14
|
-
const b0 = bytes[index];
|
|
15
|
-
const b1 = index + 1 < length ? bytes[index + 1] : 0;
|
|
16
|
-
const b2 = index + 2 < length ? bytes[index + 2] : 0;
|
|
17
|
-
out += BASE64_TABLE.charAt(b0 >> 2);
|
|
18
|
-
out += BASE64_TABLE.charAt((b0 & 3) << 4 | b1 >> 4);
|
|
19
|
-
out += index + 1 < length ? BASE64_TABLE.charAt((b1 & 15) << 2 | b2 >> 6) : "=";
|
|
20
|
-
out += index + 2 < length ? BASE64_TABLE.charAt(b2 & 63) : "=";
|
|
21
|
-
}
|
|
22
|
-
return out;
|
|
23
|
-
}
|
|
24
|
-
function base64ToBytes(base64) {
|
|
25
|
-
const clean = base64.replace(/[^A-Za-z0-9+/=]/g, "");
|
|
26
|
-
const { length } = clean;
|
|
27
|
-
const out = new Uint8Array(Math.floor(length * 3 / 4));
|
|
28
|
-
let position = 0;
|
|
29
|
-
for (let index = 0; index < length; index += 4) {
|
|
30
|
-
const c0 = BASE64_DECODE[clean.charCodeAt(index)];
|
|
31
|
-
const c1 = BASE64_DECODE[clean.charCodeAt(index + 1)];
|
|
32
|
-
const code2 = clean.charCodeAt(index + 2);
|
|
33
|
-
const code3 = clean.charCodeAt(index + 3);
|
|
34
|
-
if (c0 === 255 || c1 === 255) throw new Error("invalid base64 input");
|
|
35
|
-
out[position] = c0 << 2 | c1 >> 4;
|
|
36
|
-
position += 1;
|
|
37
|
-
if (code2 !== BASE64_PADDING_CODE) {
|
|
38
|
-
const d2 = BASE64_DECODE[code2];
|
|
39
|
-
out[position] = (c1 & 15) << 4 | d2 >> 2;
|
|
40
|
-
position += 1;
|
|
41
|
-
if (code3 !== BASE64_PADDING_CODE) {
|
|
42
|
-
const d3 = BASE64_DECODE[code3];
|
|
43
|
-
out[position] = (d2 & 3) << 6 | d3;
|
|
44
|
-
position += 1;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return out.subarray(0, position);
|
|
49
|
-
}
|
|
50
3
|
function readUint16BE(bytes, offset) {
|
|
51
4
|
return (bytes[offset] << 8 | bytes[offset + 1]) & 65535;
|
|
52
5
|
}
|
|
@@ -65,9 +18,11 @@ const PNG_SIGNATURE = [
|
|
|
65
18
|
];
|
|
66
19
|
const PNG_HEADER_BYTES = 24;
|
|
67
20
|
function isPng(bytes) {
|
|
68
|
-
if (bytes.length < PNG_SIGNATURE.length) return false;
|
|
69
21
|
return PNG_SIGNATURE.every((byte, index) => bytes[index] === byte);
|
|
70
22
|
}
|
|
23
|
+
function isJpeg(bytes) {
|
|
24
|
+
return bytes[0] === 255 && bytes[1] === 216;
|
|
25
|
+
}
|
|
71
26
|
function readPngDimensions(bytes) {
|
|
72
27
|
if (bytes.length < PNG_HEADER_BYTES) return;
|
|
73
28
|
if (bytes[12] !== 73 || bytes[13] !== 72 || bytes[14] !== 68 || bytes[15] !== 82) return;
|
|
@@ -84,10 +39,12 @@ function hasNoLengthField(marker) {
|
|
|
84
39
|
return marker === 216 || marker === 217 || marker === 1 || marker >= 208 && marker <= 215;
|
|
85
40
|
}
|
|
86
41
|
function readJpegDimensions(bytes) {
|
|
87
|
-
if (bytes
|
|
42
|
+
if (!isJpeg(bytes)) return;
|
|
88
43
|
let offset = 2;
|
|
89
|
-
|
|
90
|
-
|
|
44
|
+
for (;;) {
|
|
45
|
+
const byte = bytes[offset];
|
|
46
|
+
if (byte === void 0) return;
|
|
47
|
+
if (byte !== 255) {
|
|
91
48
|
offset += 1;
|
|
92
49
|
continue;
|
|
93
50
|
}
|
|
@@ -97,7 +54,6 @@ function readJpegDimensions(bytes) {
|
|
|
97
54
|
if (marker === void 0) return;
|
|
98
55
|
offset = markerOffset + 1;
|
|
99
56
|
if (hasNoLengthField(marker)) continue;
|
|
100
|
-
if (offset + 2 > bytes.length) return;
|
|
101
57
|
const length = readUint16BE(bytes, offset);
|
|
102
58
|
if (isStartOfFrameMarker(marker)) {
|
|
103
59
|
if (offset + 7 > bytes.length) return;
|
|
@@ -111,9 +67,6 @@ function readJpegDimensions(bytes) {
|
|
|
111
67
|
offset += length;
|
|
112
68
|
}
|
|
113
69
|
}
|
|
114
|
-
function isJpeg(bytes) {
|
|
115
|
-
return bytes.length >= 2 && bytes[0] === 255 && bytes[1] === 216;
|
|
116
|
-
}
|
|
117
70
|
function detectImageFormat(bytes) {
|
|
118
71
|
if (isPng(bytes)) return "png";
|
|
119
72
|
return isJpeg(bytes) ? "jpeg" : void 0;
|
|
@@ -123,7 +76,5 @@ function readImageDimensions(bytes) {
|
|
|
123
76
|
return readJpegDimensions(bytes);
|
|
124
77
|
}
|
|
125
78
|
//#endregion
|
|
126
|
-
exports.base64ToBytes = base64ToBytes;
|
|
127
|
-
exports.bytesToBase64 = bytesToBase64;
|
|
128
79
|
exports.detectImageFormat = detectImageFormat;
|
|
129
80
|
exports.readImageDimensions = readImageDimensions;
|
package/dist/image/image.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { ImageDimensions, ImageFormat,
|
|
1
|
+
import { i as readImageDimensions, n as ImageFormat, r as detectImageFormat, t as ImageDimensions } from "../image-83yql5ES.cjs";
|
|
2
|
+
export { ImageDimensions, ImageFormat, detectImageFormat, readImageDimensions };
|
package/dist/image/image.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { ImageDimensions, ImageFormat,
|
|
1
|
+
import { i as readImageDimensions, n as ImageFormat, r as detectImageFormat, t as ImageDimensions } from "../image-83yql5ES.js";
|
|
2
|
+
export { ImageDimensions, ImageFormat, detectImageFormat, readImageDimensions };
|
package/dist/image/image.js
CHANGED
|
@@ -1,51 +1,4 @@
|
|
|
1
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.charAt(b0 >> 2);
|
|
17
|
-
out += BASE64_TABLE.charAt((b0 & 3) << 4 | b1 >> 4);
|
|
18
|
-
out += index + 1 < length ? BASE64_TABLE.charAt((b1 & 15) << 2 | b2 >> 6) : "=";
|
|
19
|
-
out += index + 2 < length ? BASE64_TABLE.charAt(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
2
|
function readUint16BE(bytes, offset) {
|
|
50
3
|
return (bytes[offset] << 8 | bytes[offset + 1]) & 65535;
|
|
51
4
|
}
|
|
@@ -64,9 +17,11 @@ const PNG_SIGNATURE = [
|
|
|
64
17
|
];
|
|
65
18
|
const PNG_HEADER_BYTES = 24;
|
|
66
19
|
function isPng(bytes) {
|
|
67
|
-
if (bytes.length < PNG_SIGNATURE.length) return false;
|
|
68
20
|
return PNG_SIGNATURE.every((byte, index) => bytes[index] === byte);
|
|
69
21
|
}
|
|
22
|
+
function isJpeg(bytes) {
|
|
23
|
+
return bytes[0] === 255 && bytes[1] === 216;
|
|
24
|
+
}
|
|
70
25
|
function readPngDimensions(bytes) {
|
|
71
26
|
if (bytes.length < PNG_HEADER_BYTES) return;
|
|
72
27
|
if (bytes[12] !== 73 || bytes[13] !== 72 || bytes[14] !== 68 || bytes[15] !== 82) return;
|
|
@@ -83,10 +38,12 @@ function hasNoLengthField(marker) {
|
|
|
83
38
|
return marker === 216 || marker === 217 || marker === 1 || marker >= 208 && marker <= 215;
|
|
84
39
|
}
|
|
85
40
|
function readJpegDimensions(bytes) {
|
|
86
|
-
if (bytes
|
|
41
|
+
if (!isJpeg(bytes)) return;
|
|
87
42
|
let offset = 2;
|
|
88
|
-
|
|
89
|
-
|
|
43
|
+
for (;;) {
|
|
44
|
+
const byte = bytes[offset];
|
|
45
|
+
if (byte === void 0) return;
|
|
46
|
+
if (byte !== 255) {
|
|
90
47
|
offset += 1;
|
|
91
48
|
continue;
|
|
92
49
|
}
|
|
@@ -96,7 +53,6 @@ function readJpegDimensions(bytes) {
|
|
|
96
53
|
if (marker === void 0) return;
|
|
97
54
|
offset = markerOffset + 1;
|
|
98
55
|
if (hasNoLengthField(marker)) continue;
|
|
99
|
-
if (offset + 2 > bytes.length) return;
|
|
100
56
|
const length = readUint16BE(bytes, offset);
|
|
101
57
|
if (isStartOfFrameMarker(marker)) {
|
|
102
58
|
if (offset + 7 > bytes.length) return;
|
|
@@ -110,9 +66,6 @@ function readJpegDimensions(bytes) {
|
|
|
110
66
|
offset += length;
|
|
111
67
|
}
|
|
112
68
|
}
|
|
113
|
-
function isJpeg(bytes) {
|
|
114
|
-
return bytes.length >= 2 && bytes[0] === 255 && bytes[1] === 216;
|
|
115
|
-
}
|
|
116
69
|
function detectImageFormat(bytes) {
|
|
117
70
|
if (isPng(bytes)) return "png";
|
|
118
71
|
return isJpeg(bytes) ? "jpeg" : void 0;
|
|
@@ -122,4 +75,4 @@ function readImageDimensions(bytes) {
|
|
|
122
75
|
return readJpegDimensions(bytes);
|
|
123
76
|
}
|
|
124
77
|
//#endregion
|
|
125
|
-
export {
|
|
78
|
+
export { detectImageFormat, readImageDimensions };
|
|
@@ -4,9 +4,7 @@ interface ImageDimensions {
|
|
|
4
4
|
readonly heightPx: number;
|
|
5
5
|
}
|
|
6
6
|
type ImageFormat = "png" | "jpeg";
|
|
7
|
-
declare function bytesToBase64(bytes: Uint8Array): string;
|
|
8
|
-
declare function base64ToBytes(base64: string): Uint8Array;
|
|
9
7
|
declare function detectImageFormat(bytes: Uint8Array): ImageFormat | undefined;
|
|
10
8
|
declare function readImageDimensions(bytes: Uint8Array): ImageDimensions | undefined;
|
|
11
9
|
//#endregion
|
|
12
|
-
export {
|
|
10
|
+
export { readImageDimensions as i, ImageFormat as n, detectImageFormat as r, ImageDimensions as t };
|
|
@@ -4,9 +4,7 @@ interface ImageDimensions {
|
|
|
4
4
|
readonly heightPx: number;
|
|
5
5
|
}
|
|
6
6
|
type ImageFormat = "png" | "jpeg";
|
|
7
|
-
declare function bytesToBase64(bytes: Uint8Array): string;
|
|
8
|
-
declare function base64ToBytes(base64: string): Uint8Array;
|
|
9
7
|
declare function detectImageFormat(bytes: Uint8Array): ImageFormat | undefined;
|
|
10
8
|
declare function readImageDimensions(bytes: Uint8Array): ImageDimensions | undefined;
|
|
11
9
|
//#endregion
|
|
12
|
-
export {
|
|
10
|
+
export { readImageDimensions as i, ImageFormat as n, detectImageFormat as r, ImageDimensions as t };
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as MarkdownInputTooLargeError, c as MarkdownNestingLimitExceededError, d as MarkdownUnbalancedConstructMarkersError, f as MarkdownUnsupportedDocumentKindError, i as MarkdownDiagnosticSink, m as NOOP_MARKDOWN_DIAGNOSTIC_SINK, n as MarkdownDiagnosticCodes, o as MarkdownInvalidRunConstructExtentError, p as MarkdownWriteError, r as MarkdownDiagnosticSeverity, s as MarkdownInvalidUtf8Error, t as MarkdownDiagnostic, u as MarkdownParseError } from "./diagnostics-CjfBoW4K.cjs";
|
|
2
2
|
import { MarkdownBytesSchema, markdownCodec, markdownContentCodec } from "./codec.cjs";
|
|
3
|
-
import { n as MarkdownImageResolver, r as MarkdownResolvedImageBytes, t as MarkdownImageResolveContext } from "./image-
|
|
3
|
+
import { n as MarkdownImageResolver, r as MarkdownResolvedImageBytes, t as MarkdownImageResolveContext } from "./image-B6p0Ovgy.cjs";
|
|
4
4
|
import { MarkdownBulletListMarker, MarkdownCodeFenceChar, MarkdownEmphasisMarker, MarkdownHeadingStyle, MarkdownLineEnding, MarkdownOrderedListDelimiter, MarkdownThematicBreakChar, ReadMarkdownOptions, WriteMarkdownOptions, WriteMarkdownStyleOptions } from "./options/options.cjs";
|
|
5
5
|
import { ReadMarkdownContentResult, ReadMarkdownResult, readMarkdown, readMarkdownContent } from "./read.cjs";
|
|
6
6
|
import { writeMarkdown, writeMarkdownContent } from "./write.cjs";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as MarkdownInputTooLargeError, c as MarkdownNestingLimitExceededError, d as MarkdownUnbalancedConstructMarkersError, f as MarkdownUnsupportedDocumentKindError, i as MarkdownDiagnosticSink, m as NOOP_MARKDOWN_DIAGNOSTIC_SINK, n as MarkdownDiagnosticCodes, o as MarkdownInvalidRunConstructExtentError, p as MarkdownWriteError, r as MarkdownDiagnosticSeverity, s as MarkdownInvalidUtf8Error, t as MarkdownDiagnostic, u as MarkdownParseError } from "./diagnostics-CjfBoW4K.js";
|
|
2
2
|
import { MarkdownBytesSchema, markdownCodec, markdownContentCodec } from "./codec.js";
|
|
3
|
-
import { n as MarkdownImageResolver, r as MarkdownResolvedImageBytes, t as MarkdownImageResolveContext } from "./image-
|
|
3
|
+
import { n as MarkdownImageResolver, r as MarkdownResolvedImageBytes, t as MarkdownImageResolveContext } from "./image-gR1vISI0.js";
|
|
4
4
|
import { MarkdownBulletListMarker, MarkdownCodeFenceChar, MarkdownEmphasisMarker, MarkdownHeadingStyle, MarkdownLineEnding, MarkdownOrderedListDelimiter, MarkdownThematicBreakChar, ReadMarkdownOptions, WriteMarkdownOptions, WriteMarkdownStyleOptions } from "./options/options.js";
|
|
5
5
|
import { ReadMarkdownContentResult, ReadMarkdownResult, readMarkdown, readMarkdownContent } from "./read.js";
|
|
6
6
|
import { writeMarkdown, writeMarkdownContent } from "./write.js";
|
package/dist/inline/chars.cjs
CHANGED
|
@@ -18,8 +18,7 @@ function isAsciiControl(char) {
|
|
|
18
18
|
return code <= 31 || code === 127;
|
|
19
19
|
}
|
|
20
20
|
function containsAsciiControlOrSpace(text) {
|
|
21
|
-
|
|
22
|
-
return false;
|
|
21
|
+
return text.split("").some((char) => isAsciiControl(char) || char === " ");
|
|
23
22
|
}
|
|
24
23
|
function isMarkdownSpace(char) {
|
|
25
24
|
return char === " " || char === " " || char === "\n" || char === "\r";
|
|
@@ -27,7 +26,7 @@ function isMarkdownSpace(char) {
|
|
|
27
26
|
function codePointBefore(text, index) {
|
|
28
27
|
if (index <= 0) return "\n";
|
|
29
28
|
const low = text.charCodeAt(index - 1);
|
|
30
|
-
if (
|
|
29
|
+
if (low >= 56320 && low <= 57343) {
|
|
31
30
|
const high = text.charCodeAt(index - 2);
|
|
32
31
|
if (high >= 55296 && high <= 56319) return text.slice(index - 2, index);
|
|
33
32
|
}
|
|
@@ -35,9 +34,7 @@ function codePointBefore(text, index) {
|
|
|
35
34
|
}
|
|
36
35
|
function codePointAt(text, index) {
|
|
37
36
|
if (index >= text.length) return "\n";
|
|
38
|
-
|
|
39
|
-
if (code === void 0) return "\n";
|
|
40
|
-
return String.fromCodePoint(code);
|
|
37
|
+
return String.fromCodePoint(text.codePointAt(index));
|
|
41
38
|
}
|
|
42
39
|
//#endregion
|
|
43
40
|
exports.codePointAt = codePointAt;
|
package/dist/inline/chars.js
CHANGED
|
@@ -17,8 +17,7 @@ function isAsciiControl(char) {
|
|
|
17
17
|
return code <= 31 || code === 127;
|
|
18
18
|
}
|
|
19
19
|
function containsAsciiControlOrSpace(text) {
|
|
20
|
-
|
|
21
|
-
return false;
|
|
20
|
+
return text.split("").some((char) => isAsciiControl(char) || char === " ");
|
|
22
21
|
}
|
|
23
22
|
function isMarkdownSpace(char) {
|
|
24
23
|
return char === " " || char === " " || char === "\n" || char === "\r";
|
|
@@ -26,7 +25,7 @@ function isMarkdownSpace(char) {
|
|
|
26
25
|
function codePointBefore(text, index) {
|
|
27
26
|
if (index <= 0) return "\n";
|
|
28
27
|
const low = text.charCodeAt(index - 1);
|
|
29
|
-
if (
|
|
28
|
+
if (low >= 56320 && low <= 57343) {
|
|
30
29
|
const high = text.charCodeAt(index - 2);
|
|
31
30
|
if (high >= 55296 && high <= 56319) return text.slice(index - 2, index);
|
|
32
31
|
}
|
|
@@ -34,9 +33,7 @@ function codePointBefore(text, index) {
|
|
|
34
33
|
}
|
|
35
34
|
function codePointAt(text, index) {
|
|
36
35
|
if (index >= text.length) return "\n";
|
|
37
|
-
|
|
38
|
-
if (code === void 0) return "\n";
|
|
39
|
-
return String.fromCodePoint(code);
|
|
36
|
+
return String.fromCodePoint(text.codePointAt(index));
|
|
40
37
|
}
|
|
41
38
|
//#endregion
|
|
42
39
|
export { codePointAt, codePointBefore, containsAsciiControlOrSpace, isAsciiControl, isAsciiPunctuation, isMarkdownSpace, isUnicodePunctuation, isUnicodeWhitespace };
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_inline_chars = require("./chars.cjs");
|
|
3
3
|
//#region src/inline/delimiter.ts
|
|
4
|
-
function isDelimiterChar(char) {
|
|
5
|
-
return char === "*" || char === "_" || char === "~";
|
|
6
|
-
}
|
|
7
4
|
const MAX_STRIKETHROUGH_RUN = 2;
|
|
8
5
|
function scanDelimiterRun(text, start, char) {
|
|
9
6
|
let count = 0;
|
|
@@ -63,7 +60,6 @@ function canMatch(opener, closer) {
|
|
|
63
60
|
return !isRuleOfThreeBlocked(opener, closer);
|
|
64
61
|
}
|
|
65
62
|
function delimitersConsumedByMatch(opener, closer) {
|
|
66
|
-
if (closer.char === "~") return closer.count;
|
|
67
63
|
return closer.count >= 2 && opener.count >= 2 ? 2 : 1;
|
|
68
64
|
}
|
|
69
65
|
function wrapperKindFor(closer, used) {
|
|
@@ -83,7 +79,7 @@ function processEmphasis(stack, stackBottom, createWrapper) {
|
|
|
83
79
|
const floor = openersFloor.has(signature) ? openersFloor.get(signature) : stackBottom;
|
|
84
80
|
let opener = closer.previous;
|
|
85
81
|
let matchedOpener;
|
|
86
|
-
while (opener !== void 0 && opener !==
|
|
82
|
+
while (opener !== void 0 && opener !== floor) {
|
|
87
83
|
if (canMatch(opener, closer)) {
|
|
88
84
|
matchedOpener = opener;
|
|
89
85
|
break;
|
|
@@ -94,7 +90,6 @@ function processEmphasis(stack, stackBottom, createWrapper) {
|
|
|
94
90
|
if (matchedOpener === void 0) {
|
|
95
91
|
closer = closer.next;
|
|
96
92
|
openersFloor.set(signature, failedCloser.previous);
|
|
97
|
-
if (!failedCloser.canOpen) stack.remove(failedCloser);
|
|
98
93
|
continue;
|
|
99
94
|
}
|
|
100
95
|
const used = delimitersConsumedByMatch(matchedOpener, closer);
|
|
@@ -112,16 +107,10 @@ function processEmphasis(stack, stackBottom, createWrapper) {
|
|
|
112
107
|
moving = following;
|
|
113
108
|
}
|
|
114
109
|
openerNode.insertAfter(wrapper);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
if (matchedOpener.count === 0) {
|
|
120
|
-
openerNode.unlink();
|
|
121
|
-
stack.remove(matchedOpener);
|
|
122
|
-
}
|
|
110
|
+
matchedOpener.next = closer;
|
|
111
|
+
closer.previous = matchedOpener;
|
|
112
|
+
if (matchedOpener.count === 0) stack.remove(matchedOpener);
|
|
123
113
|
if (closer.count === 0) {
|
|
124
|
-
closerNode.unlink();
|
|
125
114
|
const following = closer.next;
|
|
126
115
|
stack.remove(closer);
|
|
127
116
|
closer = following;
|
|
@@ -131,6 +120,6 @@ function processEmphasis(stack, stackBottom, createWrapper) {
|
|
|
131
120
|
}
|
|
132
121
|
//#endregion
|
|
133
122
|
exports.DelimiterStack = DelimiterStack;
|
|
134
|
-
exports.
|
|
123
|
+
exports.closerSignature = closerSignature;
|
|
135
124
|
exports.processEmphasis = processEmphasis;
|
|
136
125
|
exports.scanDelimiterRun = scanDelimiterRun;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { InlineNode } from "./node.cjs";
|
|
2
2
|
//#region src/inline/delimiter.d.ts
|
|
3
3
|
type DelimiterChar = "*" | "_" | "~";
|
|
4
|
-
declare function isDelimiterChar(char: string): char is DelimiterChar;
|
|
5
4
|
interface Delimiter {
|
|
6
5
|
readonly char: DelimiterChar;
|
|
7
6
|
count: number;
|
|
@@ -23,7 +22,8 @@ declare class DelimiterStack {
|
|
|
23
22
|
push(char: DelimiterChar, run: DelimiterRun, node: InlineNode): void;
|
|
24
23
|
remove(delimiter: Delimiter): void;
|
|
25
24
|
}
|
|
25
|
+
declare function closerSignature(closer: Delimiter): string;
|
|
26
26
|
type EmphasisWrapperFactory = (kind: "emphasis" | "strong" | "strikethrough", marker: DelimiterChar) => InlineNode;
|
|
27
27
|
declare function processEmphasis(stack: DelimiterStack, stackBottom: Delimiter | undefined, createWrapper: EmphasisWrapperFactory): void;
|
|
28
28
|
//#endregion
|
|
29
|
-
export { Delimiter, DelimiterChar, DelimiterRun, DelimiterStack, EmphasisWrapperFactory,
|
|
29
|
+
export { Delimiter, DelimiterChar, DelimiterRun, DelimiterStack, EmphasisWrapperFactory, closerSignature, processEmphasis, scanDelimiterRun };
|