Files
edentext/tests/unit/docx-highlight.test.ts
T
Steffen Becker 993e64e933 fix: keep the highlighter pen a docx run carries
Word's highlighter is w:highlight, a palette name; only w:shd's hex fill was
read, so 121 yellow runs of a fixture imported unmarked. 'none' maps to the
same 'auto' sentinel an empty w:shd gives, so it still cancels a style's pen.
2026-08-08 08:56:38 +00:00

23 lines
1.0 KiB
TypeScript

// Word's highlighter pen is w:highlight (a palette name), not the w:shd hex fill.
import { describe, it, expect } from 'vitest';
import { parseRunProps, mergeRunProps, W } from '../../src/lib/import/docxStyles';
const rPr = (inner: string) =>
new DOMParser().parseFromString(`<w:rPr xmlns:w="${W}">${inner}</w:rPr>`, 'application/xml').documentElement;
describe('parseRunProps highlight', () => {
it('resolves a palette name to its hex', () => {
expect(parseRunProps(rPr('<w:highlight w:val="yellow"/>')).highlightFill).toBe('FFFF00');
});
it("lets a run's w:highlight none cancel the character style's pen", () => {
const base = parseRunProps(rPr('<w:highlight w:val="green"/>'));
const merged = mergeRunProps(base, parseRunProps(rPr('<w:highlight w:val="none"/>')));
expect(merged.highlightFill).toBe('auto');
});
it('ignores an unknown name rather than inventing a colour', () => {
expect(parseRunProps(rPr('<w:highlight w:val="chartreuse"/>')).highlightFill).toBeUndefined();
});
});