@taprootio/site-authoring 0.42.0 → 0.56.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 +110 -12
- package/examples/riverbend-wellness/settings/site-publishing-preferences.json +3 -0
- package/examples/riverbend-wellness/settings/taproot-styles.json +11 -0
- package/package.json +4 -3
- package/src/api.js +242 -23
- package/src/appearance-contract.js +264 -3
- package/src/authored-tag-names.js +88 -0
- package/src/authors-contract.js +71 -3
- package/src/block-flow.js +103 -1
- package/src/brand-color.js +22 -0
- package/src/breadcrumb-artwork.js +234 -0
- package/src/breadcrumb-separators.js +11 -0
- package/src/changelog.json +160 -0
- package/src/chrome-features.js +6 -2
- package/src/chrome-input.js +1 -0
- package/src/chrome-paint-catalog-taproot.json +3 -3
- package/src/chrome-report.js +91 -12
- package/src/cli.js +136 -38
- package/src/constants.js +1 -0
- package/src/content/components.js +27 -4
- package/src/content/external-link.js +2 -1
- package/src/content/markdown.js +271 -101
- package/src/content/tiptap-prosemirror.ts +125 -43
- package/src/content/validate-document.js +4 -1
- package/src/content-inset.js +48 -0
- package/src/errors.js +1 -0
- package/src/espalier-shared.js +26 -0
- package/src/field-suggestions.js +40 -0
- package/src/fixture-init.js +22 -5
- package/src/font-catalog.js +11 -1
- package/src/footer-brand-inputs.js +22 -3
- package/src/footer-content.js +1 -0
- package/src/footer-contract.js +11 -0
- package/src/footer-cta-styles.js +6 -0
- package/src/footer-draft-hash.js +4 -2
- package/src/footer-fit.js +62 -15
- package/src/footer-workspace.js +44 -7
- package/src/latest-posts-tags.js +57 -0
- package/src/page-metadata.js +15 -13
- package/src/page-structure-checks.js +5 -0
- package/src/page-tag-badge-modes.js +6 -0
- package/src/page-tag-writes.js +158 -0
- package/src/page-type-tags.js +16 -0
- package/src/presentation-reference.js +297 -86
- package/src/recipe-page-options.js +22 -0
- package/src/recipe-step-contract.js +164 -0
- package/src/recipe-step-contract.json +65 -0
- package/src/reference-help.js +182 -79
- package/src/session.js +39 -24
- package/src/setting-reference.js +239 -48
- package/src/settings-catalog.js +63 -0
- package/src/site-check-findings.js +23 -5
- package/src/site-check-rules.json +1 -0
- package/src/site-health-findings.js +13 -13
- package/src/styling-fixed-values.js +71 -0
- package/src/tag-destination-warnings.js +35 -0
- package/src/template-token-reach.json +242 -0
- package/src/theme-proposals.js +18 -27
- package/src/theme-resolve.js +265 -23
- package/src/theme-validation.js +118 -7
- package/src/token-reach.js +222 -0
- package/src/typed-page-reference.js +94 -16
- package/src/typed-pages.js +233 -74
- package/src/verbs/authors.js +198 -33
- package/src/verbs/deploy.js +6 -0
- package/src/verbs/footer-push.js +30 -5
- package/src/verbs/forms-push.js +11 -3
- package/src/verbs/index.js +4 -2
- package/src/verbs/pages-delete.js +19 -10
- package/src/verbs/pages-push.js +225 -71
- package/src/verbs/plan.js +10 -4
- package/src/verbs/pull.js +324 -69
- package/src/verbs/staging-review.js +27 -1
- package/src/verbs/status.js +22 -0
- package/src/verbs/theme-push.js +93 -25
- package/src/verbs/theme-resolve.js +189 -55
- package/src/verbs/validate.js +6 -5
- package/src/workspace-check.js +35 -3
- package/src/workspace.js +73 -2
- package/test/fixtures/default-site-theme.json +516 -0
|
@@ -61,7 +61,8 @@ export function newTabAttributeMarkup(rel) {
|
|
|
61
61
|
* `esp-button` read alike. `generator/browser-tests/new-tab-cue.spec.ts` holds
|
|
62
62
|
* the two together.
|
|
63
63
|
*/
|
|
64
|
-
export const
|
|
64
|
+
export const NEW_TAB_LABEL = "opens in a new tab";
|
|
65
|
+
export const NEW_TAB_CUE_TEXT = ` (${NEW_TAB_LABEL})`;
|
|
65
66
|
/**
|
|
66
67
|
* The cue for a native anchor, as its last child. Pagefind indexes raw HTML, so
|
|
67
68
|
* `data-pagefind-ignore` keeps the words out of search content and excerpts.
|
package/src/content/markdown.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SiteAuthoringError } from "../errors.js";
|
|
2
|
+
import { isRecipeStepLinkHref, recipeStepUnsupportedContentMessage } from "../recipe-step-contract.js";
|
|
2
3
|
import { readBlockquoteMetadata, validateBlockquoteMetadata } from "./blockquote-metadata.js";
|
|
3
4
|
import {
|
|
4
5
|
canonicalizeComponentData,
|
|
@@ -91,11 +92,13 @@ const TABLE_DELIMITER_TOKEN_RE = new RegExp(
|
|
|
91
92
|
const TABLE_DELIMITERISH_TOKEN_RE = /^:?-*:?$/u;
|
|
92
93
|
|
|
93
94
|
function fail(code, construct, message, line, cause) {
|
|
94
|
-
|
|
95
|
+
const error = new SiteAuthoringError(
|
|
95
96
|
code,
|
|
96
97
|
line === undefined ? message : `${message} (line ${line})`,
|
|
97
98
|
{ field: construct, cause },
|
|
98
99
|
);
|
|
100
|
+
if (line !== undefined) Object.defineProperty(error, "markdownLine", { value: line });
|
|
101
|
+
return error;
|
|
99
102
|
}
|
|
100
103
|
|
|
101
104
|
// ---------------------------------------------------------------------------
|
|
@@ -128,7 +131,7 @@ function isBlank(text) {
|
|
|
128
131
|
* name the line the author has to look at, including inside a blockquote or a
|
|
129
132
|
* list item where the text has been re-indented.
|
|
130
133
|
*/
|
|
131
|
-
function toLines(markdown) {
|
|
134
|
+
function toLines(markdown, firstLine = 1) {
|
|
132
135
|
const normalized = markdown.replaceAll("\r\n", "\n").replaceAll("\r", "\n");
|
|
133
136
|
for (const character of normalized) {
|
|
134
137
|
const codePoint = character.codePointAt(0);
|
|
@@ -136,7 +139,7 @@ function toLines(markdown) {
|
|
|
136
139
|
throw fail(CODES.markdownControl, "control character", "The Markdown source contains a control character.");
|
|
137
140
|
}
|
|
138
141
|
}
|
|
139
|
-
return normalized.split("\n").map((text, index) => ({ text, number:
|
|
142
|
+
return normalized.split("\n").map((text, index) => ({ text, number: firstLine + index }));
|
|
140
143
|
}
|
|
141
144
|
|
|
142
145
|
/**
|
|
@@ -294,6 +297,64 @@ function guardBlockConstructs(text, line, nextText) {
|
|
|
294
297
|
}
|
|
295
298
|
}
|
|
296
299
|
|
|
300
|
+
function nextRecipeStepLine(lines, start, keepGoing) {
|
|
301
|
+
let next = start;
|
|
302
|
+
while (next < lines.length && keepGoing(expandLeadingTabs(lines[next].text))) next += 1;
|
|
303
|
+
return next;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// A step uses the same block recognizers. Skip discarded constructs without
|
|
307
|
+
// resolving their media or parsing their payload as if it belonged to a step.
|
|
308
|
+
function unsupportedRecipeStepBlock(lines, index, text) {
|
|
309
|
+
const nextText = expandLeadingTabs(lines[index + 1]?.text ?? "");
|
|
310
|
+
const table = tablePrelude(lines, index);
|
|
311
|
+
if (table) {
|
|
312
|
+
return ["table", nextRecipeStepLine(lines, table.headerIndex + 2, line => !isBlank(line) && tableRowCells(line) !== undefined)];
|
|
313
|
+
}
|
|
314
|
+
const fence = FENCE_RE.exec(text);
|
|
315
|
+
if (fence) {
|
|
316
|
+
const info = fence[3].trim();
|
|
317
|
+
const end = fenceClosing(fence[2]);
|
|
318
|
+
const type = info.startsWith("component:") ? "componentBlock"
|
|
319
|
+
: info === INLINE_FACTS_CONTRACT.markdown.fence ? "inlineFacts" : "codeBlock";
|
|
320
|
+
return [type, Math.min(lines.length, nextRecipeStepLine(lines, index + 1, line => !end.test(line)) + 1)];
|
|
321
|
+
}
|
|
322
|
+
if (indentOf(text) >= 4) {
|
|
323
|
+
return ["indentedCodeBlock", nextRecipeStepLine(lines, index + 1, line => indentOf(line) >= 4 || isBlank(line))];
|
|
324
|
+
}
|
|
325
|
+
if (ATX_RE.test(text)) return ["heading", index + 1];
|
|
326
|
+
if (SETEXT_RE.test(nextText) && !isBlockStart(text)) return ["heading", index + 2];
|
|
327
|
+
if (THEMATIC_RE.test(text)) return ["horizontalRule", index + 1];
|
|
328
|
+
if (BLOCKQUOTE_RE.test(text)) {
|
|
329
|
+
return ["blockquote", nextRecipeStepLine(lines, index + 1, line =>
|
|
330
|
+
BLOCKQUOTE_RE.test(line) || (!isBlank(line) && !isBlockStart(line)))];
|
|
331
|
+
}
|
|
332
|
+
if (STANDALONE_IMAGE_RE.test(text.trim())) return ["taprootImage", index + 1];
|
|
333
|
+
const list = BULLET_RE.test(text) ? [BULLET_RE, "bulletList"] : ORDERED_RE.test(text) ? [ORDERED_RE, "orderedList"] : undefined;
|
|
334
|
+
if (list) {
|
|
335
|
+
const [marker, type] = list;
|
|
336
|
+
return [type, nextRecipeStepLine(lines, index + 1, line => marker.test(line) || (!isBlank(line) && !isBlockStart(line)))];
|
|
337
|
+
}
|
|
338
|
+
if (BLOCKQUOTE_DIRECTIVE_LIKE_RE.test(text)) {
|
|
339
|
+
const marker = BLOCKQUOTE_CONTRACT.markdown.close;
|
|
340
|
+
const next = text.trim() === marker ? index + 1
|
|
341
|
+
: Math.min(lines.length, nextRecipeStepLine(lines, index + 1, line => line.trim() !== marker) + 1);
|
|
342
|
+
return ["blockquote", next];
|
|
343
|
+
}
|
|
344
|
+
if (SECTION_HEADER_LIKE_RE.test(text) || SECTION_CLOSE_RE.test(text)) {
|
|
345
|
+
const next = SECTION_CLOSE_RE.test(text) ? index + 1
|
|
346
|
+
: Math.min(lines.length, nextRecipeStepLine(lines, index + 1, line => !SECTION_CLOSE_RE.test(line)) + 1);
|
|
347
|
+
return ["section", next];
|
|
348
|
+
}
|
|
349
|
+
if (COLUMNS_DIRECTIVE_LIKE_RE.test(text)) {
|
|
350
|
+
const next = text.startsWith(":::columns")
|
|
351
|
+
? Math.min(lines.length, nextRecipeStepLine(lines, index + 1, line => line.trim() !== ":::endcolumns") + 1)
|
|
352
|
+
: index + 1;
|
|
353
|
+
return ["columns", next];
|
|
354
|
+
}
|
|
355
|
+
return undefined;
|
|
356
|
+
}
|
|
357
|
+
|
|
297
358
|
async function parseBlocks(lines, context, depth) {
|
|
298
359
|
if (depth > CONTENT_LIMITS.markdownNesting) {
|
|
299
360
|
throw fail(
|
|
@@ -315,6 +376,19 @@ async function parseBlocks(lines, context, depth) {
|
|
|
315
376
|
continue;
|
|
316
377
|
}
|
|
317
378
|
|
|
379
|
+
if (context.recipeStepIssues !== undefined) {
|
|
380
|
+
const unsupported = unsupportedRecipeStepBlock(lines, index, text);
|
|
381
|
+
if (unsupported !== undefined) {
|
|
382
|
+
const [type, next] = unsupported;
|
|
383
|
+
context.recipeStepIssues.push({
|
|
384
|
+
line: line.number,
|
|
385
|
+
message: recipeStepUnsupportedContentMessage(type),
|
|
386
|
+
});
|
|
387
|
+
index = next;
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
318
392
|
// Four columns of indentation is an indented code block in CommonMark,
|
|
319
393
|
// ahead of every other block type. It cannot interrupt a paragraph, so
|
|
320
394
|
// this only ever fires on a line that starts a block.
|
|
@@ -436,9 +510,19 @@ async function parseBlocks(lines, context, depth) {
|
|
|
436
510
|
continue;
|
|
437
511
|
}
|
|
438
512
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
513
|
+
try {
|
|
514
|
+
const consumed = await consumeParagraph(lines, index, context);
|
|
515
|
+
if (consumed.node) nodes.push(consumed.node);
|
|
516
|
+
index = consumed.next;
|
|
517
|
+
} catch (error) {
|
|
518
|
+
if (context.recipeStepIssues === undefined || !(error instanceof SiteAuthoringError)) throw error;
|
|
519
|
+
context.recipeStepIssues.push({
|
|
520
|
+
line: error.markdownLine ?? line.number,
|
|
521
|
+
message: error.message.replace(/ \(line \d+\)$/u, ""),
|
|
522
|
+
});
|
|
523
|
+
index = nextRecipeStepLine(lines, index + 1, line =>
|
|
524
|
+
!isBlank(line) && !isBlockStart(line) && !STANDALONE_IMAGE_RE.test(line.trim()));
|
|
525
|
+
}
|
|
442
526
|
}
|
|
443
527
|
|
|
444
528
|
return nodes;
|
|
@@ -1255,31 +1339,48 @@ async function consumeParagraph(lines, start, context) {
|
|
|
1255
1339
|
const line = lines[index];
|
|
1256
1340
|
const text = expandLeadingTabs(line.text);
|
|
1257
1341
|
if (isBlank(text)) break;
|
|
1258
|
-
|
|
1259
|
-
if (
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1342
|
+
try {
|
|
1343
|
+
if (collected.length > 0) {
|
|
1344
|
+
if (SETEXT_RE.test(text)) {
|
|
1345
|
+
throw fail(
|
|
1346
|
+
CODES.markdownSetext,
|
|
1347
|
+
"setext heading",
|
|
1348
|
+
"Setext headings are outside the supported subset; use '#' or '##'.",
|
|
1349
|
+
line.number,
|
|
1350
|
+
);
|
|
1351
|
+
}
|
|
1352
|
+
if (tablePrelude(lines, index)) break;
|
|
1353
|
+
if (isBlockStart(text)) break;
|
|
1354
|
+
if (context.recipeStepIssues !== undefined && STANDALONE_IMAGE_RE.test(text.trim())) break;
|
|
1266
1355
|
}
|
|
1267
|
-
|
|
1268
|
-
|
|
1356
|
+
guardBlockConstructs(text, line, index + 1 < lines.length ? expandLeadingTabs(lines[index + 1].text) : undefined);
|
|
1357
|
+
} catch (error) {
|
|
1358
|
+
if (context.recipeStepIssues === undefined || !(error instanceof SiteAuthoringError)) throw error;
|
|
1359
|
+
// Parse the buffered inline text before resuming after the offending line.
|
|
1360
|
+
context.recipeStepIssues.push({
|
|
1361
|
+
line: error.markdownLine ?? line.number,
|
|
1362
|
+
message: error.message.replace(/ \(line \d+\)$/u, ""),
|
|
1363
|
+
});
|
|
1364
|
+
index += 1;
|
|
1365
|
+
break;
|
|
1269
1366
|
}
|
|
1270
|
-
guardBlockConstructs(text, line, index + 1 < lines.length ? expandLeadingTabs(lines[index + 1].text) : undefined);
|
|
1271
1367
|
collected.push({ text: text.trim(), number: line.number, raw: text });
|
|
1272
1368
|
index += 1;
|
|
1273
1369
|
}
|
|
1274
1370
|
|
|
1275
1371
|
const line = lines[start];
|
|
1276
|
-
const
|
|
1372
|
+
const inlineSource = context.recipeStepIssues === undefined ? undefined : {
|
|
1373
|
+
lineStarts: [],
|
|
1374
|
+
offset: 0,
|
|
1375
|
+
issues: context.recipeStepIssues,
|
|
1376
|
+
};
|
|
1377
|
+
const joined = joinParagraphLines(collected, inlineSource?.lineStarts);
|
|
1277
1378
|
const standalone = STANDALONE_IMAGE_RE.exec(joined);
|
|
1278
1379
|
if (standalone) {
|
|
1279
1380
|
return { node: await imageNode(standalone[1], standalone[2], context, line), next: index };
|
|
1280
1381
|
}
|
|
1281
1382
|
|
|
1282
|
-
const content = parseInline(joined, context.scan, line.number, []);
|
|
1383
|
+
const content = parseInline(joined, context.scan, line.number, [], inlineSource);
|
|
1283
1384
|
return { node: content.length > 0 ? { type: "paragraph", content } : undefined, next: index };
|
|
1284
1385
|
}
|
|
1285
1386
|
|
|
@@ -1291,13 +1392,14 @@ async function consumeParagraph(lines, start, context) {
|
|
|
1291
1392
|
* stores continued text. Joining before the inline pass — rather than parsing
|
|
1292
1393
|
* each line separately — is what lets `**bold` on one line close on the next.
|
|
1293
1394
|
*/
|
|
1294
|
-
function joinParagraphLines(collected) {
|
|
1395
|
+
function joinParagraphLines(collected, lineStarts) {
|
|
1295
1396
|
let joined = "";
|
|
1296
1397
|
collected.forEach((entry, position) => {
|
|
1297
1398
|
const last = position === collected.length - 1;
|
|
1298
1399
|
const hardBySpaces = /[ ]{2,}$/u.test(entry.raw);
|
|
1299
1400
|
const hardByBackslash = /(^|[^\\])\\$/u.test(entry.text);
|
|
1300
1401
|
const text = hardByBackslash ? entry.text.slice(0, -1) : entry.text;
|
|
1402
|
+
lineStarts?.push({ offset: joined.length, line: entry.number });
|
|
1301
1403
|
joined += text;
|
|
1302
1404
|
if (last) return;
|
|
1303
1405
|
joined += hardBySpaces || hardByBackslash ? HARD_BREAK : " ";
|
|
@@ -1456,7 +1558,41 @@ function findLinkTextEnd(text, start, scan, lineNumber) {
|
|
|
1456
1558
|
return -1;
|
|
1457
1559
|
}
|
|
1458
1560
|
|
|
1459
|
-
function
|
|
1561
|
+
function inlineSourceLine(source, offset, fallback) {
|
|
1562
|
+
if (source === undefined) return fallback;
|
|
1563
|
+
// Find the last physical line whose joined-text offset starts at or before
|
|
1564
|
+
// this token. Recursive mark scans keep the same map with a shifted offset.
|
|
1565
|
+
const position = source.offset + offset;
|
|
1566
|
+
let start = 0;
|
|
1567
|
+
let end = source.lineStarts.length;
|
|
1568
|
+
while (start + 1 < end) {
|
|
1569
|
+
const middle = start + Math.floor((end - start) / 2);
|
|
1570
|
+
if (source.lineStarts[middle].offset <= position) start = middle;
|
|
1571
|
+
else end = middle;
|
|
1572
|
+
}
|
|
1573
|
+
return source.lineStarts[start].line;
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
function sliceInlineSource(source, start) {
|
|
1577
|
+
return source === undefined ? undefined : { ...source, offset: source.offset + start };
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
function reportInlineIssue(error, source) {
|
|
1581
|
+
if (source === undefined) throw error;
|
|
1582
|
+
source.issues.push({
|
|
1583
|
+
line: error.markdownLine,
|
|
1584
|
+
message: error.message.replace(/ \(line \d+\)$/u, ""),
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
function inlineImageEnd(text, index, scan, lineNumber) {
|
|
1589
|
+
const bracket = findLinkTextEnd(text, index + 2, scan, lineNumber);
|
|
1590
|
+
if (bracket < 0) return index + 2;
|
|
1591
|
+
const end = text[bracket + 1] === "(" ? findDestinationEnd(text, bracket + 2, scan, lineNumber) : -1;
|
|
1592
|
+
return Math.max(bracket, end) + 1;
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
function parseInline(text, scan, lineNumber, marks, source) {
|
|
1460
1596
|
const nodes = [];
|
|
1461
1597
|
let buffer = "";
|
|
1462
1598
|
const flush = () => {
|
|
@@ -1489,32 +1625,40 @@ function parseInline(text, scan, lineNumber, marks) {
|
|
|
1489
1625
|
continue;
|
|
1490
1626
|
}
|
|
1491
1627
|
|
|
1492
|
-
|
|
1493
|
-
|
|
1628
|
+
const entity = character === "&" ? ENTITY_RE.exec(text.slice(index)) : null;
|
|
1629
|
+
if (entity) {
|
|
1630
|
+
reportInlineIssue(fail(
|
|
1494
1631
|
CODES.markdownEntity,
|
|
1495
1632
|
"HTML entity",
|
|
1496
1633
|
"HTML entities are outside the supported subset; write the character itself.",
|
|
1497
|
-
lineNumber,
|
|
1498
|
-
);
|
|
1634
|
+
inlineSourceLine(source, index, lineNumber),
|
|
1635
|
+
), source);
|
|
1636
|
+
index += entity[0].length;
|
|
1637
|
+
continue;
|
|
1499
1638
|
}
|
|
1500
1639
|
|
|
1501
1640
|
if (character === "<") {
|
|
1502
1641
|
const rest = text.slice(index);
|
|
1503
|
-
|
|
1504
|
-
|
|
1642
|
+
const autolink = AUTOLINK_RE.exec(rest);
|
|
1643
|
+
if (autolink) {
|
|
1644
|
+
reportInlineIssue(fail(
|
|
1505
1645
|
CODES.markdownAutolink,
|
|
1506
1646
|
"autolink",
|
|
1507
1647
|
"Autolinks are outside the supported subset; write [text](url).",
|
|
1508
|
-
lineNumber,
|
|
1509
|
-
);
|
|
1648
|
+
inlineSourceLine(source, index, lineNumber),
|
|
1649
|
+
), source);
|
|
1650
|
+
index += autolink[0].length;
|
|
1651
|
+
continue;
|
|
1510
1652
|
}
|
|
1511
1653
|
if (HTML_TAG_RE.test(rest)) {
|
|
1512
|
-
|
|
1654
|
+
reportInlineIssue(fail(
|
|
1513
1655
|
CODES.markdownHtml,
|
|
1514
1656
|
"inline HTML",
|
|
1515
1657
|
"Inline HTML is outside the supported subset; it would publish verbatim and unsanitised.",
|
|
1516
|
-
lineNumber,
|
|
1517
|
-
);
|
|
1658
|
+
inlineSourceLine(source, index, lineNumber),
|
|
1659
|
+
), source);
|
|
1660
|
+
index = Math.max(index, text.indexOf(">", index + 1)) + 1;
|
|
1661
|
+
continue;
|
|
1518
1662
|
}
|
|
1519
1663
|
buffer += character;
|
|
1520
1664
|
index += 1;
|
|
@@ -1522,7 +1666,7 @@ function parseInline(text, scan, lineNumber, marks) {
|
|
|
1522
1666
|
}
|
|
1523
1667
|
|
|
1524
1668
|
if (character === "`") {
|
|
1525
|
-
const span = matchCodeSpan(text, index, scan, lineNumber);
|
|
1669
|
+
const span = matchCodeSpan(text, index, scan, inlineSourceLine(source, index, lineNumber));
|
|
1526
1670
|
if (span) {
|
|
1527
1671
|
flush();
|
|
1528
1672
|
nodes.push(textNode(normalizeCodeSpan(span.content), [...marks, { type: "code" }]));
|
|
@@ -1535,24 +1679,31 @@ function parseInline(text, scan, lineNumber, marks) {
|
|
|
1535
1679
|
}
|
|
1536
1680
|
|
|
1537
1681
|
if (character === "!" && text[index + 1] === "[") {
|
|
1538
|
-
|
|
1682
|
+
const sourceLine = inlineSourceLine(source, index, lineNumber);
|
|
1683
|
+
reportInlineIssue(fail(
|
|
1539
1684
|
CODES.markdownImage,
|
|
1540
1685
|
"inline image",
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1686
|
+
source === undefined
|
|
1687
|
+
? "An image must stand alone in its own block; the document model has no inline image."
|
|
1688
|
+
: recipeStepUnsupportedContentMessage("inlineImage"),
|
|
1689
|
+
sourceLine,
|
|
1690
|
+
), source);
|
|
1691
|
+
index = inlineImageEnd(text, index, scan, sourceLine);
|
|
1692
|
+
continue;
|
|
1544
1693
|
}
|
|
1545
1694
|
|
|
1546
1695
|
if (character === "[") {
|
|
1547
1696
|
if (text[index + 1] === "^") {
|
|
1548
|
-
|
|
1697
|
+
reportInlineIssue(fail(
|
|
1549
1698
|
CODES.markdownFootnote,
|
|
1550
1699
|
"footnote",
|
|
1551
1700
|
"Footnotes are outside the supported Markdown subset.",
|
|
1552
|
-
lineNumber,
|
|
1553
|
-
);
|
|
1701
|
+
inlineSourceLine(source, index, lineNumber),
|
|
1702
|
+
), source);
|
|
1703
|
+
index = Math.max(index, text.indexOf("]", index + 2)) + 1;
|
|
1704
|
+
continue;
|
|
1554
1705
|
}
|
|
1555
|
-
const link = parseLink(text, index, scan, lineNumber, marks);
|
|
1706
|
+
const link = parseLink(text, index, scan, lineNumber, marks, source);
|
|
1556
1707
|
if (link) {
|
|
1557
1708
|
flush();
|
|
1558
1709
|
nodes.push(...link.nodes);
|
|
@@ -1564,7 +1715,7 @@ function parseInline(text, scan, lineNumber, marks) {
|
|
|
1564
1715
|
continue;
|
|
1565
1716
|
}
|
|
1566
1717
|
|
|
1567
|
-
const emphasis = parseEmphasis(text, index, scan, lineNumber, marks);
|
|
1718
|
+
const emphasis = parseEmphasis(text, index, scan, lineNumber, marks, source);
|
|
1568
1719
|
if (emphasis) {
|
|
1569
1720
|
flush();
|
|
1570
1721
|
nodes.push(...emphasis.nodes);
|
|
@@ -1601,7 +1752,7 @@ const EMPHASIS_DELIMITERS = Object.freeze([
|
|
|
1601
1752
|
{ delimiter: "_", types: Object.freeze(["italic"]), underscore: true },
|
|
1602
1753
|
]);
|
|
1603
1754
|
|
|
1604
|
-
function parseEmphasis(text, index, scan, lineNumber, marks) {
|
|
1755
|
+
function parseEmphasis(text, index, scan, lineNumber, marks, source) {
|
|
1605
1756
|
for (const candidate of EMPHASIS_DELIMITERS) {
|
|
1606
1757
|
if (!text.startsWith(candidate.delimiter, index)) continue;
|
|
1607
1758
|
if (!isFlanking(text, index, candidate.delimiter.length)) continue;
|
|
@@ -1610,69 +1761,61 @@ function parseEmphasis(text, index, scan, lineNumber, marks) {
|
|
|
1610
1761
|
if (candidate.underscore && index > 0 && !/[\s\p{P}]/u.test(text[index - 1])) continue;
|
|
1611
1762
|
if (candidate.types.some((type) => marks.some((mark) => mark.type === type))) continue;
|
|
1612
1763
|
const from = index + candidate.delimiter.length;
|
|
1613
|
-
const close = findClosing(text, from, candidate.delimiter, candidate.underscore, scan, lineNumber);
|
|
1764
|
+
const close = findClosing(text, from, candidate.delimiter, candidate.underscore, scan, inlineSourceLine(source, index, lineNumber));
|
|
1614
1765
|
if (close < 0) continue;
|
|
1615
1766
|
const inner = text.slice(from, close);
|
|
1616
1767
|
if (inner.trim() === "") continue;
|
|
1617
1768
|
return {
|
|
1618
|
-
nodes: parseInline(inner, scan, lineNumber, [...marks, ...candidate.types.map((type) => ({ type }))]),
|
|
1769
|
+
nodes: parseInline(inner, scan, lineNumber, [...marks, ...candidate.types.map((type) => ({ type }))], sliceInlineSource(source, from)),
|
|
1619
1770
|
end: close + candidate.delimiter.length,
|
|
1620
1771
|
};
|
|
1621
1772
|
}
|
|
1622
1773
|
return undefined;
|
|
1623
1774
|
}
|
|
1624
1775
|
|
|
1625
|
-
function parseLink(text, index, scan, lineNumber, marks) {
|
|
1626
|
-
const
|
|
1776
|
+
function parseLink(text, index, scan, lineNumber, marks, source) {
|
|
1777
|
+
const line = inlineSourceLine(source, index, lineNumber);
|
|
1778
|
+
const textEnd = findLinkTextEnd(text, index + 1, scan, line);
|
|
1627
1779
|
if (textEnd < 0) return undefined;
|
|
1628
1780
|
const after = text[textEnd + 1];
|
|
1629
1781
|
if (after === "[") {
|
|
1630
|
-
|
|
1782
|
+
reportInlineIssue(fail(
|
|
1631
1783
|
CODES.markdownReferenceLink,
|
|
1632
1784
|
"reference link",
|
|
1633
1785
|
"Reference-style links are outside the supported subset; write the URL inline.",
|
|
1634
|
-
|
|
1635
|
-
);
|
|
1786
|
+
line,
|
|
1787
|
+
), source);
|
|
1788
|
+
const referenceEnd = findLinkTextEnd(text, textEnd + 2, scan, line);
|
|
1789
|
+
return { nodes: [], end: Math.max(textEnd + 1, referenceEnd) + 1 };
|
|
1636
1790
|
}
|
|
1637
1791
|
if (after !== "(") return undefined;
|
|
1638
1792
|
|
|
1639
|
-
const destinationEnd = findDestinationEnd(text, textEnd + 2, scan,
|
|
1793
|
+
const destinationEnd = findDestinationEnd(text, textEnd + 2, scan, line);
|
|
1640
1794
|
if (destinationEnd < 0) return undefined;
|
|
1641
1795
|
const destination = text.slice(textEnd + 2, destinationEnd).trim();
|
|
1796
|
+
const isAllowedDestination = source === undefined ? isSafeUrl : isRecipeStepLinkHref;
|
|
1797
|
+
const before = source?.issues.length;
|
|
1798
|
+
let refusal;
|
|
1642
1799
|
if (marks.some((mark) => mark.type === "link")) {
|
|
1643
|
-
|
|
1644
|
-
}
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
"
|
|
1649
|
-
"
|
|
1650
|
-
|
|
1651
|
-
);
|
|
1652
|
-
}
|
|
1653
|
-
if (
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
"link",
|
|
1657
|
-
"Link titles are outside the supported subset; the document model has nowhere to put one.",
|
|
1658
|
-
lineNumber,
|
|
1659
|
-
);
|
|
1660
|
-
}
|
|
1661
|
-
if (destination === "" || !isSafeUrl(destination)) {
|
|
1662
|
-
throw fail(
|
|
1663
|
-
CODES.markdownLink,
|
|
1664
|
-
"link",
|
|
1665
|
-
"A link destination must be a safe HTTP(S), mailto, tel, non-protocol-relative root, fragment, query, or relative URL without backslashes or ASCII controls; the renderer drops an unsafe link and publishes only its text.",
|
|
1666
|
-
lineNumber,
|
|
1667
|
-
);
|
|
1668
|
-
}
|
|
1669
|
-
|
|
1670
|
-
const options = parseLinkAttributes(text, destinationEnd + 1, lineNumber);
|
|
1800
|
+
refusal = "Links cannot be nested.";
|
|
1801
|
+
} else if (destination.startsWith("<")) {
|
|
1802
|
+
refusal = "Pointy-bracket link destinations are outside the supported subset; write the URL directly.";
|
|
1803
|
+
} else if (/\s/u.test(destination)) {
|
|
1804
|
+
refusal = source === undefined
|
|
1805
|
+
? "Link titles are outside the supported subset; the document model has nowhere to put one."
|
|
1806
|
+
: "Use a plain link destination and put the title in attribute braces.";
|
|
1807
|
+
} else if (destination === "" || !isAllowedDestination(destination)) {
|
|
1808
|
+
refusal = "A link destination must be a safe HTTP(S), mailto, tel, non-protocol-relative root, fragment, query, or relative URL without backslashes or ASCII controls; the renderer drops an unsafe link and publishes only its text.";
|
|
1809
|
+
}
|
|
1810
|
+
if (refusal !== undefined) reportInlineIssue(fail(CODES.markdownLink, "link", refusal, line), source);
|
|
1811
|
+
|
|
1812
|
+
const options = parseLinkAttributes(text, destinationEnd + 1, line, source);
|
|
1671
1813
|
const attrs = { href: destination, ...options?.attrs };
|
|
1672
1814
|
const inner = text.slice(index + 1, textEnd);
|
|
1673
|
-
const
|
|
1674
|
-
|
|
1675
|
-
|
|
1815
|
+
const innerMarks = refusal === undefined ? [...marks, { type: "link", attrs }] : marks;
|
|
1816
|
+
const nodes = parseInline(inner, scan, lineNumber, innerMarks, sliceInlineSource(source, index + 1));
|
|
1817
|
+
if (nodes.length === 0 && before === source?.issues.length) {
|
|
1818
|
+
reportInlineIssue(fail(CODES.markdownLink, "link", "A link must have text.", line), source);
|
|
1676
1819
|
}
|
|
1677
1820
|
return { nodes, end: options ? options.end : destinationEnd + 1 };
|
|
1678
1821
|
}
|
|
@@ -1683,32 +1826,53 @@ function parseLink(text, index, scan, lineNumber, marks) {
|
|
|
1683
1826
|
* Braces that start `{rel=` or `{target=` are attributes and must be well
|
|
1684
1827
|
* formed; any other brace after a link stays literal text.
|
|
1685
1828
|
*/
|
|
1686
|
-
function parseLinkAttributes(text, from, lineNumber) {
|
|
1829
|
+
function parseLinkAttributes(text, from, lineNumber, source) {
|
|
1830
|
+
const recipeStep = source !== undefined;
|
|
1687
1831
|
const rest = text.slice(from);
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
const
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1832
|
+
const prefix = recipeStep ? /^\{\s*[A-Za-z][\w-]*\s*=/u : /^\{\s*(?:rel|target)\s*=/u;
|
|
1833
|
+
if (!prefix.test(rest)) return undefined;
|
|
1834
|
+
const attributes = recipeStep ? /^\{((?:\s*[A-Za-z][\w-]*="[^"\\{}]*")+)\s*\}/u
|
|
1835
|
+
: /^\{((?:\s*(?:rel|target)="[^"\\{}]*")+)\s*\}/u;
|
|
1836
|
+
const match = attributes.exec(rest);
|
|
1837
|
+
const pairs = match ? [...match[1].matchAll(/([A-Za-z][\w-]*)="([^"]*)"/gu)] : [];
|
|
1838
|
+
if (!match || (!recipeStep && new Set(pairs.map(pair => pair[1])).size !== pairs.length)) {
|
|
1839
|
+
reportInlineIssue(fail(
|
|
1694
1840
|
CODES.markdownLink,
|
|
1695
1841
|
"link attributes",
|
|
1696
1842
|
'Write a link\'s attributes right after it as {rel="nofollow" target="_blank"}: each at most once, '
|
|
1697
1843
|
+ "double-quoted. Escape a literal brace as \\{.",
|
|
1698
|
-
lineNumber,
|
|
1699
|
-
);
|
|
1844
|
+
inlineSourceLine(source, from, lineNumber),
|
|
1845
|
+
), source);
|
|
1846
|
+
return { attrs: {}, end: from + Math.max(0, rest.indexOf("}")) + 1 };
|
|
1700
1847
|
}
|
|
1701
1848
|
const attrs = {};
|
|
1702
|
-
|
|
1849
|
+
const seen = new Set();
|
|
1850
|
+
for (const pair of pairs) {
|
|
1851
|
+
const [, name, value] = pair;
|
|
1852
|
+
const line = inlineSourceLine(source, from + 1 + pair.index, lineNumber);
|
|
1853
|
+
if (seen.has(name)) {
|
|
1854
|
+
reportInlineIssue(fail(CODES.markdownLink, "link attributes", `A link repeats the ${name} attribute.`, line), source);
|
|
1855
|
+
continue;
|
|
1856
|
+
}
|
|
1857
|
+
seen.add(name);
|
|
1858
|
+
if (name === "title" && recipeStep) {
|
|
1859
|
+
attrs.title = value;
|
|
1860
|
+
continue;
|
|
1861
|
+
}
|
|
1862
|
+
if (name !== "rel" && name !== "target") {
|
|
1863
|
+
reportInlineIssue(fail(CODES.markdownLink, "link attributes", `A recipe step link does not support the ${name} attribute.`, line), source);
|
|
1864
|
+
continue;
|
|
1865
|
+
}
|
|
1703
1866
|
if (name === "target") {
|
|
1704
1867
|
const target = value.trim().toLowerCase();
|
|
1705
1868
|
if (!LINK_TARGETS.includes(target)) {
|
|
1706
|
-
|
|
1869
|
+
reportInlineIssue(fail(
|
|
1707
1870
|
CODES.linkTarget,
|
|
1708
1871
|
"link target",
|
|
1709
1872
|
`A link's target is "_blank" (open in a new tab) or "_self"; "${value}" is not one.`,
|
|
1710
|
-
|
|
1711
|
-
);
|
|
1873
|
+
line,
|
|
1874
|
+
), source);
|
|
1875
|
+
continue;
|
|
1712
1876
|
}
|
|
1713
1877
|
attrs.target = target;
|
|
1714
1878
|
continue;
|
|
@@ -1716,7 +1880,7 @@ function parseLinkAttributes(text, from, lineNumber) {
|
|
|
1716
1880
|
const tokens = value.trim().toLowerCase().split(/\s+/u).filter(Boolean);
|
|
1717
1881
|
const unknown = tokens.filter((token) => !LINK_REL_TOKENS.includes(token));
|
|
1718
1882
|
if (tokens.length === 0 || unknown.length > 0) {
|
|
1719
|
-
|
|
1883
|
+
reportInlineIssue(fail(
|
|
1720
1884
|
CODES.linkRel,
|
|
1721
1885
|
"link rel",
|
|
1722
1886
|
`A link's rel takes space-separated link types from ${LINK_REL_TOKENS.join(", ")}; ${
|
|
@@ -1724,8 +1888,9 @@ function parseLinkAttributes(text, from, lineNumber) {
|
|
|
1724
1888
|
? `${unknown.map((token) => `"${token}"`).join(", ")} ${unknown.length === 1 ? "is" : "are"} not one`
|
|
1725
1889
|
: "this one is empty"
|
|
1726
1890
|
}.`,
|
|
1727
|
-
|
|
1728
|
-
);
|
|
1891
|
+
line,
|
|
1892
|
+
), source);
|
|
1893
|
+
continue;
|
|
1729
1894
|
}
|
|
1730
1895
|
// Vocabulary order, so a written rel can never read as the editor's old
|
|
1731
1896
|
// default ("noopener noreferrer nofollow"), which means no choice.
|
|
@@ -1907,14 +2072,19 @@ export async function markdownToProseMirror(markdown, options = {}) {
|
|
|
1907
2072
|
);
|
|
1908
2073
|
}
|
|
1909
2074
|
|
|
1910
|
-
const
|
|
1911
|
-
|
|
2075
|
+
const recipeStepIssues = options.recipeStep === true ? [] : undefined;
|
|
2076
|
+
const lines = toLines(markdown, recipeStepIssues === undefined ? 1 : options.firstLine);
|
|
2077
|
+
if (recipeStepIssues === undefined) rejectFrontMatter(lines);
|
|
1912
2078
|
const content = await parseBlocks(
|
|
1913
2079
|
lines,
|
|
1914
|
-
{ resolveImage, scan: createScanBudget(), blockPlacement: "root" },
|
|
2080
|
+
{ resolveImage, scan: createScanBudget(), blockPlacement: "root", recipeStepIssues },
|
|
1915
2081
|
0,
|
|
1916
2082
|
);
|
|
1917
2083
|
const document = { type: "doc", content };
|
|
2084
|
+
if (recipeStepIssues !== undefined) {
|
|
2085
|
+
recipeStepIssues.sort((left, right) => left.line - right.line);
|
|
2086
|
+
return { doc: document, recipeStepIssues };
|
|
2087
|
+
}
|
|
1918
2088
|
if (!documentIsPresent(document)) {
|
|
1919
2089
|
throw fail(
|
|
1920
2090
|
CODES.markdownEmpty,
|