diff --git a/corpus/round-trip/combinations/carry-text-attributes.json b/corpus/round-trip/combinations/carry-text-attributes.json index fbc01a1..8e23c5f 100644 --- a/corpus/round-trip/combinations/carry-text-attributes.json +++ b/corpus/round-trip/combinations/carry-text-attributes.json @@ -50,25 +50,6 @@ } ], "type": "paragraph" - }, - { - "content": [ - { - "attrs": { - "localId": "01a0a067-68cf-78af-abd6-c660ec0d189b" - }, - "text": "Two ", - "type": "text" - }, - { - "attrs": { - "localId": "01a0a067-68d9-73fa-9b9a-caa42061993c" - }, - "text": "anchors", - "type": "text" - } - ], - "type": "paragraph" } ], "type": "doc", diff --git a/corpus/round-trip/combinations/carry-text-attributes.md b/corpus/round-trip/combinations/carry-text-attributes.md index 83c35d2..dad9c07 100644 --- a/corpus/round-trip/combinations/carry-text-attributes.md +++ b/corpus/round-trip/combinations/carry-text-attributes.md @@ -3,5 +3,3 @@ Signed by :adf{json="{\"attrs\":{\"localId\":\"01a0a067-68d2-787e-afc5-2459776aa029\"},\"text\":\"the owner\",\"type\":\"text\"}"} :adf{json="{\"attrs\":{\"localId\":\"01a0a067-68d5-7372-9962-29a039654056\"},\"text\":\"One \",\"type\":\"text\"}"}:adf{json="{\"attrs\":{\"localId\":\"01a0a067-68d5-7372-9962-29a039654056\"},\"text\":\"anchor\",\"type\":\"text\"}"} - -:adf{json="{\"attrs\":{\"localId\":\"01a0a067-68cf-78af-abd6-c660ec0d189b\"},\"text\":\"Two \",\"type\":\"text\"}"}:adf{json="{\"attrs\":{\"localId\":\"01a0a067-68d9-73fa-9b9a-caa42061993c\"},\"text\":\"anchors\",\"type\":\"text\"}"} diff --git a/src/adf/document.ts b/src/adf/document.ts index dfd6b21..bedca8c 100644 --- a/src/adf/document.ts +++ b/src/adf/document.ts @@ -72,7 +72,7 @@ export function isAdfMark(value: unknown): value is AdfMark { return !('attrs' in value) || isAttributes(value['attrs']) } -export function nodeAttrs(node: { attrs?: AdfAttributes }): AdfAttributes { +export function nodeAttrs(node: { attrs?: AdfAttributes }): Readonly { return node.attrs ?? {} } diff --git a/src/adf/editor-normal.test.ts b/src/adf/editor-normal.test.ts index eaefc83..f640a48 100644 --- a/src/adf/editor-normal.test.ts +++ b/src/adf/editor-normal.test.ts @@ -14,6 +14,7 @@ test('merges adjacent text nodes carrying identical marks, at every level', () = { text: 'e', type: 'text' }, { attrs: { localId: '01a0a06b-5281-7f27-9022-8d3a74b0ab0d' }, text: 'f', type: 'text' }, { text: 'g', type: 'text' }, + { attrs: {}, text: 'h', type: 'text' }, ] assert.deepEqual(toEditorNormal({ content: [{ attrs: { panelType: 'info' }, content: [{ content, type: 'paragraph' }], type: 'panel' }], type: 'doc', version: 1 }), { content: [ @@ -27,7 +28,7 @@ test('merges adjacent text nodes carrying identical marks, at every level', () = { type: 'hardBreak' }, { text: 'e', type: 'text' }, { attrs: { localId: '01a0a06b-5281-7f27-9022-8d3a74b0ab0d' }, text: 'f', type: 'text' }, - { text: 'g', type: 'text' }, + { text: 'gh', type: 'text' }, ], type: 'paragraph', }, diff --git a/src/adf/editor-normal.ts b/src/adf/editor-normal.ts index b6514f1..fe74067 100644 --- a/src/adf/editor-normal.ts +++ b/src/adf/editor-normal.ts @@ -11,7 +11,6 @@ export function sameMark(candidate: AdfMark, mark: AdfMark): boolean { return markKey(candidate) === markKey(mark) } -// AGENTS.md ยง2: adjacent text nodes carrying identical marks and no attributes are one node. export function mergeAdjacentText(nodes: readonly AdfNode[]): AdfNode[] { const merged: AdfNode[] = [] for (const node of nodes) { diff --git a/src/corpus.test.ts b/src/corpus.test.ts index ae36632..31a7f1d 100644 --- a/src/corpus.test.ts +++ b/src/corpus.test.ts @@ -96,7 +96,7 @@ for (const directory of roundTripDirectories) { assert.ok(isAdfDocument(expected), `${name}.json is not an ADF document`) const result = markdownToAdf(readFileSync(join(roundTripRoot, directory, `${name}.md`), 'utf8')) assert.ok(result.ok, result.ok ? '' : `${result.error.code}: ${result.error.message}`) - assert.deepEqual(toEditorNormal(result.value), toEditorNormal(expected)) + assert.deepEqual(toEditorNormal(result.value), expected) }) } } @@ -185,12 +185,12 @@ for (const name of pairedNames(normalizationRoot, '.md', '.json')) { assert.ok(isAdfDocument(expected), `${name}.json is not an ADF document`) const result = markdownToAdf(readFileSync(join(normalizationRoot, `${name}.md`), 'utf8')) assert.ok(result.ok, result.ok ? '' : `${result.error.code}: ${result.error.message}`) - assert.deepEqual(toEditorNormal(result.value), toEditorNormal(expected)) + assert.deepEqual(toEditorNormal(result.value), expected) const emitted = adfToMarkdown(result.value) assert.ok(emitted.ok, emitted.ok ? '' : `${emitted.error.code}: ${emitted.error.message}`) const again = markdownToAdf(emitted.value) assert.ok(again.ok, again.ok ? '' : `${again.error.code}: ${again.error.message}`) - assert.deepEqual(toEditorNormal(again.value), toEditorNormal(expected)) + assert.deepEqual(toEditorNormal(again.value), expected) }) } diff --git a/src/markdown/emit/adf-to-markdown.test.ts b/src/markdown/emit/adf-to-markdown.test.ts index 4f53351..5995088 100644 --- a/src/markdown/emit/adf-to-markdown.test.ts +++ b/src/markdown/emit/adf-to-markdown.test.ts @@ -356,7 +356,7 @@ test('refuses marks and attributes nested deeper than the emitter carries', () = assert.ok(spelled.ok, spelled.ok ? '' : spelled.error.message) const read = markdownToAdf(spelled.value) assert.ok(read.ok, read.ok ? '' : read.error.message) - assert.deepEqual(toEditorNormal(read.value), toEditorNormal(document(node))) + assert.deepEqual(toEditorNormal(read.value), document(node)) } assert.equal(markdown(adfToMarkdown(document(paragraph({ marks: [{ attrs, type: 'em' }], text: 'x', type: 'text' })))), deeper('depth', 'em', largestNesting - 3))