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.
This commit is contained in:
1 parent
361b14dc17
commit
993e64e933
2 files changed
+33
-1
No files matched your search
@@ -0,0 +1,22 @@
|
||||
// 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();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user