This commit is contained in:
Ian Gulliver
2026-10-16 13:03:22 -07:00
parent d9e0498d10
commit 5b22e5bc70
6 changed files with 49 additions and 3 deletions
+8 -1
View File
@@ -19,7 +19,8 @@ const bullet = /^(\s*)[-*+]\s+(.*)$/;
const ordered = /^(\s*)(\d+)[.)]\s+(.*)$/;
const quote = /^\s*>\s?(.*)$/;
const rule = /^\s*([-*_])(\s*\1){2,}\s*$/;
const tableSep = /^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/;
const imageOnly = /^\s*!\[[^\]]*\]\((<[^>]*>|[^)]*)\)\s*$/;
const tableSep =/^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/;
export function markdown(src: string, className = "md", opts: Options = {}): HTMLElement {
return h("div", { class: className }, ...blocks(src.replace(/\r\n?/g, "\n").split("\n"), opts));
@@ -194,6 +195,7 @@ function parseList(lines: string[], start: number, opts: Options): [HTMLElement,
}
let i = start;
let imageChoices = !isOrdered && !!opts.choice;
while (i < lines.length) {
const line = lines[i]!;
const m = isOrdered ? ordered.exec(line) : bullet.exec(line);
@@ -220,11 +222,16 @@ function parseList(lines: string[], start: number, opts: Options): [HTMLElement,
body.push(indentOf(next) > base ? next.slice(Math.min(indentOf(next), base + 2)) : next.trim());
i++;
}
const detail = body.slice(1).filter((l) => l.trim() !== "");
imageChoices &&= choiceMarker.test(text) && detail.length === 1 && imageOnly.test(detail[0]!);
list.append(item(body, isOrdered ? { taskId: opts.taskId } : opts));
while (i < lines.length && lines[i]!.trim() === "" && lines[i + 1] !== undefined && indentOf(lines[i + 1]!) === base && (isOrdered ? ordered : bullet).test(lines[i + 1]!)) {
i++;
}
}
if (imageChoices) {
list.className = "choice-grid";
}
return [list, i];
}