diff --git a/packages/super-editor/src/core/super-converter/v3/handlers/utils.js b/packages/super-editor/src/core/super-converter/v3/handlers/utils.js index fa6ebe0205..9809ee2c27 100644 --- a/packages/super-editor/src/core/super-converter/v3/handlers/utils.js +++ b/packages/super-editor/src/core/super-converter/v3/handlers/utils.js @@ -317,7 +317,9 @@ export function decodeProperties(params, translatorsBySdName, properties) { if (translator) { const result = translator.decode({ ...params, node: { attrs: { [key]: properties[key] } } }); if (result != null) { - result.name = translator.xmlName; + if (result.name == null) { + result.name = translator.xmlName; + } elements.push(result); } } diff --git a/packages/super-editor/src/core/super-converter/v3/handlers/utils.test.js b/packages/super-editor/src/core/super-converter/v3/handlers/utils.test.js new file mode 100644 index 0000000000..abfc1ead3e --- /dev/null +++ b/packages/super-editor/src/core/super-converter/v3/handlers/utils.test.js @@ -0,0 +1,51 @@ +import { describe, expect, it } from 'vitest'; +import { decodeProperties } from './utils.js'; + +describe('decodeProperties', () => { + it('preserves explicit node name returned by translator.decode', () => { + const translator = { + xmlName: 'w:highlight', + sdNodeOrKeyName: 'highlight', + decode: () => ({ + name: 'w:shd', + attributes: { + 'w:color': 'auto', + 'w:val': 'clear', + 'w:fill': 'E4668C', + }, + }), + }; + + const elements = decodeProperties({ node: { attrs: {} } }, { highlight: translator }, { highlight: '#E4668C' }); + + expect(elements).toEqual([ + { + name: 'w:shd', + attributes: { + 'w:color': 'auto', + 'w:val': 'clear', + 'w:fill': 'E4668C', + }, + }, + ]); + }); + + it('falls back to translator xmlName when decode result has no name', () => { + const translator = { + xmlName: 'w:b', + sdNodeOrKeyName: 'bold', + decode: () => ({ + attributes: {}, + }), + }; + + const elements = decodeProperties({ node: { attrs: {} } }, { bold: translator }, { bold: true }); + + expect(elements).toEqual([ + { + name: 'w:b', + attributes: {}, + }, + ]); + }); +});