mrkdwn.js 6.7.3 → 6.7.5
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/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/table.cjs +3 -4
- package/dist/block/table.js +3 -4
- package/dist/emit/emit.cjs +35 -37
- package/dist/emit/emit.js +35 -37
- package/dist/emit/table.cjs +2 -2
- package/dist/emit/table.js +2 -2
- 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 +0 -49
- package/dist/image/image.d.cts +2 -2
- package/dist/image/image.d.ts +2 -2
- package/dist/image/image.js +1 -48
- 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 -12
- package/dist/inline/delimiter.d.cts +2 -1
- package/dist/inline/delimiter.d.ts +2 -1
- package/dist/inline/delimiter.js +5 -13
- package/dist/inline/entity.cjs +6 -10
- package/dist/inline/entity.js +6 -10
- 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/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 +3 -2
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ graph TD
|
|
|
25
25
|
schema --> mdcodec
|
|
26
26
|
schema --> documents
|
|
27
27
|
bytecodec --> pdfcodec
|
|
28
|
+
bytecodec --> mdcodec
|
|
28
29
|
ooxml --> documents
|
|
29
30
|
odf --> documents
|
|
30
31
|
pdfcodec --> documents
|
|
@@ -143,7 +144,7 @@ Modelled on `pdf-codec`'s own layering, aimed at CommonMark+GFM instead of PDF:
|
|
|
143
144
|
- **`src/block/`** — CommonMark block-structure algorithm (open-block stack, continuation matching): paragraphs, headings, code blocks, block quotes, lists (incl. GFM task-list-item), thematic breaks, link references, footnote definitions, GFM tables.
|
|
144
145
|
- **`src/inline/`** — emphasis, code spans, links, autolinks, raw HTML, GFM strikethrough, footnote references, line breaks. `link.ts` and `footnote.ts` hold the label grammars the block phase shares.
|
|
145
146
|
- **`src/html/`** — raw HTML recognition (bounded rules, not a general parser) plus `render.ts` (conformance oracle; internal only). `html-table.ts` is the one exception to "never parsed as markup": a block-level HTML that is, in full, one well-formed `<table>` recognises straight to a real `ContentTable` instead of opaque text — see [HTML-table fallback](#html-table-fallback).
|
|
146
|
-
- **`src/image/`** — PNG/JPEG dimension reader
|
|
147
|
+
- **`src/image/`** — PNG/JPEG dimension reader, shared by `src/lower/` and `src/emit/`. The base64 those paths encode and decode a `data:` URI's payload with comes from `byte-codec`.
|
|
147
148
|
- **`src/shared/`** — string-shape conventions `src/lower`/`src/emit` agree on (`style-constants.ts`, `list-id.ts`'s opaque `numId`). Re-exported so `documents.js`'s `MarkdownEditor` reuses the identical grammar.
|
|
148
149
|
- **`src/lower/`** — AST → `ContentDocument` lowering (thin adapter, not a second parser); top-of-file table maps each construct to its diagnostic gap.
|
|
149
150
|
- **`src/emit/`** — `ContentDocument` → markdown text emission, the structural inverse of `src/lower`. `html-table.ts` is `src/html/html-table.ts`'s own write-side counterpart.
|
|
@@ -2,10 +2,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_diagnostics_diagnostics = require("../diagnostics/diagnostics.cjs");
|
|
3
3
|
const require_inline_link = require("../inline/link.cjs");
|
|
4
4
|
//#region src/block/definitions.ts
|
|
5
|
-
const MIN_DEFINITION_LABEL_LENGTH = 3;
|
|
6
5
|
function parseDefinition(content, start) {
|
|
7
6
|
const labelLength = require_inline_link.matchLinkLabel(content, start);
|
|
8
|
-
if (labelLength < MIN_DEFINITION_LABEL_LENGTH) return;
|
|
9
7
|
const label = require_inline_link.normalizeLinkLabel(content.slice(start, start + labelLength));
|
|
10
8
|
if (label.length === 0) return;
|
|
11
9
|
let cursor = start + labelLength;
|
|
@@ -51,9 +49,7 @@ function extractDefinitions(content, references, sink = require_diagnostics_diag
|
|
|
51
49
|
}
|
|
52
50
|
}
|
|
53
51
|
function countNewlines(content, upTo) {
|
|
54
|
-
|
|
55
|
-
for (let index = 0; index < upTo && index < content.length; index += 1) if (content.charAt(index) === "\n") count += 1;
|
|
56
|
-
return count;
|
|
52
|
+
return content.slice(0, upTo).split("\n").length - 1;
|
|
57
53
|
}
|
|
58
54
|
//#endregion
|
|
59
55
|
exports.extractDefinitions = extractDefinitions;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { MarkdownDiagnosticCodes, NOOP_MARKDOWN_DIAGNOSTIC_SINK } from "../diagnostics/diagnostics.js";
|
|
2
2
|
import { isBlankRemainderOfLine, matchLinkLabel, normalizeLinkLabel, parseLinkDestination, parseLinkTitle, skipInlineWhitespace } from "../inline/link.js";
|
|
3
3
|
//#region src/block/definitions.ts
|
|
4
|
-
const MIN_DEFINITION_LABEL_LENGTH = 3;
|
|
5
4
|
function parseDefinition(content, start) {
|
|
6
5
|
const labelLength = matchLinkLabel(content, start);
|
|
7
|
-
if (labelLength < MIN_DEFINITION_LABEL_LENGTH) return;
|
|
8
6
|
const label = normalizeLinkLabel(content.slice(start, start + labelLength));
|
|
9
7
|
if (label.length === 0) return;
|
|
10
8
|
let cursor = start + labelLength;
|
|
@@ -50,9 +48,7 @@ function extractDefinitions(content, references, sink = NOOP_MARKDOWN_DIAGNOSTIC
|
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
50
|
function countNewlines(content, upTo) {
|
|
53
|
-
|
|
54
|
-
for (let index = 0; index < upTo && index < content.length; index += 1) if (content.charAt(index) === "\n") count += 1;
|
|
55
|
-
return count;
|
|
51
|
+
return content.slice(0, upTo).split("\n").length - 1;
|
|
56
52
|
}
|
|
57
53
|
//#endregion
|
|
58
54
|
export { extractDefinitions };
|
package/dist/block/line.cjs
CHANGED
|
@@ -7,7 +7,7 @@ var LineCursor = class {
|
|
|
7
7
|
cursor;
|
|
8
8
|
nextNonspaceMark;
|
|
9
9
|
nextNonspaceColumn = 0;
|
|
10
|
-
lineIsBlank
|
|
10
|
+
lineIsBlank;
|
|
11
11
|
constructor(text) {
|
|
12
12
|
this.text = text;
|
|
13
13
|
this.cursor = new require_scan_scan.MarkdownScanCursor(text);
|
|
@@ -51,7 +51,7 @@ var LineCursor = class {
|
|
|
51
51
|
this.cursor.reset(this.nextNonspaceMark);
|
|
52
52
|
}
|
|
53
53
|
advance(columns) {
|
|
54
|
-
for (let remaining = columns; remaining > 0; remaining -= 1)
|
|
54
|
+
for (let remaining = columns; remaining > 0; remaining -= 1) this.cursor.next();
|
|
55
55
|
}
|
|
56
56
|
advanceToEndOfLine() {
|
|
57
57
|
while (this.cursor.next() !== void 0);
|
package/dist/block/line.js
CHANGED
|
@@ -6,7 +6,7 @@ var LineCursor = class {
|
|
|
6
6
|
cursor;
|
|
7
7
|
nextNonspaceMark;
|
|
8
8
|
nextNonspaceColumn = 0;
|
|
9
|
-
lineIsBlank
|
|
9
|
+
lineIsBlank;
|
|
10
10
|
constructor(text) {
|
|
11
11
|
this.text = text;
|
|
12
12
|
this.cursor = new MarkdownScanCursor(text);
|
|
@@ -50,7 +50,7 @@ var LineCursor = class {
|
|
|
50
50
|
this.cursor.reset(this.nextNonspaceMark);
|
|
51
51
|
}
|
|
52
52
|
advance(columns) {
|
|
53
|
-
for (let remaining = columns; remaining > 0; remaining -= 1)
|
|
53
|
+
for (let remaining = columns; remaining > 0; remaining -= 1) this.cursor.next();
|
|
54
54
|
}
|
|
55
55
|
advanceToEndOfLine() {
|
|
56
56
|
while (this.cursor.next() !== void 0);
|
package/dist/block/list.cjs
CHANGED
|
@@ -5,17 +5,10 @@ const BULLET_MARKER_PATTERN = /^[*+-]/;
|
|
|
5
5
|
const ORDERED_MARKER_PATTERN = /^(\d{1,9})([.)])/;
|
|
6
6
|
const NON_SPACE_PATTERN = /[^ \t\f\v\r\n]/;
|
|
7
7
|
const INTERRUPTING_ORDERED_START = 1;
|
|
8
|
-
function isBulletMarker(char) {
|
|
9
|
-
return char === "-" || char === "*" || char === "+";
|
|
10
|
-
}
|
|
11
|
-
function isOrderedDelimiter(char) {
|
|
12
|
-
return char === "." || char === ")";
|
|
13
|
-
}
|
|
14
8
|
function matchMarker(rest, indent, containerIsParagraph) {
|
|
15
9
|
const bullet = BULLET_MARKER_PATTERN.exec(rest);
|
|
16
10
|
if (bullet !== null) {
|
|
17
11
|
const char = bullet[0];
|
|
18
|
-
if (!isBulletMarker(char)) return;
|
|
19
12
|
return {
|
|
20
13
|
length: bullet[0].length,
|
|
21
14
|
data: {
|
|
@@ -26,9 +19,9 @@ function matchMarker(rest, indent, containerIsParagraph) {
|
|
|
26
19
|
};
|
|
27
20
|
}
|
|
28
21
|
const ordered = ORDERED_MARKER_PATTERN.exec(rest);
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
22
|
+
if (ordered === null) return;
|
|
23
|
+
const digits = ordered[1];
|
|
24
|
+
const delimiter = ordered[2];
|
|
32
25
|
const start = Number.parseInt(digits, 10);
|
|
33
26
|
if (containerIsParagraph && start !== INTERRUPTING_ORDERED_START) return;
|
|
34
27
|
return {
|
|
@@ -55,12 +48,12 @@ function parseListMarker(line, containerIsParagraph) {
|
|
|
55
48
|
const afterMarkerColumn = line.column;
|
|
56
49
|
do
|
|
57
50
|
line.advance(1);
|
|
58
|
-
while (line.
|
|
51
|
+
while (line.peek() === " ");
|
|
59
52
|
const followingSpaces = line.column - afterMarkerColumn;
|
|
60
53
|
const startsBlank = line.atEnd;
|
|
61
|
-
if (followingSpaces > 4 ||
|
|
54
|
+
if (followingSpaces > 4 || startsBlank) {
|
|
62
55
|
line.reset(afterMarkerMark);
|
|
63
|
-
|
|
56
|
+
line.advance(1);
|
|
64
57
|
return {
|
|
65
58
|
...match.data,
|
|
66
59
|
padding: match.length + 1
|
|
@@ -72,7 +65,7 @@ function parseListMarker(line, containerIsParagraph) {
|
|
|
72
65
|
};
|
|
73
66
|
}
|
|
74
67
|
function listsMatch(a, b) {
|
|
75
|
-
return a.
|
|
68
|
+
return a.delimiter === b.delimiter && a.bulletChar === b.bulletChar;
|
|
76
69
|
}
|
|
77
70
|
function endsWithBlankLine(block) {
|
|
78
71
|
let current = block;
|
package/dist/block/list.js
CHANGED
|
@@ -4,17 +4,10 @@ const BULLET_MARKER_PATTERN = /^[*+-]/;
|
|
|
4
4
|
const ORDERED_MARKER_PATTERN = /^(\d{1,9})([.)])/;
|
|
5
5
|
const NON_SPACE_PATTERN = /[^ \t\f\v\r\n]/;
|
|
6
6
|
const INTERRUPTING_ORDERED_START = 1;
|
|
7
|
-
function isBulletMarker(char) {
|
|
8
|
-
return char === "-" || char === "*" || char === "+";
|
|
9
|
-
}
|
|
10
|
-
function isOrderedDelimiter(char) {
|
|
11
|
-
return char === "." || char === ")";
|
|
12
|
-
}
|
|
13
7
|
function matchMarker(rest, indent, containerIsParagraph) {
|
|
14
8
|
const bullet = BULLET_MARKER_PATTERN.exec(rest);
|
|
15
9
|
if (bullet !== null) {
|
|
16
10
|
const char = bullet[0];
|
|
17
|
-
if (!isBulletMarker(char)) return;
|
|
18
11
|
return {
|
|
19
12
|
length: bullet[0].length,
|
|
20
13
|
data: {
|
|
@@ -25,9 +18,9 @@ function matchMarker(rest, indent, containerIsParagraph) {
|
|
|
25
18
|
};
|
|
26
19
|
}
|
|
27
20
|
const ordered = ORDERED_MARKER_PATTERN.exec(rest);
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
21
|
+
if (ordered === null) return;
|
|
22
|
+
const digits = ordered[1];
|
|
23
|
+
const delimiter = ordered[2];
|
|
31
24
|
const start = Number.parseInt(digits, 10);
|
|
32
25
|
if (containerIsParagraph && start !== INTERRUPTING_ORDERED_START) return;
|
|
33
26
|
return {
|
|
@@ -54,12 +47,12 @@ function parseListMarker(line, containerIsParagraph) {
|
|
|
54
47
|
const afterMarkerColumn = line.column;
|
|
55
48
|
do
|
|
56
49
|
line.advance(1);
|
|
57
|
-
while (line.
|
|
50
|
+
while (line.peek() === " ");
|
|
58
51
|
const followingSpaces = line.column - afterMarkerColumn;
|
|
59
52
|
const startsBlank = line.atEnd;
|
|
60
|
-
if (followingSpaces > 4 ||
|
|
53
|
+
if (followingSpaces > 4 || startsBlank) {
|
|
61
54
|
line.reset(afterMarkerMark);
|
|
62
|
-
|
|
55
|
+
line.advance(1);
|
|
63
56
|
return {
|
|
64
57
|
...match.data,
|
|
65
58
|
padding: match.length + 1
|
|
@@ -71,7 +64,7 @@ function parseListMarker(line, containerIsParagraph) {
|
|
|
71
64
|
};
|
|
72
65
|
}
|
|
73
66
|
function listsMatch(a, b) {
|
|
74
|
-
return a.
|
|
67
|
+
return a.delimiter === b.delimiter && a.bulletChar === b.bulletChar;
|
|
75
68
|
}
|
|
76
69
|
function endsWithBlankLine(block) {
|
|
77
70
|
let current = block;
|
package/dist/block/table.cjs
CHANGED
|
@@ -8,9 +8,9 @@ function splitTableRow(line) {
|
|
|
8
8
|
const cells = [];
|
|
9
9
|
let current = "";
|
|
10
10
|
let index = 0;
|
|
11
|
-
while (index
|
|
11
|
+
while (text.charAt(index) !== "") {
|
|
12
12
|
const char = text.charAt(index);
|
|
13
|
-
if (char === "\\"
|
|
13
|
+
if (char === "\\") {
|
|
14
14
|
const escaped = text.charAt(index + 1);
|
|
15
15
|
current += escaped === "|" ? escaped : char + escaped;
|
|
16
16
|
index += 2;
|
|
@@ -31,7 +31,7 @@ function splitTableRow(line) {
|
|
|
31
31
|
function endsWithUnescapedPipe(text) {
|
|
32
32
|
if (!text.endsWith("|")) return false;
|
|
33
33
|
let backslashes = 0;
|
|
34
|
-
while (
|
|
34
|
+
while (text.charAt(text.length - 2 - backslashes) === "\\") backslashes += 1;
|
|
35
35
|
return backslashes % 2 === 0;
|
|
36
36
|
}
|
|
37
37
|
function alignmentOf(cell) {
|
|
@@ -45,7 +45,6 @@ function alignmentOf(cell) {
|
|
|
45
45
|
function parseTableDelimiterRow(line) {
|
|
46
46
|
if (!line.includes("|")) return;
|
|
47
47
|
const cells = splitTableRow(line);
|
|
48
|
-
if (cells.length === 0) return;
|
|
49
48
|
const alignments = [];
|
|
50
49
|
for (const cell of cells) {
|
|
51
50
|
if (!DELIMITER_CELL_PATTERN.test(cell)) return;
|
package/dist/block/table.js
CHANGED
|
@@ -7,9 +7,9 @@ function splitTableRow(line) {
|
|
|
7
7
|
const cells = [];
|
|
8
8
|
let current = "";
|
|
9
9
|
let index = 0;
|
|
10
|
-
while (index
|
|
10
|
+
while (text.charAt(index) !== "") {
|
|
11
11
|
const char = text.charAt(index);
|
|
12
|
-
if (char === "\\"
|
|
12
|
+
if (char === "\\") {
|
|
13
13
|
const escaped = text.charAt(index + 1);
|
|
14
14
|
current += escaped === "|" ? escaped : char + escaped;
|
|
15
15
|
index += 2;
|
|
@@ -30,7 +30,7 @@ function splitTableRow(line) {
|
|
|
30
30
|
function endsWithUnescapedPipe(text) {
|
|
31
31
|
if (!text.endsWith("|")) return false;
|
|
32
32
|
let backslashes = 0;
|
|
33
|
-
while (
|
|
33
|
+
while (text.charAt(text.length - 2 - backslashes) === "\\") backslashes += 1;
|
|
34
34
|
return backslashes % 2 === 0;
|
|
35
35
|
}
|
|
36
36
|
function alignmentOf(cell) {
|
|
@@ -44,7 +44,6 @@ function alignmentOf(cell) {
|
|
|
44
44
|
function parseTableDelimiterRow(line) {
|
|
45
45
|
if (!line.includes("|")) return;
|
|
46
46
|
const cells = splitTableRow(line);
|
|
47
|
-
if (cells.length === 0) return;
|
|
48
47
|
const alignments = [];
|
|
49
48
|
for (const cell of cells) {
|
|
50
49
|
if (!DELIMITER_CELL_PATTERN.test(cell)) return;
|
package/dist/emit/emit.cjs
CHANGED
|
@@ -4,7 +4,6 @@ require("../defaults/defaults.cjs");
|
|
|
4
4
|
const require_diagnostics_diagnostics = require("../diagnostics/diagnostics.cjs");
|
|
5
5
|
const require_html_html = require("../html/html.cjs");
|
|
6
6
|
const require_shared_line_ending = require("../shared/line-ending.cjs");
|
|
7
|
-
require("../scan/scan.cjs");
|
|
8
7
|
const require_block_line = require("../block/line.cjs");
|
|
9
8
|
const require_block_list = require("../block/list.cjs");
|
|
10
9
|
const require_block_table = require("../block/table.cjs");
|
|
@@ -24,9 +23,13 @@ const MAX_SETEXT_LEVEL = 2;
|
|
|
24
23
|
const SETEXT_LEVEL_1_CHAR = "=";
|
|
25
24
|
const SETEXT_LEVEL_2_CHAR = "-";
|
|
26
25
|
const MIN_SETEXT_UNDERLINE_LENGTH = 1;
|
|
26
|
+
function splitLines(text, pattern) {
|
|
27
|
+
const [first, ...rest] = text.split(pattern);
|
|
28
|
+
return [first, ...rest];
|
|
29
|
+
}
|
|
27
30
|
function renderSetextHeading(level, text) {
|
|
28
31
|
const underlineChar = level === 1 ? SETEXT_LEVEL_1_CHAR : SETEXT_LEVEL_2_CHAR;
|
|
29
|
-
const firstLine = text
|
|
32
|
+
const [firstLine] = splitLines(text, require_shared_line_ending.LINE_ENDING_PATTERN);
|
|
30
33
|
return `${text}\n${underlineChar.repeat(Math.max(MIN_SETEXT_UNDERLINE_LENGTH, firstLine.length))}`;
|
|
31
34
|
}
|
|
32
35
|
const MIN_CODE_FENCE_LENGTH = 3;
|
|
@@ -54,19 +57,17 @@ function isQuotableStyle(styleId) {
|
|
|
54
57
|
return QUOTABLE_STYLE_IDS.has(styleId) || require_shared_style_constants.parseHeadingStyleId(styleId) !== void 0;
|
|
55
58
|
}
|
|
56
59
|
function terminatesCleanly(styleId) {
|
|
57
|
-
|
|
58
|
-
return styleId === "CodeBlock" || styleId === "MathBlock" || styleId === "HorizontalRule" || require_shared_style_constants.parseHeadingStyleId(styleId) !== void 0;
|
|
60
|
+
return styleId === "CodeBlock" || styleId === "MathBlock" || styleId === "HorizontalRule" || styleId !== void 0 && require_shared_style_constants.parseHeadingStyleId(styleId) !== void 0;
|
|
59
61
|
}
|
|
60
62
|
const BLANK_OR_WHITESPACE_ONLY_LINE = /^[ \t]*$/;
|
|
61
63
|
function firstContentLineIndex(text) {
|
|
62
64
|
return text.split(require_shared_line_ending.LINE_ENDING_PATTERN).findIndex((line) => !BLANK_OR_WHITESPACE_ONLY_LINE.test(line));
|
|
63
65
|
}
|
|
64
|
-
function
|
|
66
|
+
function leadingIndentReachesCodeThreshold(line) {
|
|
65
67
|
let column = 0;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return column;
|
|
68
|
+
while (column < line.length && line[column] === " ") column += 1;
|
|
69
|
+
if (column >= 4) return true;
|
|
70
|
+
return line[column] === " ";
|
|
70
71
|
}
|
|
71
72
|
const MAX_LEADING_BLANK_LINES_FOR_SETEXT = 1;
|
|
72
73
|
function interruptsSetextParagraph(line, atBlockStart) {
|
|
@@ -95,7 +96,7 @@ function unsafeSetextBreakReason(text) {
|
|
|
95
96
|
continue;
|
|
96
97
|
}
|
|
97
98
|
sawContentLine = true;
|
|
98
|
-
if (
|
|
99
|
+
if (leadingIndentReachesCodeThreshold(line)) return "leading-indentation";
|
|
99
100
|
if (interruptsSetextParagraph(line, true)) return "interrupting-line";
|
|
100
101
|
precedingLine = line;
|
|
101
102
|
continue;
|
|
@@ -124,7 +125,7 @@ function willRenderAsSetext(paragraph, level, context) {
|
|
|
124
125
|
}
|
|
125
126
|
function canInterruptOpenParagraph(paragraph, context) {
|
|
126
127
|
const styleId = paragraph.styleId;
|
|
127
|
-
if (styleId === void 0
|
|
128
|
+
if (styleId === void 0) return false;
|
|
128
129
|
if (styleId === "CodeBlock" || styleId === "MathBlock") return true;
|
|
129
130
|
if (styleId === "HorizontalRule") return context.thematicBreakChar !== SETEXT_LEVEL_2_CHAR;
|
|
130
131
|
const headingLevel = require_shared_style_constants.parseHeadingStyleId(styleId);
|
|
@@ -264,24 +265,24 @@ function toEmitItem(item) {
|
|
|
264
265
|
function firstBlockCheckbox(first, taskNumId) {
|
|
265
266
|
if (first.list.checked !== void 0) return {
|
|
266
267
|
checkboxText: first.list.checked ? "[x] " : "[ ] ",
|
|
267
|
-
|
|
268
|
+
strippedFirstBlock: void 0
|
|
268
269
|
};
|
|
269
270
|
if (!taskNumId || first.kind !== "paragraph") return {
|
|
270
271
|
checkboxText: "",
|
|
271
|
-
|
|
272
|
+
strippedFirstBlock: void 0
|
|
272
273
|
};
|
|
273
274
|
const leading = first.block.runs[0]?.text ?? "";
|
|
274
275
|
if (leading.startsWith(`☒ `)) return {
|
|
275
276
|
checkboxText: "[x] ",
|
|
276
|
-
|
|
277
|
+
strippedFirstBlock: stripCheckboxRun(first.block)
|
|
277
278
|
};
|
|
278
279
|
if (leading.startsWith(`☐ `)) return {
|
|
279
280
|
checkboxText: "[ ] ",
|
|
280
|
-
|
|
281
|
+
strippedFirstBlock: stripCheckboxRun(first.block)
|
|
281
282
|
};
|
|
282
283
|
return {
|
|
283
284
|
checkboxText: "",
|
|
284
|
-
|
|
285
|
+
strippedFirstBlock: void 0
|
|
285
286
|
};
|
|
286
287
|
}
|
|
287
288
|
function renderListItemMarker(numId, info, glyph, checkboxText, context) {
|
|
@@ -316,7 +317,7 @@ function resolveListGlyph(numId, type, previousSibling, context) {
|
|
|
316
317
|
}
|
|
317
318
|
function consumeSameItemRun(items, from, level, itemId) {
|
|
318
319
|
let end = from;
|
|
319
|
-
|
|
320
|
+
for (;;) {
|
|
320
321
|
const candidate = items[end];
|
|
321
322
|
if (candidate?.list.level !== level || candidate.list.itemId !== itemId) break;
|
|
322
323
|
end += 1;
|
|
@@ -334,7 +335,7 @@ function collectListItem(items, start, level, itemId) {
|
|
|
334
335
|
index = ownEnd;
|
|
335
336
|
for (;;) {
|
|
336
337
|
let nestedEnd = index;
|
|
337
|
-
|
|
338
|
+
for (;;) {
|
|
338
339
|
const candidateLevel = items[nestedEnd]?.list.level;
|
|
339
340
|
if (candidateLevel === void 0 || candidateLevel <= level) break;
|
|
340
341
|
nestedEnd += 1;
|
|
@@ -347,7 +348,6 @@ function collectListItem(items, start, level, itemId) {
|
|
|
347
348
|
index = nestedEnd;
|
|
348
349
|
if (itemId === void 0) break;
|
|
349
350
|
const resumedEnd = consumeSameItemRun(items, index, level, itemId);
|
|
350
|
-
if (resumedEnd === index) break;
|
|
351
351
|
segments.push({
|
|
352
352
|
kind: "own",
|
|
353
353
|
blocks: items.slice(index, resumedEnd)
|
|
@@ -378,8 +378,8 @@ function regionItemCanInterrupt(item, context) {
|
|
|
378
378
|
function lastStyleIdOfRegionItem(item) {
|
|
379
379
|
return lastStyleIdOf(toEmitItem(item));
|
|
380
380
|
}
|
|
381
|
-
function listRegionItemBody(item, context,
|
|
382
|
-
if (item.kind === "paragraph") return renderParagraphBody(
|
|
381
|
+
function listRegionItemBody(item, context, overrideParagraph) {
|
|
382
|
+
if (item.kind === "paragraph") return renderParagraphBody(overrideParagraph ?? item.block, context);
|
|
383
383
|
const previousEnclosingItemId = context.enclosingItemId;
|
|
384
384
|
context.enclosingItemId = item.list.itemId;
|
|
385
385
|
const body = renderConstruct(item.item, context);
|
|
@@ -394,14 +394,14 @@ function renderListRegion(items, context) {
|
|
|
394
394
|
const parts = [];
|
|
395
395
|
let index = 0;
|
|
396
396
|
let previousSibling;
|
|
397
|
-
|
|
397
|
+
for (;;) {
|
|
398
398
|
const item = items[index];
|
|
399
399
|
if (item === void 0) break;
|
|
400
400
|
const { numId, level, itemId } = item.list;
|
|
401
401
|
const info = listInfoFor(numId, context);
|
|
402
402
|
const loose = info?.loose === true;
|
|
403
403
|
const type = info?.type ?? "bullet";
|
|
404
|
-
const glyph = numId === void 0 ?
|
|
404
|
+
const glyph = numId === void 0 ? context.bulletMarker : resolveListGlyph(numId, type, previousSibling, context);
|
|
405
405
|
if (numId !== void 0) previousSibling = {
|
|
406
406
|
numId,
|
|
407
407
|
type,
|
|
@@ -410,7 +410,7 @@ function renderListRegion(items, context) {
|
|
|
410
410
|
const { segments, next } = collectListItem(items, index, level, itemId);
|
|
411
411
|
const first = segments[0]?.blocks[0];
|
|
412
412
|
if (first === void 0) break;
|
|
413
|
-
const { checkboxText,
|
|
413
|
+
const { checkboxText, strippedFirstBlock } = firstBlockCheckbox(first, info?.task === true);
|
|
414
414
|
const marker = renderListItemMarker(numId, info, glyph, checkboxText, context);
|
|
415
415
|
const indent = " ".repeat(marker.bareLength);
|
|
416
416
|
let text = "";
|
|
@@ -426,13 +426,13 @@ function renderListRegion(items, context) {
|
|
|
426
426
|
}
|
|
427
427
|
for (const block of segment.blocks) {
|
|
428
428
|
if (!renderedFirstLine) {
|
|
429
|
-
const [firstLine
|
|
429
|
+
const [firstLine, ...restLines] = splitLines(listRegionItemBody(block, context, strippedFirstBlock), "\n");
|
|
430
430
|
text = [`${marker.full}${firstLine}`, ...restLines.map((line) => `${indent}${line}`)].join("\n");
|
|
431
431
|
renderedFirstLine = true;
|
|
432
432
|
previousStyleId = lastStyleIdOfRegionItem(block);
|
|
433
433
|
continue;
|
|
434
434
|
}
|
|
435
|
-
const rendered = listRegionItemBody(block, context,
|
|
435
|
+
const rendered = listRegionItemBody(block, context, void 0).split("\n").map((line) => line.length === 0 ? line : `${indent}${line}`).join("\n");
|
|
436
436
|
const blank = loose || requiresBlankLineBefore(block, previousStyleId, context);
|
|
437
437
|
text += blank ? `\n\n${rendered}` : `\n${rendered}`;
|
|
438
438
|
previousStyleId = lastStyleIdOfRegionItem(block);
|
|
@@ -468,7 +468,7 @@ function isMaterialisedDivision(item) {
|
|
|
468
468
|
function groupConstructItems(blocks, start) {
|
|
469
469
|
const items = [];
|
|
470
470
|
let index = start;
|
|
471
|
-
|
|
471
|
+
for (;;) {
|
|
472
472
|
const block = blocks[index];
|
|
473
473
|
if (block === void 0) break;
|
|
474
474
|
index += 1;
|
|
@@ -497,7 +497,7 @@ function renderFootnoteDefinition(name, body) {
|
|
|
497
497
|
const marker = `[^${name}]:`;
|
|
498
498
|
if (body.length === 0) return marker;
|
|
499
499
|
const indent = " ".repeat(FOOTNOTE_CONTINUATION_INDENT);
|
|
500
|
-
const [firstLine
|
|
500
|
+
const [firstLine, ...restLines] = splitLines(body, "\n");
|
|
501
501
|
return [`${marker} ${firstLine}`, ...restLines.map((line) => line.length === 0 ? line : `${indent}${line}`)].join("\n");
|
|
502
502
|
}
|
|
503
503
|
function renderConstruct(item, context) {
|
|
@@ -512,13 +512,11 @@ function renderConstruct(item, context) {
|
|
|
512
512
|
});
|
|
513
513
|
return body;
|
|
514
514
|
}
|
|
515
|
-
if (
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
return body.split("\n").map((line) => line.length === 0 ? ">" : `> ${line}`).join("\n");
|
|
521
|
-
}
|
|
515
|
+
if (isMaterialisedDivision(item)) {
|
|
516
|
+
context.divisionDepth += 1;
|
|
517
|
+
const body = renderItems(item.children, context);
|
|
518
|
+
context.divisionDepth -= 1;
|
|
519
|
+
return body.split("\n").map((line) => line.length === 0 ? ">" : `> ${line}`).join("\n");
|
|
522
520
|
}
|
|
523
521
|
if (descriptor.kind === "link" && descriptor.target.kind === "external") {
|
|
524
522
|
const onlyChild = item.children.length === 1 && !isConstructItem(item.children[0]) ? item.children[0].block : void 0;
|
|
@@ -549,7 +547,7 @@ function isInheritedListMembership(list, context) {
|
|
|
549
547
|
function renderItems(items, context) {
|
|
550
548
|
const parts = [];
|
|
551
549
|
let index = 0;
|
|
552
|
-
|
|
550
|
+
for (;;) {
|
|
553
551
|
const item = items[index];
|
|
554
552
|
if (item === void 0) break;
|
|
555
553
|
if (isConstructItem(item)) {
|
|
@@ -612,7 +610,7 @@ function emitBlocks(blocks, context) {
|
|
|
612
610
|
}
|
|
613
611
|
function validateRunConstructExtents(blocks) {
|
|
614
612
|
for (const block of blocks) {
|
|
615
|
-
if (block.kind === "paragraph"
|
|
613
|
+
if (block.kind === "paragraph") {
|
|
616
614
|
const fault = (0, document_schema_js.findRunConstructFault)(block);
|
|
617
615
|
if (fault !== void 0) throw new require_diagnostics_diagnostics.MarkdownInvalidRunConstructExtentError(fault.kind, fault.index);
|
|
618
616
|
}
|