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.
16 lines
444 B
TypeScript
16 lines
444 B
TypeScript
import { XmlAttributeComponent, XmlComponent } from "../../xml-components";
|
|
|
|
class TextAttributes extends XmlAttributeComponent<{space: "default" | "preserve"}> {
|
|
protected xmlKeys = {space: "xml:space"};
|
|
}
|
|
|
|
export class Text extends XmlComponent {
|
|
constructor(text: string) {
|
|
super("w:t");
|
|
this.root.push(new TextAttributes({space: "preserve"}));
|
|
if (text) {
|
|
this.root.push(text);
|
|
}
|
|
}
|
|
}
|