Fix replacer error on patches with empty Runs (#2875)
* Add test to demonstrate empty strings not creating runs * Fix Run not creating Text child for empty strings * Simplify TextRun constructor Since `Run` already has a option for instantiating a `Text` element, we don't need to push children here. * Add replacer test for empty runs * Add replacer test for empty runs * replacer: handle patches with empty runs * Fix incorrect test name
This commit is contained in:
@ -155,7 +155,7 @@ export class Run extends XmlComponent {
|
||||
|
||||
this.root.push(child);
|
||||
}
|
||||
} else if (options.text) {
|
||||
} else if (options.text !== undefined) {
|
||||
this.root.push(new Text(options.text));
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,14 @@ describe("TextRun", () => {
|
||||
"w:r": [{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "test"] }],
|
||||
});
|
||||
});
|
||||
|
||||
it("should add empty text into run", () => {
|
||||
run = new TextRun({ text: "" });
|
||||
const f = new Formatter().format(run);
|
||||
expect(f).to.deep.equal({
|
||||
"w:r": [{ "w:t": [{ _attr: { "xml:space": "preserve" } }, ""] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#referenceFootnote()", () => {
|
||||
|
@ -1,14 +1,7 @@
|
||||
import { IRunOptions, Run } from "./run";
|
||||
import { Text } from "./run-components/text";
|
||||
|
||||
export class TextRun extends Run {
|
||||
public constructor(options: IRunOptions | string) {
|
||||
if (typeof options === "string") {
|
||||
super({});
|
||||
this.root.push(new Text(options));
|
||||
return this;
|
||||
}
|
||||
|
||||
super(options);
|
||||
super(typeof options === "string" ? { text: options } : options);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user