Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
b210608e56 | |||
74353104dc | |||
825136d1c9 | |||
b2fea471f1 | |||
e9adb8b0ed | |||
5d6bc039d0 | |||
27638063c8 | |||
f6a4d78ab7 | |||
4061e31400 | |||
74db67689f | |||
2213eb28cb | |||
d1b45d416b | |||
f72f7e7514 | |||
0165cfb3e5 | |||
ef747486c0 | |||
e0b2f59c2f |
104
.github/workflows/default.yml
vendored
Normal file
104
.github/workflows/default.yml
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
name: Default
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@master
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
- name: Build
|
||||
run: npm run build
|
||||
- name: Archive Production Artifact
|
||||
uses: actions/upload-artifact@master
|
||||
with:
|
||||
name: build
|
||||
path: build
|
||||
test:
|
||||
name: Test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@master
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
- name: Test
|
||||
run: npm run test.coverage
|
||||
lint:
|
||||
name: Lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@master
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
- name: Lint
|
||||
run: npm run lint
|
||||
prettier:
|
||||
name: Prettier
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@master
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
- name: Prettier
|
||||
run: npm run style
|
||||
demos:
|
||||
name: Run Demos
|
||||
needs: [build]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@master
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
- name: Download Artifact
|
||||
uses: actions/download-artifact@master
|
||||
with:
|
||||
name: build
|
||||
path: build
|
||||
- name: Run demos
|
||||
run: |
|
||||
npm run ts-node -- ./demo/1-basic.ts
|
||||
npm run ts-node -- ./demo/2-declaritive-styles.ts
|
||||
npm run ts-node -- ./demo/3-numbering-and-bullet-points.ts
|
||||
npm run ts-node -- ./demo/4-basic-table.ts
|
||||
npm run ts-node -- ./demo/5-images.ts
|
||||
npm run ts-node -- ./demo/6-page-borders.ts
|
||||
npm run ts-node -- ./demo/7-landscape.ts
|
||||
npm run ts-node -- ./demo/8-header-footer.ts
|
||||
npm run ts-node -- ./demo/9-images-in-header-and-footer.ts
|
||||
npm run ts-node -- ./demo/10-my-cv.ts
|
||||
npm run ts-node -- ./demo/11-declaritive-styles-2.ts
|
||||
npm run ts-node -- ./demo/12-scaling-images.ts
|
||||
npm run ts-node -- ./demo/13-xml-styles.ts
|
||||
npm run ts-node -- ./demo/14-page-numbers.ts
|
||||
npm run ts-node -- ./demo/15-page-break-before.ts
|
||||
npm run ts-node -- ./demo/16-multiple-sections.ts
|
||||
npm run ts-node -- ./demo/17-footnotes.ts
|
||||
npm run ts-node -- ./demo/18-image-from-buffer.ts
|
||||
npm run ts-node -- ./demo/19-export-to-base64.ts
|
||||
npm run ts-node -- ./demo/20-table-cell-borders.ts
|
||||
npm run ts-node -- ./demo/21-bookmarks.ts
|
||||
npm run ts-node -- ./demo/22-right-to-left-text.ts
|
||||
npm run ts-node -- ./demo/23-base64-images.ts
|
||||
npm run ts-node -- ./demo/24-images-to-table-cell.ts
|
||||
npm run ts-node -- ./demo/26-paragraph-borders.ts
|
||||
npm run ts-node -- ./demo/27-declaritive-styles-3.ts
|
||||
npm run ts-node -- ./demo/28-table-of-contents.ts
|
||||
npm run ts-node -- ./demo/29-numbered-lists.ts
|
||||
npm run ts-node -- ./demo/30-template-document.ts
|
||||
npm run ts-node -- ./demo/31-tables.ts
|
||||
npm run ts-node -- ./demo/32-merge-and-shade-table-cells.ts
|
||||
npm run ts-node -- ./demo/33-sequential-captions.ts
|
||||
npm run ts-node -- ./demo/34-floating-tables.ts
|
@ -11,6 +11,7 @@
|
||||
[![NPM version][npm-image]][npm-url]
|
||||
[![Downloads per month][downloads-image]][downloads-url]
|
||||
[![Build Status][travis-image]][travis-url]
|
||||
[![GitHub Action Workflow Status][github-actions-workflow-image]][github-actions-workflow-url]
|
||||
[![Dependency Status][daviddm-image]][daviddm-url]
|
||||
[![Known Vulnerabilities][snky-image]][snky-url]
|
||||
[![Chat on Gitter][gitter-image]][gitter-url]
|
||||
@ -85,6 +86,7 @@ Read the contribution guidelines [here](https://docx.js.org/#/contribution-guide
|
||||
[<img src="https://i.imgur.com/QEZXU5b.png" alt="drawing" height="50"/>](https://www.beekast.com/)
|
||||
[<img src="https://imgur.com/XVU6aoi.png" alt="drawing" height="50"/>](https://herraizsoto.com/)
|
||||
[<img src="https://i.imgur.com/fn1xccG.png" alt="drawing" height="50"/>](http://www.ativer.com.br/)
|
||||
[<img src="https://i.imgur.com/cmykN7c.png" alt="drawing"/>](https://www.arity.co/)
|
||||
|
||||
|
||||
...and many more!
|
||||
@ -102,6 +104,8 @@ Made with 💖
|
||||
[downloads-url]: https://npmjs.org/package/docx
|
||||
[travis-image]: https://travis-ci.org/dolanmiu/docx.svg?branch=master
|
||||
[travis-url]: https://travis-ci.org/dolanmiu/docx
|
||||
[github-actions-workflow-image]: https://github.com/dolanmiu/docx/workflows/Default/badge.svg
|
||||
[github-actions-workflow-url]: https://github.com/dolanmiu/docx/actions
|
||||
[daviddm-image]: https://david-dm.org/dolanmiu/docx.svg?theme=shields.io
|
||||
[daviddm-url]: https://david-dm.org/dolanmiu/docx
|
||||
[snky-image]: https://snyk.io/test/github/dolanmiu/docx/badge.svg
|
||||
|
14
package-lock.json
generated
14
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "docx",
|
||||
"version": "5.3.0",
|
||||
"version": "5.4.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -576,9 +576,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"@types/mocha": {
|
||||
"version": "8.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-8.0.3.tgz",
|
||||
"integrity": "sha512-vyxR57nv8NfcU0GZu8EUXZLTbCMupIUwy95LJ6lllN+JRPG25CwMHoB1q5xKh8YKhQnHYRAn4yW2yuHbf/5xgg==",
|
||||
"version": "8.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-8.0.4.tgz",
|
||||
"integrity": "sha512-M4BwiTJjHmLq6kjON7ZoI2JMlBvpY3BYSdiP6s/qCT3jb1s9/DeJF0JELpAxiVSIxXDzfNKe+r7yedMIoLbknQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/node": {
|
||||
@ -670,9 +670,9 @@
|
||||
}
|
||||
},
|
||||
"@types/webpack": {
|
||||
"version": "4.41.24",
|
||||
"resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-4.41.24.tgz",
|
||||
"integrity": "sha512-1A0MXPwZiMOD3DPMuOKUKcpkdPo8Lq33UGggZ7xio6wJ/jV1dAu5cXDrOfGDnldUroPIRLsr/DT43/GqOA4RFQ==",
|
||||
"version": "4.41.25",
|
||||
"resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-4.41.25.tgz",
|
||||
"integrity": "sha512-cr6kZ+4m9lp86ytQc1jPOJXgINQyz3kLLunZ57jznW+WIAL0JqZbGubQk4GlD42MuQL5JGOABrxdpqqWeovlVQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/anymatch": "*",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "docx",
|
||||
"version": "5.4.0",
|
||||
"version": "5.4.1",
|
||||
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
||||
"main": "build/index.js",
|
||||
"scripts": {
|
||||
|
@ -19,3 +19,9 @@ export type MathComponent =
|
||||
| MathCurlyBrackets
|
||||
| MathAngledBrackets
|
||||
| MathSquareBrackets;
|
||||
|
||||
// Needed because of: https://github.com/s-panferov/awesome-typescript-loader/issues/432
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export const WORKAROUND4 = "";
|
||||
|
@ -6,12 +6,12 @@ import { UnderlineType } from "file/paragraph/run/underline";
|
||||
import { ShadingType } from "file/table";
|
||||
import { EMPTY_OBJECT } from "file/xml-components";
|
||||
|
||||
import { CharacterStyle } from "./character-style";
|
||||
import { StyleForCharacter } from "./character-style";
|
||||
|
||||
describe("CharacterStyle", () => {
|
||||
describe("#constructor", () => {
|
||||
it("should set the style type to character and use the given style id", () => {
|
||||
const style = new CharacterStyle({ id: "myStyleId" });
|
||||
const style = new StyleForCharacter({ id: "myStyleId" });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -31,7 +31,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the name of the style, if given", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
name: "Style Name",
|
||||
});
|
||||
@ -55,7 +55,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should add smallCaps", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
smallCaps: true,
|
||||
@ -83,7 +83,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should add allCaps", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
allCaps: true,
|
||||
@ -111,7 +111,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should add strike", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
strike: true,
|
||||
@ -139,7 +139,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should add double strike", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
doubleStrike: true,
|
||||
@ -167,7 +167,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should add sub script", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
subScript: true,
|
||||
@ -203,7 +203,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should add font by name", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
font: "test font",
|
||||
@ -242,7 +242,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should add font for ascii and eastAsia", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
font: {
|
||||
@ -282,7 +282,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should add character spacing", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
characterSpacing: 100,
|
||||
@ -312,7 +312,7 @@ describe("CharacterStyle", () => {
|
||||
|
||||
describe("formatting methods: style attributes", () => {
|
||||
it("#basedOn", () => {
|
||||
const style = new CharacterStyle({ id: "myStyleId", basedOn: "otherId" });
|
||||
const style = new StyleForCharacter({ id: "myStyleId", basedOn: "otherId" });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -357,7 +357,7 @@ describe("CharacterStyle", () => {
|
||||
];
|
||||
sizeTests.forEach(({ size, sizeComplexScript, expected }) => {
|
||||
it(`#size ${size} cs ${sizeComplexScript}`, () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: { size, sizeComplexScript },
|
||||
});
|
||||
@ -385,7 +385,7 @@ describe("CharacterStyle", () => {
|
||||
|
||||
describe("#underline", () => {
|
||||
it("should set underline to 'single' if no arguments are given", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
underline: {},
|
||||
@ -413,7 +413,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the style if given", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
underline: {
|
||||
@ -443,7 +443,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the style and color if given", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
underline: {
|
||||
@ -476,7 +476,7 @@ describe("CharacterStyle", () => {
|
||||
|
||||
describe("#emphasisMark", () => {
|
||||
it("should set emphasisMark to 'dot' if no arguments are given", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
emphasisMark: {},
|
||||
@ -504,7 +504,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the style if given", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
emphasisMark: {
|
||||
@ -535,7 +535,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("#superScript", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
superScript: true,
|
||||
@ -571,7 +571,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("#color", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
color: "123456",
|
||||
@ -616,7 +616,7 @@ describe("CharacterStyle", () => {
|
||||
];
|
||||
boldTests.forEach(({ bold, boldComplexScript, expected }) => {
|
||||
it(`#bold ${bold} cs ${boldComplexScript}`, () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: { bold, boldComplexScript },
|
||||
});
|
||||
@ -660,7 +660,7 @@ describe("CharacterStyle", () => {
|
||||
];
|
||||
italicsTests.forEach(({ italics, italicsComplexScript, expected }) => {
|
||||
it(`#italics ${italics} cs ${italicsComplexScript}`, () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: { italics, italicsComplexScript },
|
||||
});
|
||||
@ -687,7 +687,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("#link", () => {
|
||||
const style = new CharacterStyle({ id: "myStyleId", link: "MyLink" });
|
||||
const style = new StyleForCharacter({ id: "myStyleId", link: "MyLink" });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -708,7 +708,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("#semiHidden", () => {
|
||||
const style = new CharacterStyle({ id: "myStyleId", semiHidden: true });
|
||||
const style = new StyleForCharacter({ id: "myStyleId", semiHidden: true });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -749,7 +749,7 @@ describe("CharacterStyle", () => {
|
||||
];
|
||||
highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => {
|
||||
it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: { highlight, highlightComplexScript },
|
||||
});
|
||||
@ -838,7 +838,7 @@ describe("CharacterStyle", () => {
|
||||
];
|
||||
shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => {
|
||||
it("#shadow correctly", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: { shadow, shading, shadingComplexScript },
|
||||
});
|
||||
|
@ -15,7 +15,7 @@ export interface ICharacterStyleOptions extends IBaseCharacterStyleOptions {
|
||||
readonly name?: string;
|
||||
}
|
||||
|
||||
export class CharacterStyle extends Style {
|
||||
export class StyleForCharacter extends Style {
|
||||
private readonly runProperties: RunProperties;
|
||||
|
||||
constructor(options: ICharacterStyleOptions) {
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { UnderlineType } from "file/paragraph/run/underline";
|
||||
|
||||
import { CharacterStyle, IBaseCharacterStyleOptions } from "./character-style";
|
||||
import { IBaseParagraphStyleOptions, IParagraphStyleOptions, ParagraphStyle } from "./paragraph-style";
|
||||
import { IBaseCharacterStyleOptions, StyleForCharacter } from "./character-style";
|
||||
import { IBaseParagraphStyleOptions, IParagraphStyleOptions, StyleForParagraph } from "./paragraph-style";
|
||||
|
||||
export class HeadingStyle extends ParagraphStyle {
|
||||
export class HeadingStyle extends StyleForParagraph {
|
||||
constructor(options: IParagraphStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
@ -84,7 +84,7 @@ export class Heading6Style extends HeadingStyle {
|
||||
}
|
||||
}
|
||||
|
||||
export class ListParagraph extends ParagraphStyle {
|
||||
export class ListParagraph extends StyleForParagraph {
|
||||
constructor(options: IBaseParagraphStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
@ -96,7 +96,7 @@ export class ListParagraph extends ParagraphStyle {
|
||||
}
|
||||
}
|
||||
|
||||
export class FootnoteText extends ParagraphStyle {
|
||||
export class FootnoteText extends StyleForParagraph {
|
||||
constructor(options: IBaseParagraphStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
@ -121,7 +121,7 @@ export class FootnoteText extends ParagraphStyle {
|
||||
}
|
||||
}
|
||||
|
||||
export class FootnoteReferenceStyle extends CharacterStyle {
|
||||
export class FootnoteReferenceStyle extends StyleForCharacter {
|
||||
constructor(options: IBaseCharacterStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
@ -136,7 +136,7 @@ export class FootnoteReferenceStyle extends CharacterStyle {
|
||||
}
|
||||
}
|
||||
|
||||
export class FootnoteTextChar extends CharacterStyle {
|
||||
export class FootnoteTextChar extends StyleForCharacter {
|
||||
constructor(options: IBaseCharacterStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
@ -152,7 +152,7 @@ export class FootnoteTextChar extends CharacterStyle {
|
||||
}
|
||||
}
|
||||
|
||||
export class HyperlinkStyle extends CharacterStyle {
|
||||
export class HyperlinkStyle extends StyleForCharacter {
|
||||
constructor(options: IBaseCharacterStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
|
@ -6,12 +6,12 @@ import { UnderlineType } from "file/paragraph/run/underline";
|
||||
import { ShadingType } from "file/table";
|
||||
import { EMPTY_OBJECT } from "file/xml-components";
|
||||
|
||||
import { ParagraphStyle } from "./paragraph-style";
|
||||
import { StyleForParagraph } from "./paragraph-style";
|
||||
|
||||
describe("ParagraphStyle", () => {
|
||||
describe("#constructor", () => {
|
||||
it("should set the style type to paragraph and use the given style id", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId" });
|
||||
const style = new StyleForParagraph({ id: "myStyleId" });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||
@ -19,7 +19,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the name of the style, if given", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
name: "Style Name",
|
||||
});
|
||||
@ -35,7 +35,7 @@ describe("ParagraphStyle", () => {
|
||||
|
||||
describe("formatting methods: style attributes", () => {
|
||||
it("#basedOn", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId", basedOn: "otherId" });
|
||||
const style = new StyleForParagraph({ id: "myStyleId", basedOn: "otherId" });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -46,7 +46,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#quickFormat", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId", quickFormat: true });
|
||||
const style = new StyleForParagraph({ id: "myStyleId", quickFormat: true });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -62,7 +62,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#next", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId", next: "otherId" });
|
||||
const style = new StyleForParagraph({ id: "myStyleId", next: "otherId" });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -75,7 +75,7 @@ describe("ParagraphStyle", () => {
|
||||
|
||||
describe("formatting methods: paragraph properties", () => {
|
||||
it("#indent", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
indent: { left: 720 },
|
||||
@ -93,7 +93,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#spacing", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId", paragraph: { spacing: { before: 50, after: 150 } } });
|
||||
const style = new StyleForParagraph({ id: "myStyleId", paragraph: { spacing: { before: 50, after: 150 } } });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -106,7 +106,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#center", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
alignment: AlignmentType.CENTER,
|
||||
@ -124,7 +124,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#character spacing", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
characterSpacing: 24,
|
||||
@ -142,7 +142,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#left", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
alignment: AlignmentType.LEFT,
|
||||
@ -160,7 +160,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#right", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
alignment: AlignmentType.RIGHT,
|
||||
@ -178,7 +178,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#justified", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
alignment: AlignmentType.JUSTIFIED,
|
||||
@ -196,7 +196,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#thematicBreak", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
thematicBreak: true,
|
||||
@ -229,7 +229,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#contextualSpacing", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
contextualSpacing: true,
|
||||
@ -255,7 +255,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#leftTabStop", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
leftTabStop: 1200,
|
||||
@ -277,7 +277,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#maxRightTabStop", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
rightTabStop: TabStopPosition.MAX,
|
||||
@ -299,7 +299,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#keepLines", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
keepLines: true,
|
||||
@ -320,7 +320,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#keepNext", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
keepNext: true,
|
||||
@ -341,7 +341,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#outlineLevel", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
outlineLevel: 1,
|
||||
@ -381,7 +381,7 @@ describe("ParagraphStyle", () => {
|
||||
];
|
||||
sizeTests.forEach(({ size, sizeComplexScript, expected }) => {
|
||||
it(`#size ${size} cs ${sizeComplexScript}`, () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: { size, sizeComplexScript },
|
||||
});
|
||||
@ -393,7 +393,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#smallCaps", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
smallCaps: true,
|
||||
@ -411,7 +411,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#allCaps", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
allCaps: true,
|
||||
@ -429,7 +429,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#strike", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
strike: true,
|
||||
@ -447,7 +447,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#doubleStrike", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
doubleStrike: true,
|
||||
@ -465,7 +465,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#subScript", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
subScript: true,
|
||||
@ -483,7 +483,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#superScript", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
superScript: true,
|
||||
@ -501,7 +501,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#font by name", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
font: "Times",
|
||||
@ -530,7 +530,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#font for ascii and eastAsia", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
font: {
|
||||
@ -577,7 +577,7 @@ describe("ParagraphStyle", () => {
|
||||
];
|
||||
boldTests.forEach(({ bold, boldComplexScript, expected }) => {
|
||||
it(`#bold ${bold} cs ${boldComplexScript}`, () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: { bold, boldComplexScript },
|
||||
});
|
||||
@ -606,7 +606,7 @@ describe("ParagraphStyle", () => {
|
||||
];
|
||||
italicsTests.forEach(({ italics, italicsComplexScript, expected }) => {
|
||||
it(`#italics ${italics} cs ${italicsComplexScript}`, () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: { italics, italicsComplexScript },
|
||||
});
|
||||
@ -640,7 +640,7 @@ describe("ParagraphStyle", () => {
|
||||
];
|
||||
highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => {
|
||||
it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: { highlight, highlightComplexScript },
|
||||
});
|
||||
@ -714,7 +714,7 @@ describe("ParagraphStyle", () => {
|
||||
];
|
||||
shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => {
|
||||
it("#shadow correctly", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: { shadow, shading, shadingComplexScript },
|
||||
});
|
||||
@ -727,7 +727,7 @@ describe("ParagraphStyle", () => {
|
||||
|
||||
describe("#underline", () => {
|
||||
it("should set underline to 'single' if no arguments are given", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
underline: {},
|
||||
@ -745,7 +745,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the style if given", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
underline: {
|
||||
@ -765,7 +765,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the style and color if given", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
underline: {
|
||||
@ -788,7 +788,7 @@ describe("ParagraphStyle", () => {
|
||||
|
||||
describe("#emphasisMark", () => {
|
||||
it("should set emphasisMark to 'dot' if no arguments are given", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
emphasisMark: {},
|
||||
@ -806,7 +806,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the style if given", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
emphasisMark: {
|
||||
@ -827,7 +827,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#color", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
color: "123456",
|
||||
@ -845,7 +845,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#link", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId", link: "MyLink" });
|
||||
const style = new StyleForParagraph({ id: "myStyleId", link: "MyLink" });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -861,7 +861,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#semiHidden", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId", semiHidden: true });
|
||||
const style = new StyleForParagraph({ id: "myStyleId", semiHidden: true });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -877,7 +877,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#uiPriority", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId", uiPriority: 99 });
|
||||
const style = new StyleForParagraph({ id: "myStyleId", uiPriority: 99 });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -894,7 +894,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#unhideWhenUsed", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId", unhideWhenUsed: true });
|
||||
const style = new StyleForParagraph({ id: "myStyleId", unhideWhenUsed: true });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
|
@ -21,7 +21,7 @@ export interface IParagraphStyleOptions extends IBaseParagraphStyleOptions {
|
||||
readonly name?: string;
|
||||
}
|
||||
|
||||
export class ParagraphStyle extends Style {
|
||||
export class StyleForParagraph extends Style {
|
||||
private readonly paragraphProperties: ParagraphProperties;
|
||||
private readonly runProperties: RunProperties;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { BaseXmlComponent, ImportedXmlComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
import { CharacterStyle, ParagraphStyle } from "./style";
|
||||
import { StyleForCharacter, StyleForParagraph } from "./style";
|
||||
import { ICharacterStyleOptions } from "./style/character-style";
|
||||
import { IParagraphStyleOptions } from "./style/paragraph-style";
|
||||
export * from "./border";
|
||||
@ -9,7 +9,7 @@ export interface IStylesOptions {
|
||||
readonly initialStyles?: BaseXmlComponent;
|
||||
readonly paragraphStyles?: IParagraphStyleOptions[];
|
||||
readonly characterStyles?: ICharacterStyleOptions[];
|
||||
readonly importedStyles?: (XmlComponent | ParagraphStyle | CharacterStyle | ImportedXmlComponent)[];
|
||||
readonly importedStyles?: (XmlComponent | StyleForParagraph | StyleForCharacter | ImportedXmlComponent)[];
|
||||
}
|
||||
|
||||
export class Styles extends XmlComponent {
|
||||
@ -28,13 +28,13 @@ export class Styles extends XmlComponent {
|
||||
|
||||
if (options.paragraphStyles) {
|
||||
for (const style of options.paragraphStyles) {
|
||||
this.root.push(new ParagraphStyle(style));
|
||||
this.root.push(new StyleForParagraph(style));
|
||||
}
|
||||
}
|
||||
|
||||
if (options.characterStyles) {
|
||||
for (const style of options.characterStyles) {
|
||||
this.root.push(new CharacterStyle(style));
|
||||
this.root.push(new StyleForCharacter(style));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user