markdown-codec 6.4.3 → 6.5.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.
- package/README.md +20 -7
- package/dist/block/block.cjs +1 -1
- package/dist/block/block.d.cts +1 -1
- package/dist/block/block.d.ts +1 -1
- package/dist/block/block.js +1 -1
- package/dist/block/definitions.d.cts +1 -1
- package/dist/block/definitions.d.ts +1 -1
- package/dist/diagnostics/diagnostics.cjs +2 -1
- package/dist/diagnostics/diagnostics.d.cts +1 -1
- package/dist/diagnostics/diagnostics.d.ts +1 -1
- package/dist/diagnostics/diagnostics.js +2 -1
- package/dist/{diagnostics-eL5c8OWm.d.cts → diagnostics-DLum7kY6.d.cts} +1 -0
- package/dist/{diagnostics-eL5c8OWm.d.ts → diagnostics-DLum7kY6.d.ts} +1 -0
- package/dist/emit/emit.cjs +28 -5
- package/dist/emit/emit.js +28 -5
- package/dist/emit/front-matter.cjs +22 -5
- package/dist/emit/front-matter.js +22 -5
- package/dist/emit/html-table.cjs +104 -0
- package/dist/emit/html-table.d.cts +7 -0
- package/dist/emit/html-table.d.ts +7 -0
- package/dist/emit/html-table.js +102 -0
- package/dist/emit/inline.cjs +30 -6
- package/dist/emit/inline.d.cts +1 -13
- package/dist/emit/inline.d.ts +1 -13
- package/dist/emit/inline.js +30 -6
- package/dist/emit/table.cjs +10 -13
- package/dist/emit/table.d.cts +2 -2
- package/dist/emit/table.d.ts +2 -2
- package/dist/emit/table.js +10 -13
- package/dist/html/html-table.cjs +243 -0
- package/dist/html/html-table.d.cts +5 -0
- package/dist/html/html-table.d.ts +5 -0
- package/dist/html/html-table.js +242 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/inline-2-lUb0vo.d.ts +14 -0
- package/dist/inline-514HW3Pi.d.cts +14 -0
- package/dist/lower/front-matter.cjs +64 -20
- package/dist/lower/front-matter.d.cts +1 -1
- package/dist/lower/front-matter.d.ts +1 -1
- package/dist/lower/front-matter.js +64 -20
- package/dist/lower/inline.d.cts +1 -1
- package/dist/lower/inline.d.ts +1 -1
- package/dist/lower/lower.cjs +16 -5
- package/dist/lower/lower.js +16 -5
- package/dist/options/options.d.cts +1 -1
- package/dist/options/options.d.ts +1 -1
- package/dist/read.d.cts +1 -1
- package/dist/read.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { resolveMarkdownImage } from "../lower/image.js";
|
|
2
|
+
import { MONOSPACE_FONT_FAMILY } from "../shared/style-constants.js";
|
|
3
|
+
import { rgbHexToColor } from "document-schema.js";
|
|
4
|
+
//#region src/html/html-table.ts
|
|
5
|
+
function findBalancedClose(text, openEnd, tagNames) {
|
|
6
|
+
const names = tagNames.join("|");
|
|
7
|
+
const openPattern = new RegExp(`<(?:${names})(?=[\\s/>])`, "gi");
|
|
8
|
+
const closePattern = new RegExp(`</(?:${names})\\s*>`, "gi");
|
|
9
|
+
let depth = 1;
|
|
10
|
+
let pos = openEnd;
|
|
11
|
+
while (depth > 0) {
|
|
12
|
+
openPattern.lastIndex = pos;
|
|
13
|
+
closePattern.lastIndex = pos;
|
|
14
|
+
const openMatch = openPattern.exec(text);
|
|
15
|
+
const closeMatch = closePattern.exec(text);
|
|
16
|
+
if (closeMatch === null) return;
|
|
17
|
+
if (openMatch !== null && openMatch.index < closeMatch.index) {
|
|
18
|
+
depth += 1;
|
|
19
|
+
pos = openMatch.index + openMatch[0].length;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
depth -= 1;
|
|
23
|
+
pos = closeMatch.index + closeMatch[0].length;
|
|
24
|
+
if (depth === 0) return {
|
|
25
|
+
start: closeMatch.index,
|
|
26
|
+
end: pos
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function extractTopLevelElements(text, tagNames) {
|
|
31
|
+
const openPattern = new RegExp(`<(?:${tagNames.join("|")})\\b([^>]*)>`, "gi");
|
|
32
|
+
const elements = [];
|
|
33
|
+
let pos = 0;
|
|
34
|
+
for (;;) {
|
|
35
|
+
openPattern.lastIndex = pos;
|
|
36
|
+
const match = openPattern.exec(text);
|
|
37
|
+
if (match === null) break;
|
|
38
|
+
if (text.slice(pos, match.index).trim().length > 0) return;
|
|
39
|
+
const attrs = match[1] ?? "";
|
|
40
|
+
const openEnd = match.index + match[0].length;
|
|
41
|
+
const close = findBalancedClose(text, openEnd, tagNames);
|
|
42
|
+
if (close === void 0) return;
|
|
43
|
+
elements.push({
|
|
44
|
+
attrs,
|
|
45
|
+
inner: text.slice(openEnd, close.start)
|
|
46
|
+
});
|
|
47
|
+
pos = close.end;
|
|
48
|
+
}
|
|
49
|
+
if (text.slice(pos).trim().length > 0) return;
|
|
50
|
+
return elements;
|
|
51
|
+
}
|
|
52
|
+
function readAttr(attrs, name) {
|
|
53
|
+
return new RegExp(`\\b${name}\\s*=\\s*"([^"]*)"`, "i").exec(attrs)?.[1];
|
|
54
|
+
}
|
|
55
|
+
function readPositiveIntAttr(attrs, name) {
|
|
56
|
+
const raw = readAttr(attrs, name);
|
|
57
|
+
if (raw === void 0) return;
|
|
58
|
+
const value = Number.parseInt(raw, 10);
|
|
59
|
+
return Number.isFinite(value) && value > 0 ? value : void 0;
|
|
60
|
+
}
|
|
61
|
+
const BACKGROUND_COLOR_PATTERN = /background-color\s*:\s*#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})\b/i;
|
|
62
|
+
function readBackgroundFill(attrs) {
|
|
63
|
+
const style = readAttr(attrs, "style");
|
|
64
|
+
if (style === void 0) return;
|
|
65
|
+
const hex = BACKGROUND_COLOR_PATTERN.exec(style)?.[1];
|
|
66
|
+
if (hex === void 0) return;
|
|
67
|
+
const normalised = hex.length === 3 ? hex.split("").map((digit) => digit + digit).join("") : hex;
|
|
68
|
+
return {
|
|
69
|
+
kind: "solid",
|
|
70
|
+
color: rgbHexToColor(normalised)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const TEXT_ALIGN_PATTERN = /text-align\s*:\s*(left|right|center|justify)\b/i;
|
|
74
|
+
function readTextAlign(attrs) {
|
|
75
|
+
const style = readAttr(attrs, "style");
|
|
76
|
+
if (style === void 0) return;
|
|
77
|
+
switch (TEXT_ALIGN_PATTERN.exec(style)?.[1]?.toLowerCase()) {
|
|
78
|
+
case "left": return "left";
|
|
79
|
+
case "right": return "right";
|
|
80
|
+
case "center": return "center";
|
|
81
|
+
case "justify": return "justify";
|
|
82
|
+
default: return;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function unescapeHtml(text) {
|
|
86
|
+
return text.replaceAll("<", "<").replaceAll(">", ">").replaceAll(""", "\"").replaceAll("'", "'").replaceAll("&", "&");
|
|
87
|
+
}
|
|
88
|
+
const INLINE_TAG_PATTERN = /<(a|strong|b|em|i|del|s|strike|code)\b([^>]*)>/i;
|
|
89
|
+
function applyTagStyle(style, tagName, attrs) {
|
|
90
|
+
switch (tagName) {
|
|
91
|
+
case "strong":
|
|
92
|
+
case "b": return {
|
|
93
|
+
...style,
|
|
94
|
+
bold: true
|
|
95
|
+
};
|
|
96
|
+
case "em":
|
|
97
|
+
case "i": return {
|
|
98
|
+
...style,
|
|
99
|
+
italic: true
|
|
100
|
+
};
|
|
101
|
+
case "del":
|
|
102
|
+
case "s":
|
|
103
|
+
case "strike": return {
|
|
104
|
+
...style,
|
|
105
|
+
strike: true
|
|
106
|
+
};
|
|
107
|
+
case "code": return {
|
|
108
|
+
...style,
|
|
109
|
+
fontFamily: MONOSPACE_FONT_FAMILY
|
|
110
|
+
};
|
|
111
|
+
case "a": {
|
|
112
|
+
const href = readAttr(attrs, "href");
|
|
113
|
+
return href === void 0 ? style : {
|
|
114
|
+
...style,
|
|
115
|
+
hyperlink: unescapeHtml(href)
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
default: return style;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function pushPlainRun(runs, text, style) {
|
|
122
|
+
if (text.length === 0) return;
|
|
123
|
+
runs.push({
|
|
124
|
+
text: unescapeHtml(text),
|
|
125
|
+
...style
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function parseInlineHtml(text, style) {
|
|
129
|
+
const runs = [];
|
|
130
|
+
let pos = 0;
|
|
131
|
+
for (;;) {
|
|
132
|
+
const rest = text.slice(pos);
|
|
133
|
+
const match = INLINE_TAG_PATTERN.exec(rest);
|
|
134
|
+
if (match === null) {
|
|
135
|
+
pushPlainRun(runs, rest, style);
|
|
136
|
+
return runs;
|
|
137
|
+
}
|
|
138
|
+
pushPlainRun(runs, rest.slice(0, match.index), style);
|
|
139
|
+
const tagName = match[1].toLowerCase();
|
|
140
|
+
const attrs = match[2] ?? "";
|
|
141
|
+
const openEnd = pos + match.index + match[0].length;
|
|
142
|
+
const close = findBalancedClose(text, openEnd, [tagName]);
|
|
143
|
+
if (close === void 0) {
|
|
144
|
+
pushPlainRun(runs, rest, style);
|
|
145
|
+
return runs;
|
|
146
|
+
}
|
|
147
|
+
runs.push(...parseInlineHtml(text.slice(openEnd, close.start), applyTagStyle(style, tagName, attrs)));
|
|
148
|
+
pos = close.end;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const IMG_TAG_PATTERN = /^<img\b([^>]*?)\/?>$/i;
|
|
152
|
+
function parseHtmlImage(piece) {
|
|
153
|
+
const attrs = IMG_TAG_PATTERN.exec(piece)?.[1];
|
|
154
|
+
if (attrs === void 0) return;
|
|
155
|
+
const src = readAttr(attrs, "src");
|
|
156
|
+
if (src === void 0) return;
|
|
157
|
+
const alt = unescapeHtml(readAttr(attrs, "alt") ?? "");
|
|
158
|
+
const resolved = resolveMarkdownImage(src, { alt }, void 0);
|
|
159
|
+
if (resolved === void 0) return;
|
|
160
|
+
return {
|
|
161
|
+
kind: "image",
|
|
162
|
+
format: resolved.format,
|
|
163
|
+
base64: resolved.base64,
|
|
164
|
+
widthPt: resolved.widthPt,
|
|
165
|
+
heightPt: resolved.heightPt,
|
|
166
|
+
altText: alt
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function parseCellBlocks(inner, contentWidthPt) {
|
|
170
|
+
const trimmed = inner.trim();
|
|
171
|
+
if (trimmed.length === 0) return [];
|
|
172
|
+
const nestedTable = parseWholeTable(trimmed, contentWidthPt);
|
|
173
|
+
if (nestedTable !== void 0) return [nestedTable];
|
|
174
|
+
const blocks = [];
|
|
175
|
+
for (const segment of trimmed.split(/<br\s*\/?>/i)) {
|
|
176
|
+
const piece = segment.trim();
|
|
177
|
+
if (piece.length === 0) continue;
|
|
178
|
+
const image = parseHtmlImage(piece);
|
|
179
|
+
blocks.push(image ?? {
|
|
180
|
+
kind: "paragraph",
|
|
181
|
+
runs: parseInlineHtml(piece, {})
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return blocks;
|
|
185
|
+
}
|
|
186
|
+
function applyTextAlign(blocks, alignment) {
|
|
187
|
+
const first = blocks[0];
|
|
188
|
+
if (alignment === void 0 || first?.kind !== "paragraph") return blocks;
|
|
189
|
+
return [{
|
|
190
|
+
...first,
|
|
191
|
+
alignment
|
|
192
|
+
}, ...blocks.slice(1)];
|
|
193
|
+
}
|
|
194
|
+
function buildCell(cell, contentWidthPt) {
|
|
195
|
+
const colSpan = readPositiveIntAttr(cell.attrs, "colspan");
|
|
196
|
+
const rowSpan = readPositiveIntAttr(cell.attrs, "rowspan");
|
|
197
|
+
const background = readBackgroundFill(cell.attrs);
|
|
198
|
+
const textAlign = readTextAlign(cell.attrs);
|
|
199
|
+
const parsedBlocks = parseCellBlocks(cell.inner, contentWidthPt);
|
|
200
|
+
return {
|
|
201
|
+
blocks: applyTextAlign(parsedBlocks.length > 0 ? parsedBlocks : [{
|
|
202
|
+
kind: "paragraph",
|
|
203
|
+
runs: []
|
|
204
|
+
}], textAlign),
|
|
205
|
+
...colSpan === void 0 ? {} : { colSpan },
|
|
206
|
+
...rowSpan === void 0 ? {} : { rowSpan },
|
|
207
|
+
...background === void 0 ? {} : { background }
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function parseTableRows(inner, contentWidthPt) {
|
|
211
|
+
const rowElements = extractTopLevelElements(inner, ["tr"]);
|
|
212
|
+
if (rowElements === void 0 || rowElements.length === 0) return;
|
|
213
|
+
const rows = [];
|
|
214
|
+
for (const row of rowElements) {
|
|
215
|
+
const cellElements = extractTopLevelElements(row.inner, ["td", "th"]);
|
|
216
|
+
if (cellElements === void 0 || cellElements.length === 0) return;
|
|
217
|
+
rows.push({ cells: cellElements.map((cell) => buildCell(cell, contentWidthPt)) });
|
|
218
|
+
}
|
|
219
|
+
return rows;
|
|
220
|
+
}
|
|
221
|
+
function buildContentTable(rows, contentWidthPt) {
|
|
222
|
+
const header = rows[0];
|
|
223
|
+
const columnCount = Math.max(1, header.cells.reduce((sum, cell) => sum + (cell.colSpan ?? 1), 0));
|
|
224
|
+
return {
|
|
225
|
+
kind: "table",
|
|
226
|
+
rows,
|
|
227
|
+
columnWidthsPt: Array.from({ length: columnCount }, () => contentWidthPt / columnCount)
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function parseWholeTable(text, contentWidthPt) {
|
|
231
|
+
const tableElements = extractTopLevelElements(text, ["table"]);
|
|
232
|
+
if (tableElements?.length !== 1) return;
|
|
233
|
+
const rows = parseTableRows(tableElements[0].inner, contentWidthPt);
|
|
234
|
+
return rows === void 0 ? void 0 : buildContentTable(rows, contentWidthPt);
|
|
235
|
+
}
|
|
236
|
+
function parseHtmlTable(literal, contentWidthPt) {
|
|
237
|
+
const trimmed = literal.trim();
|
|
238
|
+
if (!/^<table\b/i.test(trimmed)) return;
|
|
239
|
+
return parseWholeTable(trimmed, contentWidthPt);
|
|
240
|
+
}
|
|
241
|
+
//#endregion
|
|
242
|
+
export { parseHtmlTable };
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_diagnostics_diagnostics = require("./diagnostics/diagnostics.cjs");
|
|
3
|
-
const require_shared_list_id = require("./shared/list-id.cjs");
|
|
4
3
|
const require_shared_style_constants = require("./shared/style-constants.cjs");
|
|
4
|
+
const require_shared_list_id = require("./shared/list-id.cjs");
|
|
5
5
|
const require_read = require("./read.cjs");
|
|
6
6
|
const require_write = require("./write.cjs");
|
|
7
7
|
const require_codec = require("./codec.cjs");
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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-DLum7kY6.cjs";
|
|
2
2
|
import { MarkdownBytesSchema, markdownCodec, markdownContentCodec } from "./codec.cjs";
|
|
3
3
|
import { n as MarkdownImageResolver, r as MarkdownResolvedImageBytes, t as MarkdownImageResolveContext } from "./image-B5L0HpAJ.cjs";
|
|
4
4
|
import { MarkdownBulletListMarker, MarkdownCodeFenceChar, MarkdownEmphasisMarker, MarkdownHeadingStyle, MarkdownLineEnding, MarkdownOrderedListDelimiter, MarkdownThematicBreakChar, ReadMarkdownOptions, WriteMarkdownOptions, WriteMarkdownStyleOptions } from "./options/options.cjs";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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-DLum7kY6.js";
|
|
2
2
|
import { MarkdownBytesSchema, markdownCodec, markdownContentCodec } from "./codec.js";
|
|
3
3
|
import { n as MarkdownImageResolver, r as MarkdownResolvedImageBytes, t as MarkdownImageResolveContext } from "./image-C390OIB3.js";
|
|
4
4
|
import { MarkdownBulletListMarker, MarkdownCodeFenceChar, MarkdownEmphasisMarker, MarkdownHeadingStyle, MarkdownLineEnding, MarkdownOrderedListDelimiter, MarkdownThematicBreakChar, ReadMarkdownOptions, WriteMarkdownOptions, WriteMarkdownStyleOptions } from "./options/options.js";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MarkdownDiagnosticCodes, MarkdownInputTooLargeError, MarkdownInvalidRunConstructExtentError, MarkdownInvalidUtf8Error, MarkdownNestingLimitExceededError, MarkdownParseError, MarkdownUnbalancedConstructMarkersError, MarkdownUnsupportedDocumentKindError, MarkdownWriteError, NOOP_MARKDOWN_DIAGNOSTIC_SINK } from "./diagnostics/diagnostics.js";
|
|
2
|
-
import { createNumIdMintState, mintListNumId, mintedListType, parseListNumId } from "./shared/list-id.js";
|
|
3
2
|
import { CODE_BLOCK_STYLE_ID, HORIZONTAL_RULE_STYLE_ID, HTML_PREFORMATTED_STYLE_ID, MAX_HEADING_STYLE_LEVEL, MONOSPACE_FONT_FAMILY, QUOTE_INDENT_PT, QUOTE_STYLE_ID, headingStyleId, parseHeadingStyleId } from "./shared/style-constants.js";
|
|
3
|
+
import { createNumIdMintState, mintListNumId, mintedListType, parseListNumId } from "./shared/list-id.js";
|
|
4
4
|
import { readMarkdown, readMarkdownContent } from "./read.js";
|
|
5
5
|
import { writeMarkdown, writeMarkdownContent } from "./write.js";
|
|
6
6
|
import { MarkdownBytesSchema, markdownCodec, markdownContentCodec } from "./codec.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { i as MarkdownDiagnosticSink } from "./diagnostics-DLum7kY6.js";
|
|
2
|
+
import { ContentRun, RunConstructExtent } from "document-schema.js";
|
|
3
|
+
//#region src/emit/inline.d.ts
|
|
4
|
+
interface InlineEmitContext {
|
|
5
|
+
readonly sink: MarkdownDiagnosticSink;
|
|
6
|
+
readonly emphasisMarker: string;
|
|
7
|
+
}
|
|
8
|
+
declare function escapeMarkdownText(text: string): string;
|
|
9
|
+
declare function escapeLinkDestination(destination: string): string;
|
|
10
|
+
declare function renderLinkTitle(title: string): string;
|
|
11
|
+
declare function emitRuns(runs: readonly ContentRun[], context: InlineEmitContext, constructs?: readonly RunConstructExtent[]): string;
|
|
12
|
+
declare function emitRunsSingleLine(runs: readonly ContentRun[], context: InlineEmitContext, constructs?: readonly RunConstructExtent[]): string;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { escapeMarkdownText as a, escapeLinkDestination as i, emitRuns as n, renderLinkTitle as o, emitRunsSingleLine as r, InlineEmitContext as t };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { i as MarkdownDiagnosticSink } from "./diagnostics-DLum7kY6.cjs";
|
|
2
|
+
import { ContentRun, RunConstructExtent } from "document-schema.js";
|
|
3
|
+
//#region src/emit/inline.d.ts
|
|
4
|
+
interface InlineEmitContext {
|
|
5
|
+
readonly sink: MarkdownDiagnosticSink;
|
|
6
|
+
readonly emphasisMarker: string;
|
|
7
|
+
}
|
|
8
|
+
declare function escapeMarkdownText(text: string): string;
|
|
9
|
+
declare function escapeLinkDestination(destination: string): string;
|
|
10
|
+
declare function renderLinkTitle(title: string): string;
|
|
11
|
+
declare function emitRuns(runs: readonly ContentRun[], context: InlineEmitContext, constructs?: readonly RunConstructExtent[]): string;
|
|
12
|
+
declare function emitRunsSingleLine(runs: readonly ContentRun[], context: InlineEmitContext, constructs?: readonly RunConstructExtent[]): string;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { escapeMarkdownText as a, escapeLinkDestination as i, emitRuns as n, renderLinkTitle as o, emitRunsSingleLine as r, InlineEmitContext as t };
|
|
@@ -5,6 +5,56 @@ const require_shared_line_ending = require("../shared/line-ending.cjs");
|
|
|
5
5
|
const LEADING_DELIMITER_PATTERN = /^---[ \t]*$/;
|
|
6
6
|
const CLOSING_DELIMITER_PATTERN = /^(?:---|\.\.\.)[ \t]*$/;
|
|
7
7
|
const KEY_VALUE_LINE_PATTERN = /^([A-Za-z_][A-Za-z0-9_-]*):[ \t]*(.*)$/;
|
|
8
|
+
const STRING_FIELD_SETTERS = {
|
|
9
|
+
title: (metadata, value) => {
|
|
10
|
+
metadata.title = value;
|
|
11
|
+
},
|
|
12
|
+
author: (metadata, value) => {
|
|
13
|
+
metadata.author = value;
|
|
14
|
+
},
|
|
15
|
+
subject: (metadata, value) => {
|
|
16
|
+
metadata.subject = value;
|
|
17
|
+
},
|
|
18
|
+
creator: (metadata, value) => {
|
|
19
|
+
metadata.creator = value;
|
|
20
|
+
},
|
|
21
|
+
date: (metadata, value) => {
|
|
22
|
+
metadata.createdIso = value;
|
|
23
|
+
},
|
|
24
|
+
modified: (metadata, value) => {
|
|
25
|
+
metadata.modifiedIso = value;
|
|
26
|
+
},
|
|
27
|
+
lastPrinted: (metadata, value) => {
|
|
28
|
+
metadata.lastPrintedIso = value;
|
|
29
|
+
},
|
|
30
|
+
language: (metadata, value) => {
|
|
31
|
+
metadata.language = value;
|
|
32
|
+
},
|
|
33
|
+
publisher: (metadata, value) => {
|
|
34
|
+
metadata.publisher = value;
|
|
35
|
+
},
|
|
36
|
+
contributor: (metadata, value) => {
|
|
37
|
+
metadata.contributor = value;
|
|
38
|
+
},
|
|
39
|
+
rights: (metadata, value) => {
|
|
40
|
+
metadata.rights = value;
|
|
41
|
+
},
|
|
42
|
+
identifier: (metadata, value) => {
|
|
43
|
+
metadata.identifier = value;
|
|
44
|
+
},
|
|
45
|
+
comments: (metadata, value) => {
|
|
46
|
+
metadata.comments = value;
|
|
47
|
+
},
|
|
48
|
+
company: (metadata, value) => {
|
|
49
|
+
metadata.company = value;
|
|
50
|
+
},
|
|
51
|
+
manager: (metadata, value) => {
|
|
52
|
+
metadata.manager = value;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
function isTextDirection(value) {
|
|
56
|
+
return value === "ltr" || value === "rtl";
|
|
57
|
+
}
|
|
8
58
|
function parseScalar(raw) {
|
|
9
59
|
const trimmed = raw.trim();
|
|
10
60
|
const isDoubleQuoted = trimmed.length >= 2 && trimmed.startsWith("\"") && trimmed.endsWith("\"");
|
|
@@ -41,32 +91,26 @@ function extractFrontMatter(source, sink = require_diagnostics_diagnostics.NOOP_
|
|
|
41
91
|
const key = match?.[1];
|
|
42
92
|
const value = match?.[2];
|
|
43
93
|
if (key === void 0 || value === void 0) continue;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
break;
|
|
57
|
-
case "date":
|
|
58
|
-
metadata.createdIso = parseScalar(value);
|
|
59
|
-
break;
|
|
60
|
-
case "keywords":
|
|
61
|
-
metadata.keywords = [...parseKeywordList(value)];
|
|
62
|
-
break;
|
|
63
|
-
default: sink({
|
|
94
|
+
if (key === "keywords") {
|
|
95
|
+
metadata.keywords = [...parseKeywordList(value)];
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (key === "direction") {
|
|
99
|
+
const scalar = parseScalar(value);
|
|
100
|
+
if (isTextDirection(scalar)) metadata.direction = scalar;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const setter = STRING_FIELD_SETTERS[key];
|
|
104
|
+
if (setter === void 0) {
|
|
105
|
+
sink({
|
|
64
106
|
code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.FRONT_MATTER_KEY_UNMAPPED,
|
|
65
107
|
severity: "info",
|
|
66
108
|
message: `front matter key "${key}" has no LayoutMetadata equivalent and was dropped from the metadata; its original spelling survives in the verbatim front-matter block this package's own writer can re-emit`,
|
|
67
109
|
line: index + 1
|
|
68
110
|
});
|
|
111
|
+
continue;
|
|
69
112
|
}
|
|
113
|
+
setter(metadata, parseScalar(value));
|
|
70
114
|
}
|
|
71
115
|
return {
|
|
72
116
|
metadata,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as MarkdownDiagnosticSink } from "../diagnostics-
|
|
1
|
+
import { i as MarkdownDiagnosticSink } from "../diagnostics-DLum7kY6.cjs";
|
|
2
2
|
import { LayoutMetadata } from "document-schema.js";
|
|
3
3
|
//#region src/lower/front-matter.d.ts
|
|
4
4
|
interface FrontMatterResult {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as MarkdownDiagnosticSink } from "../diagnostics-
|
|
1
|
+
import { i as MarkdownDiagnosticSink } from "../diagnostics-DLum7kY6.js";
|
|
2
2
|
import { LayoutMetadata } from "document-schema.js";
|
|
3
3
|
//#region src/lower/front-matter.d.ts
|
|
4
4
|
interface FrontMatterResult {
|
|
@@ -4,6 +4,56 @@ import { LINE_ENDING_PATTERN } from "../shared/line-ending.js";
|
|
|
4
4
|
const LEADING_DELIMITER_PATTERN = /^---[ \t]*$/;
|
|
5
5
|
const CLOSING_DELIMITER_PATTERN = /^(?:---|\.\.\.)[ \t]*$/;
|
|
6
6
|
const KEY_VALUE_LINE_PATTERN = /^([A-Za-z_][A-Za-z0-9_-]*):[ \t]*(.*)$/;
|
|
7
|
+
const STRING_FIELD_SETTERS = {
|
|
8
|
+
title: (metadata, value) => {
|
|
9
|
+
metadata.title = value;
|
|
10
|
+
},
|
|
11
|
+
author: (metadata, value) => {
|
|
12
|
+
metadata.author = value;
|
|
13
|
+
},
|
|
14
|
+
subject: (metadata, value) => {
|
|
15
|
+
metadata.subject = value;
|
|
16
|
+
},
|
|
17
|
+
creator: (metadata, value) => {
|
|
18
|
+
metadata.creator = value;
|
|
19
|
+
},
|
|
20
|
+
date: (metadata, value) => {
|
|
21
|
+
metadata.createdIso = value;
|
|
22
|
+
},
|
|
23
|
+
modified: (metadata, value) => {
|
|
24
|
+
metadata.modifiedIso = value;
|
|
25
|
+
},
|
|
26
|
+
lastPrinted: (metadata, value) => {
|
|
27
|
+
metadata.lastPrintedIso = value;
|
|
28
|
+
},
|
|
29
|
+
language: (metadata, value) => {
|
|
30
|
+
metadata.language = value;
|
|
31
|
+
},
|
|
32
|
+
publisher: (metadata, value) => {
|
|
33
|
+
metadata.publisher = value;
|
|
34
|
+
},
|
|
35
|
+
contributor: (metadata, value) => {
|
|
36
|
+
metadata.contributor = value;
|
|
37
|
+
},
|
|
38
|
+
rights: (metadata, value) => {
|
|
39
|
+
metadata.rights = value;
|
|
40
|
+
},
|
|
41
|
+
identifier: (metadata, value) => {
|
|
42
|
+
metadata.identifier = value;
|
|
43
|
+
},
|
|
44
|
+
comments: (metadata, value) => {
|
|
45
|
+
metadata.comments = value;
|
|
46
|
+
},
|
|
47
|
+
company: (metadata, value) => {
|
|
48
|
+
metadata.company = value;
|
|
49
|
+
},
|
|
50
|
+
manager: (metadata, value) => {
|
|
51
|
+
metadata.manager = value;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
function isTextDirection(value) {
|
|
55
|
+
return value === "ltr" || value === "rtl";
|
|
56
|
+
}
|
|
7
57
|
function parseScalar(raw) {
|
|
8
58
|
const trimmed = raw.trim();
|
|
9
59
|
const isDoubleQuoted = trimmed.length >= 2 && trimmed.startsWith("\"") && trimmed.endsWith("\"");
|
|
@@ -40,32 +90,26 @@ function extractFrontMatter(source, sink = NOOP_MARKDOWN_DIAGNOSTIC_SINK) {
|
|
|
40
90
|
const key = match?.[1];
|
|
41
91
|
const value = match?.[2];
|
|
42
92
|
if (key === void 0 || value === void 0) continue;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
break;
|
|
56
|
-
case "date":
|
|
57
|
-
metadata.createdIso = parseScalar(value);
|
|
58
|
-
break;
|
|
59
|
-
case "keywords":
|
|
60
|
-
metadata.keywords = [...parseKeywordList(value)];
|
|
61
|
-
break;
|
|
62
|
-
default: sink({
|
|
93
|
+
if (key === "keywords") {
|
|
94
|
+
metadata.keywords = [...parseKeywordList(value)];
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (key === "direction") {
|
|
98
|
+
const scalar = parseScalar(value);
|
|
99
|
+
if (isTextDirection(scalar)) metadata.direction = scalar;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const setter = STRING_FIELD_SETTERS[key];
|
|
103
|
+
if (setter === void 0) {
|
|
104
|
+
sink({
|
|
63
105
|
code: MarkdownDiagnosticCodes.FRONT_MATTER_KEY_UNMAPPED,
|
|
64
106
|
severity: "info",
|
|
65
107
|
message: `front matter key "${key}" has no LayoutMetadata equivalent and was dropped from the metadata; its original spelling survives in the verbatim front-matter block this package's own writer can re-emit`,
|
|
66
108
|
line: index + 1
|
|
67
109
|
});
|
|
110
|
+
continue;
|
|
68
111
|
}
|
|
112
|
+
setter(metadata, parseScalar(value));
|
|
69
113
|
}
|
|
70
114
|
return {
|
|
71
115
|
metadata,
|
package/dist/lower/inline.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { v as MarkdownInlineNode } from "../ast-CNfTgS0N.cjs";
|
|
2
|
-
import { i as MarkdownDiagnosticSink } from "../diagnostics-
|
|
2
|
+
import { i as MarkdownDiagnosticSink } from "../diagnostics-DLum7kY6.cjs";
|
|
3
3
|
import { ContentRun, RunConstructExtent } from "document-schema.js";
|
|
4
4
|
//#region src/lower/inline.d.ts
|
|
5
5
|
interface InlineLowerContext {
|
package/dist/lower/inline.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { v as MarkdownInlineNode } from "../ast-CNfTgS0N.js";
|
|
2
|
-
import { i as MarkdownDiagnosticSink } from "../diagnostics-
|
|
2
|
+
import { i as MarkdownDiagnosticSink } from "../diagnostics-DLum7kY6.js";
|
|
3
3
|
import { ContentRun, RunConstructExtent } from "document-schema.js";
|
|
4
4
|
//#region src/lower/inline.d.ts
|
|
5
5
|
interface InlineLowerContext {
|
package/dist/lower/lower.cjs
CHANGED
|
@@ -2,10 +2,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_defaults_defaults = require("../defaults/defaults.cjs");
|
|
3
3
|
const require_diagnostics_diagnostics = require("../diagnostics/diagnostics.cjs");
|
|
4
4
|
const require_block_block = require("../block/block.cjs");
|
|
5
|
-
const
|
|
5
|
+
const require_lower_image = require("./image.cjs");
|
|
6
6
|
const require_shared_style_constants = require("../shared/style-constants.cjs");
|
|
7
|
+
const require_html_html_table = require("../html/html-table.cjs");
|
|
8
|
+
const require_shared_list_id = require("../shared/list-id.cjs");
|
|
7
9
|
const require_lower_front_matter = require("./front-matter.cjs");
|
|
8
|
-
const require_lower_image = require("./image.cjs");
|
|
9
10
|
const require_lower_inline = require("./inline.cjs");
|
|
10
11
|
const require_lower_table = require("./table.cjs");
|
|
11
12
|
let document_schema_js = require("document-schema.js");
|
|
@@ -152,7 +153,16 @@ function lowerThematicBreak(context) {
|
|
|
152
153
|
styleId: require_shared_style_constants.HORIZONTAL_RULE_STYLE_ID
|
|
153
154
|
}, context)];
|
|
154
155
|
}
|
|
155
|
-
function lowerHtmlBlock(node, context) {
|
|
156
|
+
function lowerHtmlBlock(node, context, contentWidthPt) {
|
|
157
|
+
const table = context.gfmTables ? require_html_html_table.parseHtmlTable(node.literal, contentWidthPt) : void 0;
|
|
158
|
+
if (table !== void 0) {
|
|
159
|
+
if (context.list !== void 0) context.sink({
|
|
160
|
+
code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.LIST_ITEM_BLOCK_UNLISTED,
|
|
161
|
+
severity: "info",
|
|
162
|
+
message: "an HTML-table block directly inside a list item has no ContentListMembership field of its own -- only ContentParagraph carries .list -- so its association with the enclosing list item is lost"
|
|
163
|
+
});
|
|
164
|
+
return [table];
|
|
165
|
+
}
|
|
156
166
|
if (context.rawHtmlMode === "drop") {
|
|
157
167
|
context.sink({
|
|
158
168
|
code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.RAW_HTML_DROPPED,
|
|
@@ -350,7 +360,7 @@ function lowerBlock(node, context, contentWidthPt) {
|
|
|
350
360
|
case "list": return lowerList(node, void 0, 0, context, contentWidthPt);
|
|
351
361
|
case "codeBlock": return lowerCodeBlock(node, context);
|
|
352
362
|
case "thematicBreak": return lowerThematicBreak(context);
|
|
353
|
-
case "htmlBlock": return lowerHtmlBlock(node, context);
|
|
363
|
+
case "htmlBlock": return lowerHtmlBlock(node, context, contentWidthPt);
|
|
354
364
|
case "mathBlock": return lowerMathBlock(node, context);
|
|
355
365
|
case "footnoteDefinition": return lowerFootnoteDefinition(node, context, contentWidthPt);
|
|
356
366
|
case "table":
|
|
@@ -382,7 +392,8 @@ function lowerParsedMarkdown(parsed, options = {}, metadata = {}) {
|
|
|
382
392
|
rawHtmlMode: options.rawHtml ?? "preserve",
|
|
383
393
|
numIdState: require_shared_list_id.createNumIdMintState(),
|
|
384
394
|
quoteDepth: 0,
|
|
385
|
-
list: void 0
|
|
395
|
+
list: void 0,
|
|
396
|
+
gfmTables: options.gfmTables ?? true
|
|
386
397
|
};
|
|
387
398
|
return {
|
|
388
399
|
kind: "wordprocessing",
|
package/dist/lower/lower.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { DEFAULT_MARGINS } from "../defaults/defaults.js";
|
|
2
2
|
import { MarkdownDiagnosticCodes, MarkdownInputTooLargeError, NOOP_MARKDOWN_DIAGNOSTIC_SINK } from "../diagnostics/diagnostics.js";
|
|
3
3
|
import { parseMarkdown } from "../block/block.js";
|
|
4
|
-
import {
|
|
4
|
+
import { resolveMarkdownImage } from "./image.js";
|
|
5
5
|
import { CODE_BLOCK_STYLE_ID, HORIZONTAL_RULE_STYLE_ID, HTML_PREFORMATTED_STYLE_ID, QUOTE_STYLE_ID, headingStyleId } from "../shared/style-constants.js";
|
|
6
|
+
import { parseHtmlTable } from "../html/html-table.js";
|
|
7
|
+
import { createNumIdMintState, mintListItemId, mintListNumId, mintedListType } from "../shared/list-id.js";
|
|
6
8
|
import { extractFrontMatter } from "./front-matter.js";
|
|
7
|
-
import { resolveMarkdownImage } from "./image.js";
|
|
8
9
|
import { lowerCodeBlockRun, lowerInlineNodes } from "./inline.js";
|
|
9
10
|
import { lowerTable } from "./table.js";
|
|
10
11
|
import { PAGE_SIZE_A4 } from "document-schema.js";
|
|
@@ -151,7 +152,16 @@ function lowerThematicBreak(context) {
|
|
|
151
152
|
styleId: HORIZONTAL_RULE_STYLE_ID
|
|
152
153
|
}, context)];
|
|
153
154
|
}
|
|
154
|
-
function lowerHtmlBlock(node, context) {
|
|
155
|
+
function lowerHtmlBlock(node, context, contentWidthPt) {
|
|
156
|
+
const table = context.gfmTables ? parseHtmlTable(node.literal, contentWidthPt) : void 0;
|
|
157
|
+
if (table !== void 0) {
|
|
158
|
+
if (context.list !== void 0) context.sink({
|
|
159
|
+
code: MarkdownDiagnosticCodes.LIST_ITEM_BLOCK_UNLISTED,
|
|
160
|
+
severity: "info",
|
|
161
|
+
message: "an HTML-table block directly inside a list item has no ContentListMembership field of its own -- only ContentParagraph carries .list -- so its association with the enclosing list item is lost"
|
|
162
|
+
});
|
|
163
|
+
return [table];
|
|
164
|
+
}
|
|
155
165
|
if (context.rawHtmlMode === "drop") {
|
|
156
166
|
context.sink({
|
|
157
167
|
code: MarkdownDiagnosticCodes.RAW_HTML_DROPPED,
|
|
@@ -349,7 +359,7 @@ function lowerBlock(node, context, contentWidthPt) {
|
|
|
349
359
|
case "list": return lowerList(node, void 0, 0, context, contentWidthPt);
|
|
350
360
|
case "codeBlock": return lowerCodeBlock(node, context);
|
|
351
361
|
case "thematicBreak": return lowerThematicBreak(context);
|
|
352
|
-
case "htmlBlock": return lowerHtmlBlock(node, context);
|
|
362
|
+
case "htmlBlock": return lowerHtmlBlock(node, context, contentWidthPt);
|
|
353
363
|
case "mathBlock": return lowerMathBlock(node, context);
|
|
354
364
|
case "footnoteDefinition": return lowerFootnoteDefinition(node, context, contentWidthPt);
|
|
355
365
|
case "table":
|
|
@@ -381,7 +391,8 @@ function lowerParsedMarkdown(parsed, options = {}, metadata = {}) {
|
|
|
381
391
|
rawHtmlMode: options.rawHtml ?? "preserve",
|
|
382
392
|
numIdState: createNumIdMintState(),
|
|
383
393
|
quoteDepth: 0,
|
|
384
|
-
list: void 0
|
|
394
|
+
list: void 0,
|
|
395
|
+
gfmTables: options.gfmTables ?? true
|
|
385
396
|
};
|
|
386
397
|
return {
|
|
387
398
|
kind: "wordprocessing",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as MarkdownDiagnosticSink } from "../diagnostics-
|
|
1
|
+
import { i as MarkdownDiagnosticSink } from "../diagnostics-DLum7kY6.cjs";
|
|
2
2
|
import { n as MarkdownImageResolver } from "../image-B5L0HpAJ.cjs";
|
|
3
3
|
import { Margins, PageSize } from "document-schema.js";
|
|
4
4
|
//#region src/options/options.d.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as MarkdownDiagnosticSink } from "../diagnostics-
|
|
1
|
+
import { i as MarkdownDiagnosticSink } from "../diagnostics-DLum7kY6.js";
|
|
2
2
|
import { n as MarkdownImageResolver } from "../image-C390OIB3.js";
|
|
3
3
|
import { Margins, PageSize } from "document-schema.js";
|
|
4
4
|
//#region src/options/options.d.ts
|
package/dist/read.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as MarkdownDiagnostic } from "./diagnostics-
|
|
1
|
+
import { t as MarkdownDiagnostic } from "./diagnostics-DLum7kY6.cjs";
|
|
2
2
|
import { ReadMarkdownOptions } from "./options/options.cjs";
|
|
3
3
|
import { ContentDocument, DocumentTree } from "document-schema.js";
|
|
4
4
|
//#region src/read.d.ts
|