This commit is contained in:
@@ -160,6 +160,7 @@ test('refuses a carried node nested deeper than the emitter carries', () => {
|
|||||||
|
|
||||||
test('refuses a node whose content model the canonical form cannot emit', () => {
|
test('refuses a node whose content model the canonical form cannot emit', () => {
|
||||||
assert.equal(code(adfToMarkdown(document({ content: [paragraph()], type: 'codeBlock' }))), 'unsupported-node-shape')
|
assert.equal(code(adfToMarkdown(document({ content: [paragraph()], type: 'codeBlock' }))), 'unsupported-node-shape')
|
||||||
|
assert.equal(code(adfToMarkdown(document({ content: [{ content: [{ text: 'lost', type: 'text' }], text: 'x', type: 'text' }], type: 'codeBlock' }))), 'unsupported-node-shape')
|
||||||
assert.equal(code(adfToMarkdown(document({ content: [paragraph()], type: 'bulletList' }))), 'unsupported-node-shape')
|
assert.equal(code(adfToMarkdown(document({ content: [paragraph()], type: 'bulletList' }))), 'unsupported-node-shape')
|
||||||
assert.equal(code(adfToMarkdown(document({ type: 'bulletList' }))), 'unsupported-node-shape')
|
assert.equal(code(adfToMarkdown(document({ type: 'bulletList' }))), 'unsupported-node-shape')
|
||||||
assert.equal(code(adfToMarkdown(document({ attrs: { order: 2 }, content: [], type: 'orderedList' }))), 'unsupported-node-shape')
|
assert.equal(code(adfToMarkdown(document({ attrs: { order: 2 }, content: [], type: 'orderedList' }))), 'unsupported-node-shape')
|
||||||
|
|||||||
@@ -163,7 +163,14 @@ function emitCodeBlock(node: AdfNode, path: ConvertErrorPath): Result<string> {
|
|||||||
let text = ''
|
let text = ''
|
||||||
for (const [index, child] of (node.content ?? []).entries()) {
|
for (const [index, child] of (node.content ?? []).entries()) {
|
||||||
const childPath = [...path, 'content', index]
|
const childPath = [...path, 'content', index]
|
||||||
if (child.type !== 'text' || typeof child.text !== 'string' || child.text === '' || (child.marks ?? []).length > 0 || Object.keys(child.attrs ?? {}).length > 0) {
|
if (
|
||||||
|
child.type !== 'text' ||
|
||||||
|
typeof child.text !== 'string' ||
|
||||||
|
child.text === '' ||
|
||||||
|
(child.content ?? []).length > 0 ||
|
||||||
|
(child.marks ?? []).length > 0 ||
|
||||||
|
Object.keys(child.attrs ?? {}).length > 0
|
||||||
|
) {
|
||||||
return failure('unsupported-node-shape', 'a codeBlock holds plain text nodes only', childPath)
|
return failure('unsupported-node-shape', 'a codeBlock holds plain text nodes only', childPath)
|
||||||
}
|
}
|
||||||
if (/\r/.test(child.text)) return failure('unspellable-whitespace', 'a codeBlock holds no carriage return CommonMark keeps', childPath)
|
if (/\r/.test(child.text)) return failure('unspellable-whitespace', 'a codeBlock holds no carriage return CommonMark keeps', childPath)
|
||||||
|
|||||||
Reference in New Issue
Block a user