diff --git a/ts/docx/run/formatting.ts b/ts/docx/run/formatting.ts index d8f0257e03..7236c24f5e 100644 --- a/ts/docx/run/formatting.ts +++ b/ts/docx/run/formatting.ts @@ -1,5 +1,6 @@ import { Attributes, XmlComponent } from "../xml-components"; export { Underline } from "./underline"; +export { SubScript, SuperScript } from "./script"; export class Bold extends XmlComponent { diff --git a/ts/styles/style/index.ts b/ts/styles/style/index.ts index af37157bd9..5d9e221410 100644 --- a/ts/styles/style/index.ts +++ b/ts/styles/style/index.ts @@ -111,6 +111,16 @@ export class ParagraphStyle extends Style { return this; } + public subScript(): ParagraphStyle { + this.addRunProperty(new formatting.SubScript()); + return this; + } + + public superScript(): ParagraphStyle { + this.addRunProperty(new formatting.SuperScript()); + return this; + } + public underline(underlineType?: string, color?: string): ParagraphStyle { this.addRunProperty(new formatting.Underline(underlineType, color)); return this; diff --git a/ts/tests/stylesTest.ts b/ts/tests/stylesTest.ts index c7a87f6b40..b56cb687fd 100644 --- a/ts/tests/stylesTest.ts +++ b/ts/tests/stylesTest.ts @@ -290,6 +290,36 @@ describe("ParagraphStyle", () => { }); }); + it("#subScript", () => { + const style = new ParagraphStyle("myStyleId") + .subScript(); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, + {"w:pPr": []}, + {"w:rPr": [ + {"w:vertAlign": [{_attr: {"w:val": "subscript"}}]}, + ]}, + ], + }); + }); + + it("#superScript", () => { + const style = new ParagraphStyle("myStyleId") + .superScript(); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, + {"w:pPr": []}, + {"w:rPr": [ + {"w:vertAlign": [{_attr: {"w:val": "superscript"}}]}, + ]}, + ], + }); + }); + it("#bold", () => { const style = new ParagraphStyle("myStyleId") .bold();