From 94efd30c598911c914415e5aa6ebbd9711dae5f8 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 01:38:00 +0200 Subject: [PATCH] =?UTF-8?q?Answer=20stability=20round=202:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20a=20block?= =?UTF-8?q?=20inside=20a=20carried=20code=20block=20shows=20as=20a=20parag?= =?UTF-8?q?raph=20again?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/html/emit/adf-to-html.test.ts | 4 ++++ src/html/emit/carry-element.ts | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/html/emit/adf-to-html.test.ts b/src/html/emit/adf-to-html.test.ts index 7601790..035a836 100644 --- a/src/html/emit/adf-to-html.test.ts +++ b/src/html/emit/adf-to-html.test.ts @@ -180,6 +180,10 @@ test('shows a code block in a div carry as pre and code, keeping its line feeds assert.equal(shown(html(adfToHtml(document({ content: [text('a\r\n b'), text('c')], type: 'codeBlock' })))), '
a\n  bc
') }) +test('shows a block inside a code block in a div carry as a paragraph, and the text after it as code', () => { + assert.equal(shown(html(adfToHtml(document({ content: [text('x'), paragraph(text('a\nb')), text('z')], type: 'codeBlock' })))), '
x

a
b

z
') +}) + test('gives a code block in a div carry the class its element takes, and none where its language is no class token', () => { const carried = (language: AdfAttributes[string]): string => shown(html(adfToHtml(document({ attrs: { language }, content: [text('x')], marks: [{ attrs: { mode: 'wide' }, type: 'breakout' }], type: 'codeBlock' })))) assert.equal(carried('js'), '
x
') diff --git a/src/html/emit/carry-element.ts b/src/html/emit/carry-element.ts index d67a906..4e0bfd5 100644 --- a/src/html/emit/carry-element.ts +++ b/src/html/emit/carry-element.ts @@ -30,11 +30,11 @@ export function carryElement(tag: string, json: string, content: string): string function shownBlocks(root: AdfNode, codeLineFeed: string): ShownBlock[] { const shown: ShownBlock[] = [] let current: ShownBlock = { code: undefined, html: '' } - // Each entry holds the code block it stands in; a `null` node ends a block, after which the content stands in `code` again. + // Each entry holds the code block it stands in, none where another block stands between them; a `null` node ends a block, after which the content stands in `code` again. const pending: { code: AdfNode | undefined; node: AdfNode | null }[] = [{ code: undefined, node: root }] for (let next = pending.pop(); next !== undefined; next = pending.pop()) { const { node } = next - const code = node?.type === 'codeBlock' ? node : next.code + const code = node?.type === 'codeBlock' ? node : node !== null && partsShownText(node.type) ? undefined : next.code if (node === null || partsShownText(node.type)) { if (current.html !== '') shown.push(current) current = { code, html: '' }