// Текст вики-разметки Jira без разметки — как читается отрендеренным (лента изменений, С6). // Блоки соединены пробелом; «одну строку» и обрезку делает вызывающий. import type { Inline, WikiOptions } from "./inline.ts"; import { type Block, type ListBlock, parseWiki } from "./parse.ts"; function inline(nodes: Inline[]): string { return nodes.map((n): string => { switch (n.t) { case "text": case "code": return n.text; case "mention": return "@" + n.login; case "br": return " "; case "issue": return n.children.length ? inline(n.children) : n.key; default: return inline(n.children); } }).join(""); } function list(l: ListBlock): string[] { return l.items.flatMap((it) => [inline(it.children), ...it.lists.flatMap(list)]); } function block(b: Block): string[] { switch (b.t) { case "heading": case "p": return [inline(b.children)]; case "list": return list(b); case "table": return b.rows.flatMap((r) => r.map((c) => inline(c.children))); case "pre": return [b.text]; case "quote": return b.children.flatMap(block); case "hr": return []; } } export function wikiPlain(text: string, opts: WikiOptions = {}): string { return parseWiki(text, { ...opts, anyAttachment: true }).flatMap(block).join(" "); }