Merge pull request #1822 from dolanmiu/feat/underline-none
#1807 Add underline none
This commit is contained in:
@ -222,6 +222,15 @@ const doc = new Document({
|
|||||||
new TextRun({
|
new TextRun({
|
||||||
text: "Underline and Strike",
|
text: "Underline and Strike",
|
||||||
}),
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: " Override Underline ",
|
||||||
|
underline: {
|
||||||
|
type: UnderlineType.NONE,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "Strike and Underline",
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Formatter } from "@export/formatter";
|
import { Formatter } from "@export/formatter";
|
||||||
|
import { SpaceType } from "@file/shared";
|
||||||
|
|
||||||
import { Text } from "./text";
|
import { Text } from "./text";
|
||||||
|
|
||||||
@ -13,5 +14,26 @@ describe("Text", () => {
|
|||||||
"w:t": [{ _attr: { "xml:space": "preserve" } }, " this is\n text"],
|
"w:t": [{ _attr: { "xml:space": "preserve" } }, " this is\n text"],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("adds the passed in text to the component with options", () => {
|
||||||
|
const t = new Text({
|
||||||
|
text: " this is\n text",
|
||||||
|
space: SpaceType.PRESERVE,
|
||||||
|
});
|
||||||
|
const f = new Formatter().format(t);
|
||||||
|
expect(f).to.deep.equal({
|
||||||
|
"w:t": [{ _attr: { "xml:space": "preserve" } }, " this is\n text"],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("adds the passed in text to the component with options and sets default space type", () => {
|
||||||
|
const t = new Text({
|
||||||
|
text: " this is\n text",
|
||||||
|
});
|
||||||
|
const f = new Formatter().format(t);
|
||||||
|
expect(f).to.deep.equal({
|
||||||
|
"w:t": [{ _attr: { "xml:space": "default" } }, " this is\n text"],
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -3,11 +3,31 @@ import { XmlComponent } from "@file/xml-components";
|
|||||||
|
|
||||||
import { TextAttributes } from "../text-attributes";
|
import { TextAttributes } from "../text-attributes";
|
||||||
|
|
||||||
export class Text extends XmlComponent {
|
// <xsd:complexType name="CT_Text">
|
||||||
public constructor(text: string) {
|
// <xsd:simpleContent>
|
||||||
super("w:t");
|
// <xsd:extension base="s:ST_String">
|
||||||
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
|
// <xsd:attribute ref="xml:space" use="optional" />
|
||||||
|
// </xsd:extension>
|
||||||
|
// </xsd:simpleContent>
|
||||||
|
// </xsd:complexType>
|
||||||
|
|
||||||
this.root.push(text);
|
interface ITextOptions {
|
||||||
|
readonly space?: SpaceType;
|
||||||
|
readonly text?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Text extends XmlComponent {
|
||||||
|
public constructor(options: string | ITextOptions) {
|
||||||
|
super("w:t");
|
||||||
|
|
||||||
|
if (typeof options === "string") {
|
||||||
|
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
|
||||||
|
this.root.push(options);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
this.root.push(new TextAttributes({ space: options.space ?? SpaceType.DEFAULT }));
|
||||||
|
this.root.push(options.text);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ export enum UnderlineType {
|
|||||||
WAVE = "wave",
|
WAVE = "wave",
|
||||||
WAVYHEAVY = "wavyHeavy",
|
WAVYHEAVY = "wavyHeavy",
|
||||||
WAVYDOUBLE = "wavyDouble",
|
WAVYDOUBLE = "wavyDouble",
|
||||||
|
NONE = "none",
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Underline extends XmlComponent {
|
export class Underline extends XmlComponent {
|
||||||
|
Reference in New Issue
Block a user