Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Comment thread
harbournick marked this conversation as resolved.
result.name = translator.xmlName;
}
elements.push(result);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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: {},
},
]);
});
});
Loading