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' })))), 'xa
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: '' }