In MS Word 2015 (and possibly others), leading and trailing spaces are ignored in text runs. This means that calling TextRun with leading/trailing space would result in a document that didn't include those spaces. The fix here (per http://officeopenxml.com/WPtext.php) is to include an extra attribute on the "w:t" element that forces word to recognize those spaces.
23 lines
804 B
TypeScript
23 lines
804 B
TypeScript
import { expect } from "chai";
|
|
import { Text } from "../../../../docx/run/run-components/text";
|
|
import { Formatter } from "../../../../export/formatter";
|
|
|
|
describe("Text", () => {
|
|
describe("#constructor", () => {
|
|
it("creates an empty text run if no text is given", () => {
|
|
const t = new Text("");
|
|
const f = new Formatter().format(t);
|
|
expect(f).to.deep.equal({"w:t": [{_attr: {"xml:space": "preserve"}}]});
|
|
});
|
|
|
|
it("adds the passed in text to the component", () => {
|
|
const t = new Text(" this is\n text");
|
|
const f = new Formatter().format(t);
|
|
expect(f).to.deep.equal({"w:t": [
|
|
{_attr: {"xml:space": "preserve"}},
|
|
" this is\n text",
|
|
]});
|
|
});
|
|
});
|
|
});
|