mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-18 22:25:44 +01:00
Rank discoverability third among the goals, plan the move to GitHub and the outreach, and drop a text node's content in plain
This commit is contained in:
@@ -314,6 +314,7 @@ test('breaks a line at a newline and trims whitespace at every edge CommonMark s
|
||||
assert.equal(plain(node('heading', { level: 1 }, text(' h\ni '))), '# h i\n')
|
||||
assert.equal(plain(paragraph(text('a\r\u0000b'))), 'ab\n')
|
||||
assert.equal(plain(paragraph(text('x', link('/u', 't\r\u0000')))), '[x](/u "t")\n')
|
||||
assert.equal(plain(paragraph({ content: [text('dropped')], text: 'a', type: 'text' }, text('b'))), 'ab\n')
|
||||
})
|
||||
|
||||
test('keeps a code span opening a line, whose backticks open no fence', () => {
|
||||
|
||||
@@ -77,9 +77,9 @@ test('normalizes blocks and mark attributes nesting far past the levels a recurs
|
||||
assert.deepEqual(merged.content?.[0]?.content?.map((text) => text.text), ['ab'])
|
||||
})
|
||||
|
||||
test('joins a text node holding content to no neighbour, so its content is kept', () => {
|
||||
const holding: AdfNode = { content: [{ text: 'kept', type: 'text' }], text: 'a', type: 'text' }
|
||||
for (const content of [[holding, { text: 'b', type: 'text' }], [{ text: 'b', type: 'text' }, holding]]) {
|
||||
assert.deepEqual(toEditorNormal({ content: [{ content, type: 'paragraph' }], type: 'doc', version: 1 }).content, [{ content, type: 'paragraph' }])
|
||||
}
|
||||
test('drops the content a text node holds, and joins the node as any other', () => {
|
||||
const holding: AdfNode = { content: [{ text: 'dropped', type: 'text' }], text: 'a', type: 'text' }
|
||||
const normal = (content: AdfNode[]): AdfNode[] | undefined => toEditorNormal({ content: [{ content, type: 'paragraph' }], type: 'doc', version: 1 }).content
|
||||
assert.deepEqual(normal([holding, { text: 'b', type: 'text' }]), [{ content: [{ text: 'ab', type: 'text' }], type: 'paragraph' }])
|
||||
assert.deepEqual(normal([{ text: 'b', type: 'text' }, holding]), [{ content: [{ text: 'ba', type: 'text' }], type: 'paragraph' }])
|
||||
})
|
||||
|
||||
@@ -7,9 +7,9 @@ type JsonContainer = JsonValue[] | { [key: string]: JsonValue }
|
||||
|
||||
type NodeHolder = { content?: AdfNode[] }
|
||||
|
||||
// The editor's rule is the reader's over the pair's editor-normal forms; a text node holding content never joins, so its content is kept.
|
||||
// The editor's rule is the reader's over the pair's editor-normal forms.
|
||||
export function joinsWhenEditorNormal(previous: AdfNode, node: AdfNode): boolean {
|
||||
if (previous.type !== 'text' || node.type !== 'text' || nodeContent(previous).length > 0 || nodeContent(node).length > 0) return false
|
||||
if (previous.type !== 'text' || node.type !== 'text') return false
|
||||
return joinsWhenRead(normalNode(previous), normalNode(node))
|
||||
}
|
||||
|
||||
@@ -25,7 +25,8 @@ export function toEditorNormal(document: AdfDocument): AdfDocument {
|
||||
if (content.length === 0) continue
|
||||
entry.holder.content = content.map((source) => {
|
||||
const holder = normalNode(source)
|
||||
pending.push({ holder, source })
|
||||
// Atlassian's schema allows a text node no content, so the editor keeps none.
|
||||
if (source.type !== 'text') pending.push({ holder, source })
|
||||
return holder
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user