Andrey Epifancev fbc14f6366 fix(web): вложения в ленте именем (I-1), один шаг при двойном «Назад» (M-1), разбор таблиц и {code} (T1.1, T1.2)
wikiPlain включает WikiOptions.anyAttachment: !имя! и [^имя] дают вложение без списка; карточка флаг не передаёт.
onBack защищён closingKey; в таблице [ парна, только если ближайшая скобка — ]; {code} из пробелов в одной строке не даёт pre.
Тесты: events, plain, parse, IssueModal (двойной «Назад», «Назад» при ошибке загрузки — T3.2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 01:32:16 +04:00

36 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Текст вики-разметки 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(" ");
}