mrkdwn.js 4.0.6 → 6.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -66
- package/dist/ast/ast.d.cts +1 -1
- package/dist/ast/ast.d.ts +1 -1
- package/dist/{ast-8XCbjRQT.d.cts → ast-CNfTgS0N.d.cts} +35 -35
- package/dist/{ast-8XCbjRQT.d.ts → ast-CNfTgS0N.d.ts} +35 -35
- package/dist/block/block.cjs +12 -4
- package/dist/block/block.d.cts +9 -5
- package/dist/block/block.d.ts +9 -5
- package/dist/block/block.js +8 -4
- package/dist/block/definitions.d.cts +2 -2
- package/dist/block/definitions.d.ts +2 -2
- package/dist/block/node.d.cts +4 -4
- package/dist/block/node.d.ts +4 -4
- package/dist/block/table.d.cts +1 -1
- package/dist/block/table.d.ts +1 -1
- package/dist/codec.cjs +1 -1
- package/dist/codec.d.cts +1631 -29
- package/dist/codec.d.ts +1631 -29
- package/dist/codec.js +2 -2
- package/dist/defaults/defaults.d.cts +1 -1
- package/dist/defaults/defaults.d.ts +1 -1
- package/dist/diagnostics/diagnostics.cjs +17 -7
- package/dist/diagnostics/diagnostics.d.cts +2 -2
- package/dist/diagnostics/diagnostics.d.ts +2 -2
- package/dist/diagnostics/diagnostics.js +17 -8
- package/dist/{diagnostics-BWK1iGy7.d.cts → diagnostics-CjfBoW4K.d.cts} +14 -10
- package/dist/{diagnostics-BWK1iGy7.d.ts → diagnostics-CjfBoW4K.d.ts} +14 -10
- package/dist/emit/emit.cjs +378 -42
- package/dist/emit/emit.js +381 -45
- 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 +69 -26
- package/dist/emit/inline.d.cts +2 -12
- package/dist/emit/inline.d.ts +2 -12
- package/dist/emit/inline.js +68 -27
- package/dist/emit/table.cjs +18 -11
- package/dist/emit/table.d.cts +3 -2
- package/dist/emit/table.d.ts +3 -2
- package/dist/emit/table.js +18 -11
- 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/html/render.d.cts +1 -1
- package/dist/html/render.d.ts +1 -1
- package/dist/image/image.cjs +4 -4
- package/dist/image/image.d.cts +1 -1
- package/dist/image/image.d.ts +1 -1
- package/dist/image/image.js +4 -4
- package/dist/{image-C4KYmz_L.d.cts → image-B5L0HpAJ.d.cts} +1 -1
- package/dist/{image-DescdRgq.d.cts → image-BtmTG4_a.d.cts} +1 -1
- package/dist/{image-DescdRgq.d.ts → image-BtmTG4_a.d.ts} +1 -1
- package/dist/{image-Cm3hT5PS.d.ts → image-C390OIB3.d.ts} +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/inline/delimiter.d.cts +2 -2
- package/dist/inline/delimiter.d.ts +2 -2
- package/dist/inline/inline.d.cts +1 -1
- package/dist/inline/inline.d.ts +1 -1
- package/dist/inline/link.d.cts +17 -1
- package/dist/inline/link.d.ts +17 -1
- package/dist/inline/node.d.cts +2 -2
- package/dist/inline/node.d.ts +2 -2
- package/dist/{inline-CXVQWQnW.d.cts → inline-CnO86zMw.d.cts} +2 -2
- package/dist/inline-DCIKQ83j.d.cts +14 -0
- package/dist/{inline-B_V7bs5j.d.ts → inline-DItZ-VVw.d.ts} +2 -2
- package/dist/inline-INoDAG37.d.ts +14 -0
- package/dist/lower/front-matter.cjs +73 -26
- package/dist/lower/front-matter.d.cts +2 -1
- package/dist/lower/front-matter.d.ts +2 -1
- package/dist/lower/front-matter.js +72 -25
- package/dist/lower/image.d.cts +1 -1
- package/dist/lower/image.d.ts +1 -1
- package/dist/lower/inline.cjs +87 -33
- package/dist/lower/inline.d.cts +9 -12
- package/dist/lower/inline.d.ts +9 -12
- package/dist/lower/inline.js +89 -34
- package/dist/lower/lower.cjs +143 -113
- package/dist/lower/lower.d.cts +8 -1
- package/dist/lower/lower.d.ts +8 -1
- package/dist/lower/lower.js +144 -115
- package/dist/lower/table.cjs +3 -2
- package/dist/lower/table.d.cts +1 -1
- package/dist/lower/table.d.ts +1 -1
- package/dist/lower/table.js +3 -2
- package/dist/options/options.d.cts +10 -10
- package/dist/options/options.d.ts +10 -10
- package/dist/read.cjs +45 -9
- package/dist/read.d.cts +3 -3
- package/dist/read.d.ts +3 -3
- package/dist/read.js +47 -11
- package/dist/scan/entity-table.cjs +2125 -2125
- package/dist/scan/entity-table.js +2125 -2125
- package/dist/shared/line-ending.cjs +7 -0
- package/dist/shared/line-ending.d.cts +5 -0
- package/dist/shared/line-ending.d.ts +5 -0
- package/dist/shared/line-ending.js +5 -0
- package/dist/shared/list-id.cjs +11 -3
- package/dist/shared/list-id.d.cts +7 -4
- package/dist/shared/list-id.d.ts +7 -4
- package/dist/shared/list-id.js +11 -4
- package/dist/shared/style-constants.cjs +0 -2
- package/dist/shared/style-constants.d.cts +1 -2
- package/dist/shared/style-constants.d.ts +1 -2
- package/dist/shared/style-constants.js +1 -2
- package/dist/write.cjs +33 -6
- package/dist/write.d.cts +2 -2
- package/dist/write.d.ts +2 -2
- package/dist/write.js +34 -7
- package/package.json +29 -30
- package/dist/link-Dv4kxVjk.d.cts +0 -18
- package/dist/link-Dv4kxVjk.d.ts +0 -18
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 { createNumIdMintState, mintListNumId, mintedListType } from "../shared/list-id.js";
|
|
5
|
-
import { CODE_BLOCK_STYLE_ID, HORIZONTAL_RULE_STYLE_ID, HTML_PREFORMATTED_STYLE_ID, MATH_BLOCK_STYLE_ID, QUOTE_STYLE_ID, headingStyleId } from "../shared/style-constants.js";
|
|
6
|
-
import { extractFrontMatter } from "./front-matter.js";
|
|
7
4
|
import { resolveMarkdownImage } from "./image.js";
|
|
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";
|
|
8
|
+
import { extractFrontMatter } from "./front-matter.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";
|
|
@@ -24,17 +25,21 @@ function decorateParagraph(paragraph, context) {
|
|
|
24
25
|
};
|
|
25
26
|
if (context.list !== void 0) result = {
|
|
26
27
|
...result,
|
|
27
|
-
list: {
|
|
28
|
-
numId: context.list.numId,
|
|
29
|
-
level: context.list.level
|
|
30
|
-
}
|
|
28
|
+
list: { ...context.list }
|
|
31
29
|
};
|
|
32
30
|
return result;
|
|
33
31
|
}
|
|
32
|
+
function paragraphWithConstructs(runs, runConstructExtents) {
|
|
33
|
+
return {
|
|
34
|
+
runs,
|
|
35
|
+
...runConstructExtents.length > 0 ? { constructs: [...runConstructExtents] } : {}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
34
38
|
function lowerHeading(node, context) {
|
|
39
|
+
const inline = lowerInlineNodes(node.children, inlineContext(context));
|
|
35
40
|
return [decorateParagraph({
|
|
36
41
|
kind: "paragraph",
|
|
37
|
-
|
|
42
|
+
...paragraphWithConstructs(inline.runs, inline.runConstructExtents),
|
|
38
43
|
styleId: headingStyleId(node.level),
|
|
39
44
|
headingLevel: node.level
|
|
40
45
|
}, context)];
|
|
@@ -45,9 +50,10 @@ function lowerParagraph(node, context) {
|
|
|
45
50
|
let segment = [];
|
|
46
51
|
const flushSegment = (force) => {
|
|
47
52
|
if (segment.length === 0 && !force) return;
|
|
53
|
+
const inline = lowerInlineNodes(segment, inlineCtx);
|
|
48
54
|
blocks.push(decorateParagraph({
|
|
49
55
|
kind: "paragraph",
|
|
50
|
-
runs
|
|
56
|
+
...paragraphWithConstructs(inline.runs, inline.runConstructExtents)
|
|
51
57
|
}, context));
|
|
52
58
|
segment = [];
|
|
53
59
|
};
|
|
@@ -69,39 +75,74 @@ function lowerParagraph(node, context) {
|
|
|
69
75
|
segment.push(child);
|
|
70
76
|
continue;
|
|
71
77
|
}
|
|
72
|
-
if (child.title !== void 0) context.sink({
|
|
73
|
-
code: MarkdownDiagnosticCodes.LINK_TITLE_DROPPED,
|
|
74
|
-
severity: "info",
|
|
75
|
-
message: `image title "${child.title}" has no ContentImageBlock equivalent and was dropped`
|
|
76
|
-
});
|
|
77
78
|
flushSegment(false);
|
|
78
79
|
if (context.list !== void 0) context.sink({
|
|
79
80
|
code: MarkdownDiagnosticCodes.LIST_ITEM_BLOCK_UNLISTED,
|
|
80
81
|
severity: "info",
|
|
81
82
|
message: "a resolved image 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"
|
|
82
83
|
});
|
|
83
|
-
|
|
84
|
+
const image = {
|
|
84
85
|
kind: "image",
|
|
85
86
|
format: resolved.format,
|
|
86
87
|
base64: resolved.base64,
|
|
87
88
|
widthPt: resolved.widthPt,
|
|
88
89
|
heightPt: resolved.heightPt,
|
|
89
90
|
...child.alt.length > 0 ? { altText: child.alt } : {}
|
|
90
|
-
}
|
|
91
|
+
};
|
|
92
|
+
if (child.title === void 0) {
|
|
93
|
+
blocks.push(image);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
blocks.push({
|
|
97
|
+
kind: "constructStart",
|
|
98
|
+
descriptor: {
|
|
99
|
+
kind: "link",
|
|
100
|
+
target: {
|
|
101
|
+
kind: "external",
|
|
102
|
+
uri: child.destination
|
|
103
|
+
},
|
|
104
|
+
title: child.title
|
|
105
|
+
}
|
|
106
|
+
}, image, { kind: "constructEnd" });
|
|
91
107
|
}
|
|
92
108
|
flushSegment(blocks.length === 0);
|
|
93
109
|
return blocks;
|
|
94
110
|
}
|
|
111
|
+
function splitInfoString(infoString) {
|
|
112
|
+
const firstWhitespace = infoString.search(/\s/);
|
|
113
|
+
if (firstWhitespace === -1) return infoString.startsWith("{") ? {
|
|
114
|
+
language: void 0,
|
|
115
|
+
remainder: infoString
|
|
116
|
+
} : {
|
|
117
|
+
language: infoString,
|
|
118
|
+
remainder: void 0
|
|
119
|
+
};
|
|
120
|
+
const firstWord = infoString.slice(0, firstWhitespace);
|
|
121
|
+
const remainder = infoString.slice(firstWhitespace).trim();
|
|
122
|
+
if (firstWord.startsWith("{")) return {
|
|
123
|
+
language: void 0,
|
|
124
|
+
remainder: infoString.trim()
|
|
125
|
+
};
|
|
126
|
+
return {
|
|
127
|
+
language: firstWord,
|
|
128
|
+
remainder: remainder.length > 0 ? remainder : void 0
|
|
129
|
+
};
|
|
130
|
+
}
|
|
95
131
|
function lowerCodeBlock(node, context) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
});
|
|
132
|
+
const info = node.fenced && node.infoString !== void 0 && node.infoString.length > 0 ? splitInfoString(node.infoString) : {
|
|
133
|
+
language: void 0,
|
|
134
|
+
remainder: void 0
|
|
135
|
+
};
|
|
101
136
|
return [decorateParagraph({
|
|
102
137
|
kind: "paragraph",
|
|
103
138
|
runs: [lowerCodeBlockRun(node.literal.replace(/\n$/, ""))],
|
|
104
|
-
styleId: CODE_BLOCK_STYLE_ID
|
|
139
|
+
styleId: CODE_BLOCK_STYLE_ID,
|
|
140
|
+
preformatted: true,
|
|
141
|
+
...info.language !== void 0 ? { codeLanguage: info.language } : {},
|
|
142
|
+
...info.remainder !== void 0 ? { source: {
|
|
143
|
+
format: "markdown",
|
|
144
|
+
xml: info.remainder
|
|
145
|
+
} } : {}
|
|
105
146
|
}, context)];
|
|
106
147
|
}
|
|
107
148
|
function lowerThematicBreak(context) {
|
|
@@ -111,7 +152,16 @@ function lowerThematicBreak(context) {
|
|
|
111
152
|
styleId: HORIZONTAL_RULE_STYLE_ID
|
|
112
153
|
}, context)];
|
|
113
154
|
}
|
|
114
|
-
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
|
+
}
|
|
115
165
|
if (context.rawHtmlMode === "drop") {
|
|
116
166
|
context.sink({
|
|
117
167
|
code: MarkdownDiagnosticCodes.RAW_HTML_DROPPED,
|
|
@@ -123,71 +173,76 @@ function lowerHtmlBlock(node, context) {
|
|
|
123
173
|
context.sink({
|
|
124
174
|
code: MarkdownDiagnosticCodes.RAW_HTML_PRESERVED_AS_TEXT,
|
|
125
175
|
severity: "info",
|
|
126
|
-
message: "block-level raw HTML was preserved as literal text (styleId \"HTMLPreformatted\"); it will not be rendered as HTML by any consumer of the resulting ContentDocument"
|
|
176
|
+
message: "block-level raw HTML was preserved as literal text (styleId \"HTMLPreformatted\"); it will not be rendered as HTML by any consumer of the resulting ContentDocument, and its verbatim original rides the paragraph's own markdown residue for this package's writer to re-emit as-is"
|
|
127
177
|
});
|
|
128
178
|
const literal = node.literal.replace(/\n+$/, "");
|
|
129
179
|
return [decorateParagraph({
|
|
130
180
|
kind: "paragraph",
|
|
131
181
|
runs: literal.length === 0 ? [] : [{ text: literal }],
|
|
132
|
-
styleId: HTML_PREFORMATTED_STYLE_ID
|
|
182
|
+
styleId: HTML_PREFORMATTED_STYLE_ID,
|
|
183
|
+
source: {
|
|
184
|
+
format: "markdown",
|
|
185
|
+
xml: node.literal
|
|
186
|
+
}
|
|
133
187
|
}, context)];
|
|
134
188
|
}
|
|
135
189
|
function lowerMathBlock(node, context) {
|
|
136
|
-
context.sink({
|
|
137
|
-
code: MarkdownDiagnosticCodes.
|
|
190
|
+
if (context.list !== void 0) context.sink({
|
|
191
|
+
code: MarkdownDiagnosticCodes.LIST_ITEM_BLOCK_UNLISTED,
|
|
138
192
|
severity: "info",
|
|
139
|
-
message: "
|
|
193
|
+
message: "a display-math 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"
|
|
140
194
|
});
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
195
|
+
return [{
|
|
196
|
+
kind: "embeddedObject",
|
|
197
|
+
objectKind: "formula",
|
|
198
|
+
document: {
|
|
199
|
+
kind: "formula",
|
|
200
|
+
metadata: {},
|
|
201
|
+
formula: {
|
|
202
|
+
mathml: [],
|
|
203
|
+
presentation: { latex: node.literal.replace(/\n$/, "") }
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
frame: {
|
|
207
|
+
xPt: 0,
|
|
208
|
+
yPt: 0,
|
|
209
|
+
widthPt: 0,
|
|
210
|
+
heightPt: 0
|
|
211
|
+
}
|
|
212
|
+
}];
|
|
147
213
|
}
|
|
148
214
|
function lowerBlockquote(node, context, contentWidthPt) {
|
|
149
|
-
if (context.quoteDepth >= 1) context.sink({
|
|
150
|
-
code: MarkdownDiagnosticCodes.BLOCKQUOTE_NESTED_DEPTH,
|
|
151
|
-
severity: "info",
|
|
152
|
-
message: `blockquote nesting beyond level 1 is represented only as a larger indentLeftPt (${String((context.quoteDepth + 1) * 36)}pt); recovering the exact nesting depth back out is an approximation, not an exact inverse`
|
|
153
|
-
});
|
|
154
215
|
const nested = {
|
|
155
216
|
...context,
|
|
156
217
|
quoteDepth: context.quoteDepth + 1
|
|
157
218
|
};
|
|
158
219
|
const blocks = node.children.flatMap((child) => lowerBlock(child, nested, contentWidthPt));
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
...first,
|
|
171
|
-
runs: [checkboxRun, ...first.runs]
|
|
172
|
-
};
|
|
173
|
-
return true;
|
|
220
|
+
return [
|
|
221
|
+
{
|
|
222
|
+
kind: "constructStart",
|
|
223
|
+
descriptor: { kind: "division" }
|
|
224
|
+
},
|
|
225
|
+
...blocks.length === 0 ? [decorateParagraph({
|
|
226
|
+
kind: "paragraph",
|
|
227
|
+
runs: []
|
|
228
|
+
}, nested)] : blocks,
|
|
229
|
+
{ kind: "constructEnd" }
|
|
230
|
+
];
|
|
174
231
|
}
|
|
175
232
|
function lowerListItem(item, numId, level, context, contentWidthPt) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
233
|
+
const membership = {
|
|
234
|
+
numId,
|
|
235
|
+
level,
|
|
236
|
+
...item.checked !== void 0 ? { checked: item.checked } : {},
|
|
237
|
+
itemId: mintListItemId(context.numIdState)
|
|
238
|
+
};
|
|
181
239
|
const itemContext = {
|
|
182
240
|
...context,
|
|
183
|
-
list:
|
|
184
|
-
numId,
|
|
185
|
-
level
|
|
186
|
-
}
|
|
241
|
+
list: membership
|
|
187
242
|
};
|
|
188
243
|
const blocks = [];
|
|
189
|
-
let checkboxApplied = item.checked === void 0;
|
|
190
244
|
let ownLevelBlockCount = 0;
|
|
245
|
+
let firstOwnBlock;
|
|
191
246
|
for (const child of item.children) {
|
|
192
247
|
if (child.type === "list") {
|
|
193
248
|
blocks.push(...lowerList(child, numId, level + 1, context, contentWidthPt));
|
|
@@ -195,17 +250,13 @@ function lowerListItem(item, numId, level, context, contentWidthPt) {
|
|
|
195
250
|
}
|
|
196
251
|
const childBlocks = lowerBlock(child, itemContext, contentWidthPt);
|
|
197
252
|
ownLevelBlockCount += childBlocks.length;
|
|
198
|
-
|
|
253
|
+
firstOwnBlock ??= childBlocks[0];
|
|
199
254
|
blocks.push(...childBlocks);
|
|
200
255
|
}
|
|
201
|
-
if (ownLevelBlockCount === 0) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}, itemContext)];
|
|
206
|
-
if (!checkboxApplied) applyTaskCheckbox(placeholder, item.checked === true);
|
|
207
|
-
blocks.unshift(...placeholder);
|
|
208
|
-
}
|
|
256
|
+
if (ownLevelBlockCount === 0 || firstOwnBlock?.kind === "constructStart") blocks.unshift(decorateParagraph({
|
|
257
|
+
kind: "paragraph",
|
|
258
|
+
runs: []
|
|
259
|
+
}, itemContext));
|
|
209
260
|
return blocks;
|
|
210
261
|
}
|
|
211
262
|
function lowerList(node, ancestorNumId, level, context, contentWidthPt) {
|
|
@@ -216,7 +267,8 @@ function lowerList(node, ancestorNumId, level, context, contentWidthPt) {
|
|
|
216
267
|
type: node.markerType,
|
|
217
268
|
start: node.start,
|
|
218
269
|
task,
|
|
219
|
-
loose: !node.tight
|
|
270
|
+
loose: !node.tight,
|
|
271
|
+
ownerItemId: context.list?.itemId
|
|
220
272
|
});
|
|
221
273
|
} else {
|
|
222
274
|
numId = ancestorNumId;
|
|
@@ -229,46 +281,13 @@ function lowerList(node, ancestorNumId, level, context, contentWidthPt) {
|
|
|
229
281
|
}
|
|
230
282
|
return node.children.flatMap((item) => lowerListItem(item, numId, level, context, contentWidthPt));
|
|
231
283
|
}
|
|
232
|
-
function flattenFootnoteBodyHeadings(node, context) {
|
|
233
|
-
switch (node.type) {
|
|
234
|
-
case "heading":
|
|
235
|
-
context.sink({
|
|
236
|
-
code: MarkdownDiagnosticCodes.FOOTNOTE_BODY_HEADING_FLATTENED,
|
|
237
|
-
severity: "info",
|
|
238
|
-
message: `a level-${String(node.level)} heading inside a footnote definition's body is carried as literal ATX text: a construct boundary marker's extent may not contain a block that opens or closes a heading scope, so the heading cannot stay a heading inside the anchor construct the definition lowers to`
|
|
239
|
-
});
|
|
240
|
-
return {
|
|
241
|
-
type: "paragraph",
|
|
242
|
-
children: [{
|
|
243
|
-
type: "text",
|
|
244
|
-
value: `${"#".repeat(node.level)} `
|
|
245
|
-
}, ...node.children]
|
|
246
|
-
};
|
|
247
|
-
case "blockquote": return {
|
|
248
|
-
type: "blockquote",
|
|
249
|
-
children: node.children.map((child) => flattenFootnoteBodyHeadings(child, context))
|
|
250
|
-
};
|
|
251
|
-
case "list": return {
|
|
252
|
-
...node,
|
|
253
|
-
children: node.children.map((item) => flattenFootnoteBodyHeadingsInItem(item, context))
|
|
254
|
-
};
|
|
255
|
-
case "listItem": return flattenFootnoteBodyHeadingsInItem(node, context);
|
|
256
|
-
default: return node;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
function flattenFootnoteBodyHeadingsInItem(item, context) {
|
|
260
|
-
return {
|
|
261
|
-
...item,
|
|
262
|
-
children: item.children.map((child) => flattenFootnoteBodyHeadings(child, context))
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
284
|
function lowerFootnoteDefinition(node, context, contentWidthPt) {
|
|
266
285
|
const descriptor = {
|
|
267
286
|
kind: "anchor",
|
|
268
287
|
anchorType: "footnote",
|
|
269
288
|
name: node.label
|
|
270
289
|
};
|
|
271
|
-
const body = node.children.flatMap((child) => lowerBlock(
|
|
290
|
+
const body = node.children.flatMap((child) => lowerBlock(child, context, contentWidthPt));
|
|
272
291
|
return [
|
|
273
292
|
{
|
|
274
293
|
kind: "constructStart",
|
|
@@ -286,7 +305,7 @@ function lowerBlock(node, context, contentWidthPt) {
|
|
|
286
305
|
case "list": return lowerList(node, void 0, 0, context, contentWidthPt);
|
|
287
306
|
case "codeBlock": return lowerCodeBlock(node, context);
|
|
288
307
|
case "thematicBreak": return lowerThematicBreak(context);
|
|
289
|
-
case "htmlBlock": return lowerHtmlBlock(node, context);
|
|
308
|
+
case "htmlBlock": return lowerHtmlBlock(node, context, contentWidthPt);
|
|
290
309
|
case "mathBlock": return lowerMathBlock(node, context);
|
|
291
310
|
case "footnoteDefinition": return lowerFootnoteDefinition(node, context, contentWidthPt);
|
|
292
311
|
case "table":
|
|
@@ -318,7 +337,8 @@ function lowerParsedMarkdown(parsed, options = {}, metadata = {}) {
|
|
|
318
337
|
rawHtmlMode: options.rawHtml ?? "preserve",
|
|
319
338
|
numIdState: createNumIdMintState(),
|
|
320
339
|
quoteDepth: 0,
|
|
321
|
-
list: void 0
|
|
340
|
+
list: void 0,
|
|
341
|
+
gfmTables: options.gfmTables ?? true
|
|
322
342
|
};
|
|
323
343
|
return {
|
|
324
344
|
kind: "wordprocessing",
|
|
@@ -330,15 +350,16 @@ function lowerParsedMarkdown(parsed, options = {}, metadata = {}) {
|
|
|
330
350
|
}]
|
|
331
351
|
};
|
|
332
352
|
}
|
|
333
|
-
function
|
|
353
|
+
function lowerMarkdownDetailed(source, options = {}) {
|
|
334
354
|
if (options.maxInputBytes !== void 0) {
|
|
335
355
|
const actualBytes = new TextEncoder().encode(source).length;
|
|
336
356
|
if (actualBytes > options.maxInputBytes) throw new MarkdownInputTooLargeError(options.maxInputBytes, actualBytes);
|
|
337
357
|
}
|
|
338
358
|
const sink = options.sink ?? NOOP_MARKDOWN_DIAGNOSTIC_SINK;
|
|
339
|
-
const
|
|
359
|
+
const extracted = options.frontMatter ?? false ? extractFrontMatter(source, sink) : {
|
|
340
360
|
metadata: {},
|
|
341
|
-
rest: source
|
|
361
|
+
rest: source,
|
|
362
|
+
source: void 0
|
|
342
363
|
};
|
|
343
364
|
const parseOptions = {
|
|
344
365
|
gfmTables: options.gfmTables,
|
|
@@ -349,7 +370,15 @@ function lowerMarkdown(source, options = {}) {
|
|
|
349
370
|
maxNesting: options.maxBlockNesting,
|
|
350
371
|
sink
|
|
351
372
|
};
|
|
352
|
-
|
|
373
|
+
const parsed = parseMarkdown(extracted.rest, parseOptions);
|
|
374
|
+
return {
|
|
375
|
+
document: lowerParsedMarkdown(parsed, options, extracted.metadata),
|
|
376
|
+
references: parsed.references,
|
|
377
|
+
frontMatterSource: extracted.source
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
function lowerMarkdown(source, options = {}) {
|
|
381
|
+
return lowerMarkdownDetailed(source, options).document;
|
|
353
382
|
}
|
|
354
383
|
//#endregion
|
|
355
|
-
export { lowerMarkdown, lowerParsedMarkdown };
|
|
384
|
+
export { lowerMarkdown, lowerMarkdownDetailed, lowerParsedMarkdown };
|
package/dist/lower/table.cjs
CHANGED
|
@@ -6,11 +6,12 @@ function toParagraphAlignment(alignment) {
|
|
|
6
6
|
return alignment === "none" ? void 0 : alignment;
|
|
7
7
|
}
|
|
8
8
|
function lowerTableCell(cell, alignment, context) {
|
|
9
|
-
const
|
|
9
|
+
const inline = require_lower_inline.lowerInlineNodes(cell.children, context);
|
|
10
10
|
const paragraphAlignment = toParagraphAlignment(alignment ?? "none");
|
|
11
11
|
return { blocks: [{
|
|
12
12
|
kind: "paragraph",
|
|
13
|
-
runs,
|
|
13
|
+
runs: inline.runs,
|
|
14
|
+
...inline.runConstructExtents.length > 0 ? { constructs: [...inline.runConstructExtents] } : {},
|
|
14
15
|
...paragraphAlignment === void 0 ? {} : { alignment: paragraphAlignment }
|
|
15
16
|
}] };
|
|
16
17
|
}
|
package/dist/lower/table.d.cts
CHANGED
package/dist/lower/table.d.ts
CHANGED
package/dist/lower/table.js
CHANGED
|
@@ -5,11 +5,12 @@ function toParagraphAlignment(alignment) {
|
|
|
5
5
|
return alignment === "none" ? void 0 : alignment;
|
|
6
6
|
}
|
|
7
7
|
function lowerTableCell(cell, alignment, context) {
|
|
8
|
-
const
|
|
8
|
+
const inline = lowerInlineNodes(cell.children, context);
|
|
9
9
|
const paragraphAlignment = toParagraphAlignment(alignment ?? "none");
|
|
10
10
|
return { blocks: [{
|
|
11
11
|
kind: "paragraph",
|
|
12
|
-
runs,
|
|
12
|
+
runs: inline.runs,
|
|
13
|
+
...inline.runConstructExtents.length > 0 ? { constructs: [...inline.runConstructExtents] } : {},
|
|
13
14
|
...paragraphAlignment === void 0 ? {} : { alignment: paragraphAlignment }
|
|
14
15
|
}] };
|
|
15
16
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as MarkdownDiagnosticSink } from "../diagnostics-
|
|
2
|
-
import { n as MarkdownImageResolver } from "../image-
|
|
1
|
+
import { i as MarkdownDiagnosticSink } from "../diagnostics-CjfBoW4K.cjs";
|
|
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
|
|
5
5
|
interface ReadMarkdownOptions {
|
|
@@ -8,7 +8,7 @@ interface ReadMarkdownOptions {
|
|
|
8
8
|
readonly pageSize?: PageSize;
|
|
9
9
|
readonly margins?: Margins;
|
|
10
10
|
readonly images?: MarkdownImageResolver;
|
|
11
|
-
readonly rawHtml?:
|
|
11
|
+
readonly rawHtml?: "preserve" | "drop";
|
|
12
12
|
readonly frontMatter?: boolean;
|
|
13
13
|
readonly gfmTables?: boolean;
|
|
14
14
|
readonly gfmAutolinks?: boolean;
|
|
@@ -18,13 +18,13 @@ interface ReadMarkdownOptions {
|
|
|
18
18
|
readonly maxInputBytes?: number;
|
|
19
19
|
readonly maxBlockNesting?: number;
|
|
20
20
|
}
|
|
21
|
-
type MarkdownHeadingStyle =
|
|
22
|
-
type MarkdownBulletListMarker =
|
|
23
|
-
type MarkdownOrderedListDelimiter =
|
|
24
|
-
type MarkdownEmphasisMarker =
|
|
25
|
-
type MarkdownCodeFenceChar =
|
|
26
|
-
type MarkdownThematicBreakChar =
|
|
27
|
-
type MarkdownLineEnding =
|
|
21
|
+
type MarkdownHeadingStyle = "atx" | "setext";
|
|
22
|
+
type MarkdownBulletListMarker = "-" | "*" | "+";
|
|
23
|
+
type MarkdownOrderedListDelimiter = "." | ")";
|
|
24
|
+
type MarkdownEmphasisMarker = "_" | "*";
|
|
25
|
+
type MarkdownCodeFenceChar = "`" | "~";
|
|
26
|
+
type MarkdownThematicBreakChar = "-" | "_" | "*";
|
|
27
|
+
type MarkdownLineEnding = "lf" | "crlf";
|
|
28
28
|
interface WriteMarkdownStyleOptions {
|
|
29
29
|
readonly headingStyle?: MarkdownHeadingStyle;
|
|
30
30
|
readonly bulletListMarker?: MarkdownBulletListMarker;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as MarkdownDiagnosticSink } from "../diagnostics-
|
|
2
|
-
import { n as MarkdownImageResolver } from "../image-
|
|
1
|
+
import { i as MarkdownDiagnosticSink } from "../diagnostics-CjfBoW4K.js";
|
|
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
|
|
5
5
|
interface ReadMarkdownOptions {
|
|
@@ -8,7 +8,7 @@ interface ReadMarkdownOptions {
|
|
|
8
8
|
readonly pageSize?: PageSize;
|
|
9
9
|
readonly margins?: Margins;
|
|
10
10
|
readonly images?: MarkdownImageResolver;
|
|
11
|
-
readonly rawHtml?:
|
|
11
|
+
readonly rawHtml?: "preserve" | "drop";
|
|
12
12
|
readonly frontMatter?: boolean;
|
|
13
13
|
readonly gfmTables?: boolean;
|
|
14
14
|
readonly gfmAutolinks?: boolean;
|
|
@@ -18,13 +18,13 @@ interface ReadMarkdownOptions {
|
|
|
18
18
|
readonly maxInputBytes?: number;
|
|
19
19
|
readonly maxBlockNesting?: number;
|
|
20
20
|
}
|
|
21
|
-
type MarkdownHeadingStyle =
|
|
22
|
-
type MarkdownBulletListMarker =
|
|
23
|
-
type MarkdownOrderedListDelimiter =
|
|
24
|
-
type MarkdownEmphasisMarker =
|
|
25
|
-
type MarkdownCodeFenceChar =
|
|
26
|
-
type MarkdownThematicBreakChar =
|
|
27
|
-
type MarkdownLineEnding =
|
|
21
|
+
type MarkdownHeadingStyle = "atx" | "setext";
|
|
22
|
+
type MarkdownBulletListMarker = "-" | "*" | "+";
|
|
23
|
+
type MarkdownOrderedListDelimiter = "." | ")";
|
|
24
|
+
type MarkdownEmphasisMarker = "_" | "*";
|
|
25
|
+
type MarkdownCodeFenceChar = "`" | "~";
|
|
26
|
+
type MarkdownThematicBreakChar = "-" | "_" | "*";
|
|
27
|
+
type MarkdownLineEnding = "lf" | "crlf";
|
|
28
28
|
interface WriteMarkdownStyleOptions {
|
|
29
29
|
readonly headingStyle?: MarkdownHeadingStyle;
|
|
30
30
|
readonly bulletListMarker?: MarkdownBulletListMarker;
|
package/dist/read.cjs
CHANGED
|
@@ -2,19 +2,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_lower_lower = require("./lower/lower.cjs");
|
|
3
3
|
let document_schema_js = require("document-schema.js");
|
|
4
4
|
//#region src/read.ts
|
|
5
|
-
function
|
|
6
|
-
const { document, diagnostics } = readMarkdownContent(text, options);
|
|
7
|
-
return {
|
|
8
|
-
documentPackage: (0, document_schema_js.assemblePackage)(document),
|
|
9
|
-
diagnostics
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
function readMarkdownContent(text, options = {}) {
|
|
5
|
+
function readMarkdownDetail(text, options) {
|
|
13
6
|
options.signal?.throwIfAborted();
|
|
14
7
|
const diagnostics = [];
|
|
15
8
|
const callerSink = options.sink;
|
|
16
9
|
return {
|
|
17
|
-
|
|
10
|
+
...require_lower_lower.lowerMarkdownDetailed(text, {
|
|
18
11
|
...options,
|
|
19
12
|
sink: (diagnostic) => {
|
|
20
13
|
diagnostics.push(diagnostic);
|
|
@@ -24,6 +17,49 @@ function readMarkdownContent(text, options = {}) {
|
|
|
24
17
|
diagnostics
|
|
25
18
|
};
|
|
26
19
|
}
|
|
20
|
+
function linkDefinitionEntries(references) {
|
|
21
|
+
if (references.size === 0) return;
|
|
22
|
+
const entries = {};
|
|
23
|
+
for (const [label, definition] of references) entries[label] = definition.title === void 0 ? {
|
|
24
|
+
kind: "link",
|
|
25
|
+
destination: definition.destination
|
|
26
|
+
} : {
|
|
27
|
+
kind: "link",
|
|
28
|
+
destination: definition.destination,
|
|
29
|
+
title: definition.title
|
|
30
|
+
};
|
|
31
|
+
return entries;
|
|
32
|
+
}
|
|
33
|
+
function readMarkdown(text, options = {}) {
|
|
34
|
+
const detail = readMarkdownDetail(text, options);
|
|
35
|
+
const assembled = (0, document_schema_js.assembleTree)(detail.document);
|
|
36
|
+
const definitions = linkDefinitionEntries(detail.references);
|
|
37
|
+
const frontMatterResidue = detail.frontMatterSource === void 0 ? void 0 : {
|
|
38
|
+
format: "markdown",
|
|
39
|
+
xml: detail.frontMatterSource
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
documentPackage: definitions === void 0 && frontMatterResidue === void 0 ? assembled : {
|
|
43
|
+
...assembled,
|
|
44
|
+
...definitions !== void 0 ? { definitions: {
|
|
45
|
+
...assembled.definitions,
|
|
46
|
+
...definitions
|
|
47
|
+
} } : {},
|
|
48
|
+
...frontMatterResidue !== void 0 ? { source: {
|
|
49
|
+
...assembled.source ?? {},
|
|
50
|
+
frontmatter: frontMatterResidue
|
|
51
|
+
} } : {}
|
|
52
|
+
},
|
|
53
|
+
diagnostics: detail.diagnostics
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function readMarkdownContent(text, options = {}) {
|
|
57
|
+
const detail = readMarkdownDetail(text, options);
|
|
58
|
+
return {
|
|
59
|
+
document: detail.document,
|
|
60
|
+
diagnostics: detail.diagnostics
|
|
61
|
+
};
|
|
62
|
+
}
|
|
27
63
|
//#endregion
|
|
28
64
|
exports.readMarkdown = readMarkdown;
|
|
29
65
|
exports.readMarkdownContent = readMarkdownContent;
|
package/dist/read.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as MarkdownDiagnostic } from "./diagnostics-
|
|
1
|
+
import { t as MarkdownDiagnostic } from "./diagnostics-CjfBoW4K.cjs";
|
|
2
2
|
import { ReadMarkdownOptions } from "./options/options.cjs";
|
|
3
|
-
import { ContentDocument,
|
|
3
|
+
import { ContentDocument, DocumentTree } from "document-schema.js";
|
|
4
4
|
//#region src/read.d.ts
|
|
5
5
|
interface ReadMarkdownResult {
|
|
6
|
-
readonly documentPackage:
|
|
6
|
+
readonly documentPackage: DocumentTree;
|
|
7
7
|
readonly diagnostics: readonly MarkdownDiagnostic[];
|
|
8
8
|
}
|
|
9
9
|
interface ReadMarkdownContentResult {
|
package/dist/read.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as MarkdownDiagnostic } from "./diagnostics-
|
|
1
|
+
import { t as MarkdownDiagnostic } from "./diagnostics-CjfBoW4K.js";
|
|
2
2
|
import { ReadMarkdownOptions } from "./options/options.js";
|
|
3
|
-
import { ContentDocument,
|
|
3
|
+
import { ContentDocument, DocumentTree } from "document-schema.js";
|
|
4
4
|
//#region src/read.d.ts
|
|
5
5
|
interface ReadMarkdownResult {
|
|
6
|
-
readonly documentPackage:
|
|
6
|
+
readonly documentPackage: DocumentTree;
|
|
7
7
|
readonly diagnostics: readonly MarkdownDiagnostic[];
|
|
8
8
|
}
|
|
9
9
|
interface ReadMarkdownContentResult {
|