mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-13 04:08:29 +01:00
Answer stability round 2: 1 🔴, 0 🟡 (0 misread); a block inside a carried code block shows as a paragraph again
This commit is contained in:
@@ -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' })))), '<pre><code>a\n bc</code></pre>')
|
||||
})
|
||||
|
||||
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' })))), '<pre><code>x</code></pre><p>a<br>b</p><pre><code>z</code></pre>')
|
||||
})
|
||||
|
||||
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'), '<pre><code class="language-js">x</code></pre>')
|
||||
|
||||
@@ -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: '' }
|
||||
|
||||
Reference in New Issue
Block a user