Compare commits

...

262 Commits
5.0.2 ... 5.5.0

Author SHA1 Message Date
d6f363b275 Version bump 2021-01-31 04:54:26 +00:00
118ea57412 Merge pull request #749 from dolanmiu/dependabot/npm_and_yarn/types/webpack-4.41.26
build(deps-dev): bump @types/webpack from 4.41.25 to 4.41.26
2021-01-28 10:18:02 +00:00
7c8be4c8a7 Merge pull request #757 from arran4/jszip-supports-more-datatypes
Added more data types for JSZip to consider using
2021-01-28 10:17:48 +00:00
fa9021596f Merge pull request #759 from dolanmiu/dependabot/npm_and_yarn/sinon-9.2.4
build(deps-dev): bump sinon from 9.2.2 to 9.2.4
2021-01-28 10:15:40 +00:00
3ccf4bdfe3 Ran npm run style.fix added "line_ending" configuration to .editorconfig to match the results 2021-01-26 15:09:12 +11:00
f2480673ec build(deps-dev): bump sinon from 9.2.2 to 9.2.4
Bumps [sinon](https://github.com/sinonjs/sinon) from 9.2.2 to 9.2.4.
- [Release notes](https://github.com/sinonjs/sinon/releases)
- [Changelog](https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sinonjs/sinon/compare/v9.2.2...v9.2.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-01-25 08:20:27 +00:00
e93b8032d8 Buffer is required as it was originally there too 2021-01-22 16:48:41 +11:00
5de2d8c7fb Minor change 2021-01-22 16:45:39 +11:00
e355fd3d2e build(deps-dev): bump @types/webpack from 4.41.25 to 4.41.26
Bumps [@types/webpack](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/webpack) from 4.41.25 to 4.41.26.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/webpack)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-01-12 08:20:34 +00:00
d41ef99c85 Merge pull request #739 from dolanmiu/feat/convenience-functions
Add zIndex property to floating
2020-12-25 02:26:04 +00:00
5ec18d6e01 Add tests and simplify 2020-12-25 02:15:40 +00:00
b4cd3a319c Add documentation 2020-12-25 00:30:58 +00:00
d894bfa167 Add test 2020-12-25 00:29:27 +00:00
d74db948ba Add zIndex property to floating 2020-12-25 00:07:57 +00:00
3ef26c747b Merge pull request #736 from dolanmiu/feat/convenience-functions
Use LevelFormat string enum rather than strings
2020-12-24 17:45:09 +00:00
38c8220e9e Use LevelFormat string enum rather than strings 2020-12-24 04:26:45 +00:00
86f8259b33 Merge pull request #735 from dolanmiu/feat/convenience-functions
Add Convenience functions
2020-12-24 03:44:54 +00:00
502db14bba Add Convenience functions 2020-12-24 03:37:43 +00:00
ef12ada5d7 Add parent to numbered list 2020-12-24 01:50:05 +00:00
977b2b302d Merge pull request #734 from dolanmiu/feat/strong-style
Add declarative break()
2020-12-24 00:21:07 +00:00
17d02a3d1c Fix demos 2020-12-24 00:00:24 +00:00
6100ff4c4e Add declarative break() 2020-12-23 23:31:28 +00:00
8bb73fb25e Merge pull request #729 from dolanmiu/feat/strong-style
Adding TableBorders.NONE convenience object
2020-12-23 00:28:34 +00:00
d6cce4ae15 Adding TableBorders.NONE convenience object 2020-12-22 23:42:02 +00:00
058304d16b Merge pull request #728 from dolanmiu/feat/strong-style
Add strong default style
2020-12-22 22:17:24 +00:00
345d34a2e1 Merge pull request #720 from dolanmiu/dependabot/npm_and_yarn/sinon-9.2.2
build(deps-dev): bump sinon from 9.2.1 to 9.2.2
2020-12-22 21:11:07 +00:00
3839a49d47 Merge pull request #726 from dolanmiu/dependabot/npm_and_yarn/prompt-1.1.0
build(deps-dev): bump prompt from 1.0.0 to 1.1.0
2020-12-22 21:10:57 +00:00
0afe0929a3 Add strong default style 2020-12-22 21:08:10 +00:00
a14a1fbd10 Update character style demo 2020-12-22 20:56:06 +00:00
52f0a6958a build(deps-dev): bump prompt from 1.0.0 to 1.1.0
Bumps [prompt](https://github.com/flatiron/prompt) from 1.0.0 to 1.1.0.
- [Release notes](https://github.com/flatiron/prompt/releases)
- [Changelog](https://github.com/flatiron/prompt/blob/master/CHANGELOG.md)
- [Commits](https://github.com/flatiron/prompt/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-12-22 08:14:29 +00:00
8bdde98db1 build(deps-dev): bump sinon from 9.2.1 to 9.2.2
Bumps [sinon](https://github.com/sinonjs/sinon) from 9.2.1 to 9.2.2.
- [Release notes](https://github.com/sinonjs/sinon/releases)
- [Changelog](https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sinonjs/sinon/commits/v9.2.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-12-15 08:16:05 +00:00
19fc900045 Merge pull request #708 from dolanmiu/dependabot/npm_and_yarn/ts-node-9.1.1
build(deps-dev): bump ts-node from 9.1.0 to 9.1.1
2020-12-15 02:01:08 +00:00
6bdd9b882a Merge pull request #711 from dolanmiu/dependabot/npm_and_yarn/types/mocha-8.2.0
build(deps-dev): bump @types/mocha from 8.0.4 to 8.2.0
2020-12-15 02:00:53 +00:00
0d97d428fa Merge pull request #715 from dolanmiu/dependabot/npm_and_yarn/types/request-promise-4.1.47
build(deps-dev): bump @types/request-promise from 4.1.46 to 4.1.47
2020-12-15 02:00:08 +00:00
a0b42d7bdb Merge pull request #717 from dolanmiu/dependabot/npm_and_yarn/ini-1.3.8
build(deps): bump ini from 1.3.5 to 1.3.8
2020-12-15 01:59:54 +00:00
69ba312a96 build(deps): bump ini from 1.3.5 to 1.3.8
Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.8.
- [Release notes](https://github.com/isaacs/ini/releases)
- [Commits](https://github.com/isaacs/ini/compare/v1.3.5...v1.3.8)

Signed-off-by: dependabot[bot] <support@github.com>
2020-12-11 22:47:35 +00:00
a0c13214e6 build(deps-dev): bump @types/request-promise from 4.1.46 to 4.1.47
Bumps [@types/request-promise](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/request-promise) from 4.1.46 to 4.1.47.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/request-promise)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-12-11 08:22:49 +00:00
4c8829df28 build(deps-dev): bump @types/mocha from 8.0.4 to 8.2.0
Bumps [@types/mocha](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/mocha) from 8.0.4 to 8.2.0.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/mocha)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-12-09 08:04:12 +00:00
3ee3e95410 build(deps-dev): bump ts-node from 9.1.0 to 9.1.1
Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 9.1.0 to 9.1.1.
- [Release notes](https://github.com/TypeStrong/ts-node/releases)
- [Commits](https://github.com/TypeStrong/ts-node/compare/v9.1.0...v9.1.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-12-08 08:49:26 +00:00
806deeaf78 Merge pull request #705 from dolanmiu/dependabot/npm_and_yarn/ts-node-9.1.0
build(deps-dev): bump ts-node from 9.0.0 to 9.1.0
2020-12-04 16:52:27 +00:00
feb121707d build(deps-dev): bump ts-node from 9.0.0 to 9.1.0
Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 9.0.0 to 9.1.0.
- [Release notes](https://github.com/TypeStrong/ts-node/releases)
- [Commits](https://github.com/TypeStrong/ts-node/compare/v9.0.0...v9.1.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-12-03 08:01:46 +00:00
31c7f034ec Merge pull request #697 from devoidfury/master
Add defaultStyles option to overwrite the core default styles
2020-11-30 23:58:42 +00:00
30ab92652c move file options.defaultStyles to options.styles.default 2020-11-30 10:25:58 -06:00
0407548113 Merge pull request #702 from dolanmiu/dependabot/npm_and_yarn/prettier-2.2.1
build(deps-dev): bump prettier from 2.2.0 to 2.2.1
2020-11-30 14:48:17 +00:00
277845626c build(deps-dev): bump prettier from 2.2.0 to 2.2.1
Bumps [prettier](https://github.com/prettier/prettier) from 2.2.0 to 2.2.1.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.2.0...2.2.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-30 08:29:40 +00:00
b2af8b970e Merge pull request #693 from dolanmiu/dependabot/npm_and_yarn/prettier-2.2.0
build(deps-dev): bump prettier from 2.1.2 to 2.2.0
2020-11-29 20:16:38 +00:00
542866e18b Merge pull request #699 from dolanmiu/dependabot/npm_and_yarn/highlight.js-9.18.5
build(deps): [security] bump highlight.js from 9.18.1 to 9.18.5
2020-11-29 20:16:26 +00:00
f54192809f build(deps): [security] bump highlight.js from 9.18.1 to 9.18.5
Bumps [highlight.js](https://github.com/highlightjs/highlight.js) from 9.18.1 to 9.18.5. **This update includes a security fix.**
- [Release notes](https://github.com/highlightjs/highlight.js/releases)
- [Changelog](https://github.com/highlightjs/highlight.js/blob/9.18.5/CHANGES.md)
- [Commits](https://github.com/highlightjs/highlight.js/compare/9.18.1...9.18.5)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-24 23:10:41 +00:00
f3ba62fd88 bugfix path 2020-11-24 13:36:43 -06:00
8d4a07302b Add defaultStyles option to overwrite the core default styles (Heading 1-6, document, hyperlinks, etc) 2020-11-24 13:30:26 -06:00
d504231124 build(deps-dev): bump prettier from 2.1.2 to 2.2.0
Bumps [prettier](https://github.com/prettier/prettier) from 2.1.2 to 2.2.0.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.1.2...2.2.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-20 11:14:03 +00:00
173b1e118c Merge pull request #690 from dolanmiu/dependabot/npm_and_yarn/docsify-cli-4.4.2
build(deps-dev): bump docsify-cli from 4.4.1 to 4.4.2
2020-11-17 11:50:18 +00:00
ffba276f0d build(deps-dev): bump docsify-cli from 4.4.1 to 4.4.2
Bumps [docsify-cli](https://github.com/docsifyjs/docsify-cli) from 4.4.1 to 4.4.2.
- [Release notes](https://github.com/docsifyjs/docsify-cli/releases)
- [Changelog](https://github.com/docsifyjs/docsify-cli/blob/master/CHANGELOG.md)
- [Commits](https://github.com/docsifyjs/docsify-cli/compare/v4.4.1...v4.4.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-17 11:13:13 +00:00
b210608e56 Merge pull request #685 from dolanmiu/dependabot/npm_and_yarn/types/mocha-8.0.4
build(deps-dev): bump @types/mocha from 8.0.3 to 8.0.4
2020-11-16 12:53:20 +00:00
74353104dc Merge pull request #687 from dolanmiu/dependabot/npm_and_yarn/types/webpack-4.41.25
build(deps-dev): bump @types/webpack from 4.41.24 to 4.41.25
2020-11-16 12:53:09 +00:00
825136d1c9 Version bump 2020-11-15 23:04:27 +00:00
b2fea471f1 Add workaround to include file in build 2020-11-15 23:03:44 +00:00
e9adb8b0ed build(deps-dev): bump @types/webpack from 4.41.24 to 4.41.25
Bumps [@types/webpack](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/webpack) from 4.41.24 to 4.41.25.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/webpack)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-12 08:27:51 +00:00
5d6bc039d0 build(deps-dev): bump @types/mocha from 8.0.3 to 8.0.4
Bumps [@types/mocha](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/mocha) from 8.0.3 to 8.0.4.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/mocha)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-11 07:56:26 +00:00
27638063c8 Update README.md 2020-11-06 02:08:09 +00:00
f6a4d78ab7 Add checks when submitting PR 2020-11-06 01:51:59 +00:00
4061e31400 Merge pull request #679 from dolanmiu/feat/re-name
Re-name paragraph styles
2020-11-06 01:47:49 +00:00
74db67689f Re-name paragraph styles 2020-11-06 00:27:57 +00:00
2213eb28cb Add Github Actions badge 2020-11-05 02:44:05 +00:00
d1b45d416b Fix spacing issue 2020-11-05 00:33:54 +00:00
f72f7e7514 Add build files to demo workflow 2020-11-05 00:17:55 +00:00
0165cfb3e5 Fix typo 2020-11-05 00:11:02 +00:00
ef747486c0 Remove comments 2020-11-04 23:40:59 +00:00
e0b2f59c2f Add initial GitHub Actions workflow 2020-11-04 23:36:28 +00:00
82bdb301f9 Version bump 2020-11-04 02:52:28 +00:00
c7ea26e422 Add tests 2020-11-04 01:28:46 +00:00
34b2029efe Change API of track revisions to declarative 2020-11-04 00:00:16 +00:00
37e610d2b3 Fix typo 2020-10-30 00:13:52 +00:00
4882235d20 Merge pull request #673 from dolanmiu/dependabot/npm_and_yarn/types/webpack-4.41.24
build(deps-dev): bump @types/webpack from 4.41.23 to 4.41.24
2020-10-29 23:56:22 +00:00
1552ebde11 build(deps-dev): bump @types/webpack from 4.41.23 to 4.41.24
Bumps [@types/webpack](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/webpack) from 4.41.23 to 4.41.24.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/webpack)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-10-29 22:54:05 +00:00
d263d0c8a5 Merge pull request #669 from dolanmiu/feat/background-color
Add shading to paragraph
2020-10-29 01:57:28 +00:00
610b2388bb Fix linting 2020-10-29 00:39:45 +00:00
bcb16cef9b Merge pull request #672 from dolanmiu/dependabot/npm_and_yarn/sinon-9.2.1
build(deps-dev): bump sinon from 9.2.0 to 9.2.1
2020-10-28 19:42:18 +00:00
0f3afd94f3 build(deps-dev): bump sinon from 9.2.0 to 9.2.1
Bumps [sinon](https://github.com/sinonjs/sinon) from 9.2.0 to 9.2.1.
- [Release notes](https://github.com/sinonjs/sinon/releases)
- [Changelog](https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sinonjs/sinon/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-10-28 15:28:10 +00:00
60eb686d05 Add shading to paragraph 2020-10-28 01:05:31 +00:00
7f5e43fba9 Merge pull request #667 from dolanmiu/feat/background-color
Background color for document
2020-10-27 02:45:19 +00:00
ed52ef358b Background color for document 2020-10-27 01:54:40 +00:00
214afab711 Merge branch 'master' of github.com:dolanmiu/docx 2020-10-24 21:38:30 +01:00
18a1677588 Add documentation reference 2020-10-24 21:38:20 +01:00
cae372e9ad Merge pull request #664 from dolanmiu/dependabot/npm_and_yarn/shortid-2.2.16
build(deps): bump shortid from 2.2.15 to 2.2.16
2020-10-24 21:03:53 +01:00
ea5f9a48ab Fix cantSplit documentation 2020-10-24 20:24:10 +01:00
dcf755e756 build(deps): bump shortid from 2.2.15 to 2.2.16
Bumps [shortid](https://github.com/dylang/shortid) from 2.2.15 to 2.2.16.
- [Release notes](https://github.com/dylang/shortid/releases)
- [Changelog](https://github.com/dylang/shortid/blob/master/CHANGELOG.md)
- [Commits](https://github.com/dylang/shortid/compare/2.2.15...2.2.16)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-10-24 00:40:43 +00:00
d445c21ea1 Merge pull request #662 from dolanmiu/dependabot/npm_and_yarn/types/webpack-4.41.23
build(deps-dev): bump @types/webpack from 4.41.22 to 4.41.23
2020-10-22 16:51:33 +01:00
6db0449ed0 build(deps-dev): bump @types/webpack from 4.41.22 to 4.41.23
Bumps [@types/webpack](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/webpack) from 4.41.22 to 4.41.23.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/webpack)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-10-21 11:55:53 +00:00
ae37b1980f Update Prettier 2020-10-16 16:20:04 +01:00
96f76906c4 Merge pull request #381 from dolanmiu/feat/math
MathML
2020-10-13 03:08:43 +01:00
19d9619785 Add more math documentation 2020-10-13 03:00:14 +01:00
5be195fd91 Turn math component into array 2020-10-13 02:06:27 +01:00
e36e9e1cf4 Add initial math documentation 2020-10-13 01:23:27 +01:00
102d6aa55c Add prepForXml test 2020-10-12 22:48:38 +01:00
daea8d2868 Make fractions take math component 2020-10-12 22:13:03 +01:00
700a74fd4c More math components 2020-10-10 13:41:26 +01:00
32a84a5ad0 Merge branch 'master' into feat/math 2020-10-08 10:25:45 +01:00
3c9f9474ce Merge pull request #653 from dolanmiu/dependabot/npm_and_yarn/sinon-9.2.0
build(deps-dev): bump sinon from 9.1.0 to 9.2.0
2020-10-07 11:49:11 +01:00
1e10686315 Merge pull request #644 from branzillacorp/track-revisions
basic support for track revisions
2020-10-07 11:48:47 +01:00
cae6405d9a improved signature for deleted text runs, added demo 54 and added documentation for change tracking 2020-10-07 11:44:23 +02:00
a884ce94e5 build(deps-dev): bump sinon from 9.1.0 to 9.2.0
Bumps [sinon](https://github.com/sinonjs/sinon) from 9.1.0 to 9.2.0.
- [Release notes](https://github.com/sinonjs/sinon/releases)
- [Changelog](https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sinonjs/sinon/compare/v9.1.0...v9.2.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-10-07 08:55:47 +00:00
065c17de74 style fixes 2020-10-06 11:05:52 +02:00
09db2c528a added InsertedTextRun and DeletedTextRun for Revision Tracking 2020-10-06 11:05:52 +02:00
2adfe532dd add more unit tests for trackRevision settings 2020-10-06 11:05:52 +02:00
6cbe40cecb add settings option to add trackRevisions 2020-10-06 11:05:52 +02:00
6b9467393e Merge pull request #651 from dolanmiu/dependabot/npm_and_yarn/sinon-9.1.0
build(deps-dev): bump sinon from 9.0.3 to 9.1.0
2020-10-05 22:31:28 +01:00
5125e77431 build(deps-dev): bump sinon from 9.0.3 to 9.1.0
Bumps [sinon](https://github.com/sinonjs/sinon) from 9.0.3 to 9.1.0.
- [Release notes](https://github.com/sinonjs/sinon/releases)
- [Changelog](https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sinonjs/sinon/compare/v9.0.3...v9.1.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-10-05 19:38:42 +00:00
ab68ae0092 Merge pull request #640 from dolanmiu/dependabot/npm_and_yarn/prettier-2.1.2
build(deps-dev): bump prettier from 2.1.1 to 2.1.2
2020-09-26 17:40:57 +01:00
38079b6171 build(deps-dev): bump prettier from 2.1.1 to 2.1.2
Bumps [prettier](https://github.com/prettier/prettier) from 2.1.1 to 2.1.2.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.1.1...2.1.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-09-21 18:43:32 +00:00
d584290f3d Merge pull request #635 from dolanmiu/dependabot/npm_and_yarn/node-fetch-2.6.1
build(deps): [security] bump node-fetch from 2.6.0 to 2.6.1
2020-09-13 03:01:42 +01:00
9b9baa9b4a Merge pull request #636 from netbymatt/master
Fix row height option documentation
2020-09-13 03:01:30 +01:00
c258310560 Merge pull request #1 from netbymatt/netbymatt-patch-1
Fix row height option
2020-09-11 21:10:45 -05:00
af0bf5ced5 Fix row height option 2020-09-11 21:10:10 -05:00
57c480a6c6 build(deps): [security] bump node-fetch from 2.6.0 to 2.6.1
Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1. **This update includes a security fix.**
- [Release notes](https://github.com/bitinn/node-fetch/releases)
- [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
- [Commits](https://github.com/bitinn/node-fetch/compare/v2.6.0...v2.6.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-09-11 16:44:55 +00:00
25f7423533 Merge pull request #633 from dolanmiu/dependabot/npm_and_yarn/types/webpack-4.41.22
build(deps-dev): bump @types/webpack from 4.41.21 to 4.41.22
2020-09-08 12:44:14 +01:00
0c068bb03b build(deps-dev): bump @types/webpack from 4.41.21 to 4.41.22
Bumps [@types/webpack](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/webpack) from 4.41.21 to 4.41.22.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/webpack)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-09-07 18:39:58 +00:00
1822473abc Merge branch 'master' of github.com:dolanmiu/docx 2020-09-05 18:52:05 +01:00
93a7d607b2 Update PSD 2020-09-05 18:51:50 +01:00
d45213636c Add Clippy to readme 2020-09-05 18:41:24 +01:00
e196d9d917 Add Clippy the mascot 2020-09-05 18:40:40 +01:00
cf88e50afd Merge pull request #630 from dolanmiu/dependabot/npm_and_yarn/prettier-2.1.1
build(deps-dev): bump prettier from 2.1.0 to 2.1.1
2020-08-31 22:06:05 +01:00
64e5814c31 Merge pull request #631 from dolanmiu/dependabot/npm_and_yarn/types/node-14.6.2
build(deps): bump @types/node from 14.6.0 to 14.6.2
2020-08-31 22:05:54 +01:00
37251c84f8 build(deps): bump @types/node from 14.6.0 to 14.6.2
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.6.0 to 14.6.2.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-08-31 19:37:11 +00:00
a576098639 build(deps-dev): bump prettier from 2.1.0 to 2.1.1
Bumps [prettier](https://github.com/prettier/prettier) from 2.1.0 to 2.1.1.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.1.0...2.1.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-08-31 19:36:39 +00:00
2450fe83ce Merge pull request #624 from dolanmiu/dependabot/npm_and_yarn/ts-node-9.0.0
build(deps-dev): bump ts-node from 8.10.2 to 9.0.0
2020-08-27 01:13:34 +01:00
e1004440d2 Merge pull request #625 from dolanmiu/dependabot/npm_and_yarn/prettier-2.1.0
build(deps-dev): bump prettier from 2.0.5 to 2.1.0
2020-08-27 01:13:15 +01:00
491c7abd1c build(deps-dev): bump prettier from 2.0.5 to 2.1.0
Bumps [prettier](https://github.com/prettier/prettier) from 2.0.5 to 2.1.0.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.0.5...2.1.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-08-24 18:36:24 +00:00
364ce6d856 build(deps-dev): bump ts-node from 8.10.2 to 9.0.0
Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 8.10.2 to 9.0.0.
- [Release notes](https://github.com/TypeStrong/ts-node/releases)
- [Commits](https://github.com/TypeStrong/ts-node/compare/v8.10.2...v9.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-08-24 18:35:48 +00:00
ffb6b73bb7 Merge pull request #618 from dolanmiu/dependabot/npm_and_yarn/dot-prop-4.2.1
build(deps): [security] bump dot-prop from 4.2.0 to 4.2.1
2020-08-21 23:55:11 +01:00
6041c39a26 Merge pull request #619 from dolanmiu/dependabot/npm_and_yarn/types/node-14.6.0
build(deps): bump @types/node from 14.0.27 to 14.6.0
2020-08-21 23:54:59 +01:00
c54f0a52f6 Merge pull request #621 from RayBB/patch-1
remove broken examples link
2020-08-21 23:54:42 +01:00
6b87d9c038 Merge pull request #620 from dolanmiu/dependabot/npm_and_yarn/types/mocha-8.0.3
build(deps-dev): bump @types/mocha from 8.0.2 to 8.0.3
2020-08-21 23:54:21 +01:00
1285304f97 remove broken examples link 2020-08-19 10:54:27 -10:00
58fae6b201 build(deps-dev): bump @types/mocha from 8.0.2 to 8.0.3
Bumps [@types/mocha](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/mocha) from 8.0.2 to 8.0.3.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/mocha)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-08-18 08:30:15 +00:00
dc1f3aebe9 build(deps): bump @types/node from 14.0.27 to 14.6.0
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.0.27 to 14.6.0.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-08-18 08:29:38 +00:00
8a189161f2 build(deps): [security] bump dot-prop from 4.2.0 to 4.2.1
Bumps [dot-prop](https://github.com/sindresorhus/dot-prop) from 4.2.0 to 4.2.1. **This update includes a security fix.**
- [Release notes](https://github.com/sindresorhus/dot-prop/releases)
- [Commits](https://github.com/sindresorhus/dot-prop/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-08-18 08:28:30 +00:00
6667595627 Merge pull request #615 from dolanmiu/dependabot/npm_and_yarn/sinon-9.0.3
build(deps-dev): bump sinon from 9.0.2 to 9.0.3
2020-08-13 01:27:02 +01:00
33befaab09 Merge pull request #616 from dolanmiu/dependabot/npm_and_yarn/types/mocha-8.0.2
build(deps-dev): bump @types/mocha from 8.0.1 to 8.0.2
2020-08-12 22:52:13 +01:00
c91f135c28 build(deps-dev): bump @types/mocha from 8.0.1 to 8.0.2
Bumps [@types/mocha](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/mocha) from 8.0.1 to 8.0.2.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/mocha)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-08-12 08:37:49 +00:00
08f9926e60 build(deps-dev): bump sinon from 9.0.2 to 9.0.3
Bumps [sinon](https://github.com/sinonjs/sinon) from 9.0.2 to 9.0.3.
- [Release notes](https://github.com/sinonjs/sinon/releases)
- [Changelog](https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sinonjs/sinon/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-08-11 08:38:15 +00:00
f323b293fb Merge pull request #606 from dolanmiu/dependabot/npm_and_yarn/types/mocha-8.0.1
build(deps-dev): bump @types/mocha from 8.0.0 to 8.0.1
2020-08-08 01:36:47 +01:00
adc91929b0 Merge pull request #609 from LeovR/patch-1
Fix comment regarding output file name
2020-08-08 01:36:34 +01:00
c63cba5a0c Merge pull request #610 from dolanmiu/dependabot/npm_and_yarn/prismjs-1.21.0
build(deps): [security] bump prismjs from 1.20.0 to 1.21.0
2020-08-08 01:36:01 +01:00
7a48da440b build(deps): [security] bump prismjs from 1.20.0 to 1.21.0
Bumps [prismjs](https://github.com/PrismJS/prism) from 1.20.0 to 1.21.0. **This update includes a security fix.**
- [Release notes](https://github.com/PrismJS/prism/releases)
- [Changelog](https://github.com/PrismJS/prism/blob/master/CHANGELOG.md)
- [Commits](https://github.com/PrismJS/prism/compare/v1.20.0...v1.21.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-08-07 22:43:32 +00:00
05dda37b71 Fix comment regarding output file name 2020-08-06 08:56:02 +00:00
ee43585210 build(deps-dev): bump @types/mocha from 8.0.0 to 8.0.1
Bumps [@types/mocha](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/mocha) from 8.0.0 to 8.0.1.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/mocha)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-08-03 09:48:31 +00:00
a6eb8e01df Merge pull request #604 from dolanmiu/feat/prettier-update
Update tslint to v6
2020-08-01 18:04:47 +01:00
8c45c30753 Merge pull request #598 from dolanmiu/dependabot/npm_and_yarn/rimraf-3.0.2
build(deps-dev): bump rimraf from 2.6.3 to 3.0.2
2020-08-01 17:58:31 +01:00
d18cfbc26f Update tslint to v6 2020-08-01 17:58:16 +01:00
f4af5f9e33 Merge pull request #603 from dolanmiu/feat/prettier-update
Update prettier
2020-08-01 17:55:38 +01:00
69adbbc1c1 Bump node version 2020-08-01 17:49:25 +01:00
4f6a9f734c Update prettier 2020-08-01 17:40:57 +01:00
8b78f2d200 Version bump 2020-08-01 17:28:11 +01:00
26a3fa6946 Merge pull request #596 from SpringMT/master
feat: Add decimalFullWidth numbering type
2020-08-01 17:25:12 +01:00
f955a18936 build(deps-dev): bump rimraf from 2.6.3 to 3.0.2
Bumps [rimraf](https://github.com/isaacs/rimraf) from 2.6.3 to 3.0.2.
- [Release notes](https://github.com/isaacs/rimraf/releases)
- [Changelog](https://github.com/isaacs/rimraf/blob/master/CHANGELOG.md)
- [Commits](https://github.com/isaacs/rimraf/compare/v2.6.3...v3.0.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-08-01 01:59:37 +00:00
ee1a7818b6 Merge pull request #600 from dolanmiu/dependabot/npm_and_yarn/ts-node-8.10.2
build(deps-dev): bump ts-node from 7.0.1 to 8.10.2
2020-08-01 02:57:50 +01:00
8e455f1097 Merge pull request #601 from dolanmiu/dependabot/npm_and_yarn/nyc-15.1.0
build(deps-dev): bump nyc from 14.1.1 to 15.1.0
2020-08-01 02:56:06 +01:00
827c46cf47 build(deps-dev): bump nyc from 14.1.1 to 15.1.0
Bumps [nyc](https://github.com/istanbuljs/nyc) from 14.1.1 to 15.1.0.
- [Release notes](https://github.com/istanbuljs/nyc/releases)
- [Changelog](https://github.com/istanbuljs/nyc/blob/master/CHANGELOG.md)
- [Commits](https://github.com/istanbuljs/nyc/compare/v14.1.1...v15.1.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-31 09:08:10 +00:00
61cbee829d build(deps-dev): bump ts-node from 7.0.1 to 8.10.2
Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 7.0.1 to 8.10.2.
- [Release notes](https://github.com/TypeStrong/ts-node/releases)
- [Commits](https://github.com/TypeStrong/ts-node/compare/v7.0.1...v8.10.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-31 09:06:34 +00:00
f0ad1e9194 feat: Add decimalFullWidth numbering type 2020-07-31 16:36:56 +09:00
bbd339f0e4 Merge pull request #571 from dolanmiu/dependabot/npm_and_yarn/sinon-9.0.2
Bump sinon from 5.1.1 to 9.0.2
2020-07-30 13:23:18 +01:00
858af64dc3 Improve coverage threshold 2020-07-30 13:07:48 +01:00
01e34c1b28 Bump sinon from 5.1.1 to 9.0.2
Bumps [sinon](https://github.com/sinonjs/sinon) from 5.1.1 to 9.0.2.
- [Release notes](https://github.com/sinonjs/sinon/releases)
- [Changelog](https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sinonjs/sinon/compare/v5.1.1...v9.0.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-30 10:48:07 +00:00
41acb475a9 Update documentation 2020-07-30 11:42:55 +01:00
20978f8c24 Merge pull request #578 from dolanmiu/dependabot/npm_and_yarn/types/request-promise-4.1.46
Bump @types/request-promise from 4.1.44 to 4.1.46
2020-07-30 10:09:50 +01:00
265a3dbe21 Merge pull request #592 from dolanmiu/dependabot/npm_and_yarn/types/jszip-3.4.1
Bump @types/jszip from 3.1.6 to 3.4.1
2020-07-30 10:09:21 +01:00
627f5b4bf0 Merge pull request #593 from dolanmiu/dependabot/npm_and_yarn/types/node-14.0.27
Bump @types/node from 14.0.23 to 14.0.27
2020-07-30 10:08:55 +01:00
1538c1aaeb Merge pull request #594 from dolanmiu/dependabot/npm_and_yarn/types/webpack-4.41.21
Bump @types/webpack from 4.4.34 to 4.41.21
2020-07-30 10:08:32 +01:00
839661e5f8 Bump @types/webpack from 4.4.34 to 4.41.21
Bumps [@types/webpack](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/webpack) from 4.4.34 to 4.41.21.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/webpack)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-30 08:50:39 +00:00
fff6244597 Bump @types/node from 14.0.23 to 14.0.27
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.0.23 to 14.0.27.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-30 08:49:24 +00:00
b2280f64a1 Bump @types/jszip from 3.1.6 to 3.4.1
Bumps [@types/jszip](https://github.com/Stuk/jszip) from 3.1.6 to 3.4.1.
- [Release notes](https://github.com/Stuk/jszip/releases)
- [Changelog](https://github.com/Stuk/jszip/blob/master/CHANGES.md)
- [Commits](https://github.com/Stuk/jszip/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-30 08:48:47 +00:00
21d53c41d0 Bump @types/request-promise from 4.1.44 to 4.1.46
Bumps [@types/request-promise](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/request-promise) from 4.1.44 to 4.1.46.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/request-promise)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-30 01:44:26 +00:00
6e94bbb5e5 Merge pull request #588 from dolanmiu/dependabot/npm_and_yarn/typedoc-0.16.11
Bump typedoc from 0.11.1 to 0.16.11
2020-07-30 02:41:09 +01:00
7d655cd3f7 Merge pull request #589 from dolanmiu/dependabot/npm_and_yarn/shelljs-0.8.4
Bump shelljs from 0.7.8 to 0.8.4
2020-07-30 02:40:43 +01:00
00821677c8 Merge pull request #591 from dolanmiu/dependabot/npm_and_yarn/elliptic-6.5.3
[Security] Bump elliptic from 6.5.0 to 6.5.3
2020-07-30 02:40:28 +01:00
784de3e430 [Security] Bump elliptic from 6.5.0 to 6.5.3
Bumps [elliptic](https://github.com/indutny/elliptic) from 6.5.0 to 6.5.3. **This update includes a security fix.**
- [Release notes](https://github.com/indutny/elliptic/releases)
- [Commits](https://github.com/indutny/elliptic/compare/v6.5.0...v6.5.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-29 21:32:19 +00:00
3213c4838d Bump shelljs from 0.7.8 to 0.8.4
Bumps [shelljs](https://github.com/shelljs/shelljs) from 0.7.8 to 0.8.4.
- [Release notes](https://github.com/shelljs/shelljs/releases)
- [Changelog](https://github.com/shelljs/shelljs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/shelljs/shelljs/compare/v0.7.8...v0.8.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-28 08:43:57 +00:00
1b9bc8eb1d Bump typedoc from 0.11.1 to 0.16.11
Bumps [typedoc](https://github.com/TypeStrong/TypeDoc) from 0.11.1 to 0.16.11.
- [Release notes](https://github.com/TypeStrong/TypeDoc/releases)
- [Commits](https://github.com/TypeStrong/TypeDoc/compare/v0.11.1...v0.16.11)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-28 08:43:10 +00:00
bf58d0b864 Merge pull request #581 from dolanmiu/dependabot/npm_and_yarn/docsify-cli-4.4.1
Bump docsify-cli from 4.3.0 to 4.4.1
2020-07-27 19:38:06 +01:00
28ca8392ed Merge pull request #577 from dolanmiu/dependabot/npm_and_yarn/request-2.88.2
Bump request from 2.88.0 to 2.88.2
2020-07-27 19:37:53 +01:00
5238c55bc2 Bump docsify-cli from 4.3.0 to 4.4.1
Bumps [docsify-cli](https://github.com/QingWei-Li/docsify-cli) from 4.3.0 to 4.4.1.
- [Release notes](https://github.com/QingWei-Li/docsify-cli/releases)
- [Changelog](https://github.com/docsifyjs/docsify-cli/blob/master/CHANGELOG.md)
- [Commits](https://github.com/QingWei-Li/docsify-cli/compare/v4.3.0...v4.4.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-27 09:10:52 +00:00
901f10c387 Bump request from 2.88.0 to 2.88.2
Bumps [request](https://github.com/request/request) from 2.88.0 to 2.88.2.
- [Release notes](https://github.com/request/request/releases)
- [Changelog](https://github.com/request/request/blob/master/CHANGELOG.md)
- [Commits](https://github.com/request/request/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-27 09:10:49 +00:00
defa22ffe5 Merge pull request #585 from dolanmiu/dependabot/npm_and_yarn/request-promise-4.2.6
Bump request-promise from 4.2.4 to 4.2.6
2020-07-27 10:08:50 +01:00
84919c0cc0 Update README.md 2020-07-27 09:56:30 +01:00
1e8ca123b0 Bump request-promise from 4.2.4 to 4.2.6
Bumps [request-promise](https://github.com/request/request-promise) from 4.2.4 to 4.2.6.
- [Release notes](https://github.com/request/request-promise/releases)
- [Commits](https://github.com/request/request-promise/compare/v4.2.4...v4.2.6)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-22 08:57:50 +00:00
3ae7c6aedf Merge pull request #568 from dolanmiu/dependabot/npm_and_yarn/jszip-3.5.0
Bump jszip from 3.2.2 to 3.5.0
2020-07-18 03:00:56 +01:00
6a3ed4bbf8 Merge pull request #567 from dolanmiu/dependabot/npm_and_yarn/handlebars-4.7.6
[Security] Bump handlebars from 4.5.3 to 4.7.6
2020-07-18 02:56:33 +01:00
e632d323c9 Merge pull request #570 from dolanmiu/dependabot/npm_and_yarn/types/mocha-8.0.0
Bump @types/mocha from 2.2.48 to 8.0.0
2020-07-18 02:56:09 +01:00
d2b35ab8f2 Merge pull request #566 from dolanmiu/dependabot/npm_and_yarn/types/node-14.0.23
Bump @types/node from 14.0.5 to 14.0.23
2020-07-18 02:55:32 +01:00
e60f39df41 Merge pull request #572 from dolanmiu/dependabot/npm_and_yarn/lodash-4.17.19
[Security] Bump lodash from 4.17.15 to 4.17.19
2020-07-18 02:55:09 +01:00
076431e04d Merge pull request #574 from dolanmiu/dependabot/npm_and_yarn/types/sinon-9.0.4
Bump @types/sinon from 4.3.3 to 9.0.4
2020-07-18 02:54:47 +01:00
75ab44403c Merge pull request #575 from dolanmiu/dependabot/npm_and_yarn/glob-7.1.6
Bump glob from 7.1.4 to 7.1.6
2020-07-18 02:54:28 +01:00
e2d6097819 Bump glob from 7.1.4 to 7.1.6
Bumps [glob](https://github.com/isaacs/node-glob) from 7.1.4 to 7.1.6.
- [Release notes](https://github.com/isaacs/node-glob/releases)
- [Changelog](https://github.com/isaacs/node-glob/blob/master/changelog.md)
- [Commits](https://github.com/isaacs/node-glob/compare/v7.1.4...v7.1.6)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-17 08:43:39 +00:00
ab12ff1257 Bump @types/sinon from 4.3.3 to 9.0.4
Bumps [@types/sinon](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/sinon) from 4.3.3 to 9.0.4.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/sinon)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-17 08:42:58 +00:00
25a0212f4e [Security] Bump lodash from 4.17.15 to 4.17.19
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19. **This update includes a security fix.**
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-17 08:41:22 +00:00
a8993f14d6 Bump @types/mocha from 2.2.48 to 8.0.0
Bumps [@types/mocha](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/mocha) from 2.2.48 to 8.0.0.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/mocha)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-16 20:26:36 +00:00
1834cd86da Bump jszip from 3.2.2 to 3.5.0
Bumps [jszip](https://github.com/Stuk/jszip) from 3.2.2 to 3.5.0.
- [Release notes](https://github.com/Stuk/jszip/releases)
- [Changelog](https://github.com/Stuk/jszip/blob/master/CHANGES.md)
- [Commits](https://github.com/Stuk/jszip/compare/v3.2.2...v3.5.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-16 20:25:38 +00:00
437de27ed8 [Security] Bump handlebars from 4.5.3 to 4.7.6
Bumps [handlebars](https://github.com/wycats/handlebars.js) from 4.5.3 to 4.7.6. **This update includes a security fix.**
- [Release notes](https://github.com/wycats/handlebars.js/releases)
- [Changelog](https://github.com/handlebars-lang/handlebars.js/blob/master/release-notes.md)
- [Commits](https://github.com/wycats/handlebars.js/compare/v4.5.3...v4.7.6)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-16 20:25:17 +00:00
96f08482da Bump @types/node from 14.0.5 to 14.0.23
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.0.5 to 14.0.23.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-07-16 20:24:56 +00:00
edec2eca7a Add another React example 2020-07-16 16:08:50 +01:00
9202524d83 Fix Vue.js stylistics 2020-07-16 14:15:47 +01:00
0461907533 Add VueJS example 2020-07-16 14:13:55 +01:00
445a2896d2 Add React example 2020-07-16 12:35:47 +01:00
e2d8f1b6b1 Merge pull request #562 from wangfengming/master
Feature: refine paragraph/run properties options
2020-07-15 10:30:24 +01:00
7baa696a76 :feat: coverage ignore file src/import-dotx/import-dotx.ts 2020-07-15 14:11:59 +08:00
3f7ca6bbff :test: document defaults & numbering suffix 2020-07-15 14:11:26 +08:00
36e1c5fe6a :feat: refined defaults 2020-07-15 14:10:37 +08:00
75a03f1576 :test: update test for complex script 2020-07-15 12:46:46 +08:00
437e83ab78 :feat: refine paragraph/run properties options 2020-07-14 15:42:45 +08:00
b8232f7a02 Version bump 2020-07-11 19:34:29 +01:00
49eadb0efc Merge pull request #559 from wangfengming/master
:fix: `rowSpan` can't work when column index out of range
2020-07-09 01:29:06 +01:00
40dc90e585 :fix: insert the continue cell properly 2020-07-08 12:32:01 +08:00
0de302d192 :typo: update comments 2020-07-08 11:26:24 +08:00
80bab95f6c :fix: rowSpan can't work when column index out of range 2020-07-08 10:55:15 +08:00
ba3d551c9f Version bump 2020-06-29 01:17:13 +01:00
d14fe31f97 Merge pull request #553 from wangfengming/master
Fix: `rowSpan` does not work correctly
2020-06-24 16:39:57 +01:00
057f41e355 :test: more test cases 2020-06-22 12:34:08 +08:00
8c9b61b37a :fix: handle rowSpan by convert between the virtual column index and the root index 2020-06-22 12:25:51 +08:00
11e54b3e2c :fix: handle cell that has both columnSpan and rowSpan 2020-06-20 21:36:35 +08:00
fa7cb0bef1 :test: add test case for columnSpan and rowSpan 2020-06-20 21:01:23 +08:00
3977c8ab3b :fix: rowSpan continue cell should has the same border to the first row cell 2020-06-20 20:20:22 +08:00
e8f92efe05 Merge pull request #2 from dolanmiu/master
merge from origin
2020-06-20 20:05:20 +08:00
994df8531b :fix: rowSpan does not work correctly 2020-06-20 19:47:46 +08:00
3cdf96ee0c Version bump 2020-06-17 14:34:27 +01:00
e2f55d52e9 Merge pull request #550 from wangfengming/feature/enhance-font
Feature/enhance font
2020-06-13 20:38:22 +01:00
d6fa33035a :doc: update demo 53-chinese.ts 2020-06-07 14:58:59 +08:00
f11bca728f :typo: update comment for the demo 2020-06-07 12:46:21 +08:00
596761d78d :doc: doc and demo for "Font for eastAsia" 2020-06-07 12:39:17 +08:00
8a3c8d4664 :test: Font for eastAsia 2020-06-07 12:38:31 +08:00
fdfce79e87 :feat: Font for eastAsia 2020-06-07 12:38:03 +08:00
88340aa336 Merge pull request #1 from dolanmiu/master
merge from origin
2020-06-03 19:04:55 +08:00
d0f53fdd4b Merge branch 'master' of github.com:dolanmiu/docx
# Conflicts:
#	package-lock.json
2020-05-28 18:40:44 +01:00
d657f61e11 Update node types 2020-05-28 18:38:55 +01:00
20e6b98770 Version bump 2020-05-26 21:07:30 +01:00
5ae824358c Revert "Update numbering.ts"
This reverts commit 0ebdcc30ed.
2020-05-26 21:06:43 +01:00
3ea106bd22 Merge pull request #546 from wangfengming/feature/emphasis-mark
Feature/emphasis mark
2020-05-22 13:29:25 +01:00
538264dec5 :demo: support emphasis mark 2020-05-22 12:56:02 +08:00
6bcd1c2c24 :doc: support emphasis mark 2020-05-22 12:32:40 +08:00
120c3a7bbe :feat: support emphasis mark 2020-05-22 12:22:45 +08:00
2654799822 Version bump 2020-05-19 19:24:29 +01:00
6245635b86 Merge pull request #540 from bschwarz/add-tablecell-textdirection
adds textDirection to table cells
2020-05-13 03:00:20 +01:00
b4f1c4dd6a Increase readability for enums 2020-05-13 02:51:47 +01:00
25a7ce3742 adds textDirection to table cells 2020-05-10 10:36:25 -07:00
08bc069cbf Merge pull request #539 from adrielstar/master
Update numbering.ts
2020-05-10 16:45:06 +01:00
0ebdcc30ed Update numbering.ts 2020-05-07 11:49:42 +02:00
3eca81d3f5 Merge branch 'master' of github.com:dolanmiu/docx 2020-05-06 02:15:32 +01:00
faefbae3a1 Add Japanese example 2020-05-06 02:13:25 +01:00
370fb098ac Merge pull request #480 from dolanmiu/dependabot/npm_and_yarn/handlebars-4.5.3
Bump handlebars from 4.1.2 to 4.5.3
2020-05-06 01:58:10 +01:00
c73019d84c Merge branch 'master' of github.com:dolanmiu/docx 2020-04-23 11:51:38 +01:00
250a1de71e Disable e2e temporarily 2020-04-23 11:50:56 +01:00
012963e90a Merge pull request #527 from boopathikumar018/master
Enabled dark and light mode with switch for docs using docsify-darklight-theme with redesigned search bar
2020-04-20 01:22:08 +01:00
632f3cd19b Enabled dark and light mode with switch for docs using docsify-darklight-theme 2020-04-18 01:48:00 +05:30
1c8cd325d7 Add character styles demo 2020-02-27 11:10:00 +00:00
7bcdaab2f2 Updated Hyperlink demo
To test image followed up by hyperlink bug
2020-02-27 10:44:07 +00:00
5b58e520f9 Update CodePen and JSFiddle examples 2020-01-19 02:55:31 +00:00
78f6ea6c44 Update JSFiddle Demo 2020-01-19 02:50:31 +00:00
b5172e73f9 Package lock bump 2020-01-17 21:26:09 +00:00
49b7ac212d Bump handlebars from 4.1.2 to 4.5.3
Bumps [handlebars](https://github.com/wycats/handlebars.js) from 4.1.2 to 4.5.3.
- [Release notes](https://github.com/wycats/handlebars.js/releases)
- [Changelog](https://github.com/wycats/handlebars.js/blob/master/release-notes.md)
- [Commits](https://github.com/wycats/handlebars.js/compare/v4.1.2...v4.5.3)

Signed-off-by: dependabot[bot] <support@github.com>
2019-12-27 01:44:24 +00:00
9aab68a8f8 Merge branch 'master' into feat/math
# Conflicts:
#	src/file/paragraph/index.ts
#	src/file/paragraph/paragraph.ts
2019-11-01 02:43:14 +00:00
4f8d435e16 Add Math Summation 2019-08-20 20:40:40 +01:00
a1b9be453b Add math run and fraction 2019-08-15 00:47:55 +01:00
221 changed files with 9505 additions and 3291 deletions

View File

@ -7,6 +7,7 @@ indent_style = space
indent_size = 4 indent_size = 4
insert_final_newline = true insert_final_newline = true
trim_trailing_whitespace = true trim_trailing_whitespace = true
end_of_line = lf
[*.md] [*.md]
max_line_length = off max_line_length = off

104
.github/workflows/default.yml vendored Normal file
View 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

2
.nvmrc
View File

@ -1 +1 @@
v8 v10

11
.nycrc
View File

@ -1,14 +1,15 @@
{ {
"check-coverage": true, "check-coverage": true,
"lines": 93.53, "lines": 96.81,
"functions": 89.63, "functions": 93.80,
"branches": 88.57, "branches": 92.63,
"statements": 93.34, "statements": 96.80,
"include": [ "include": [
"src/**/*.ts" "src/**/*.ts"
], ],
"exclude": [ "exclude": [
"src/**/*.spec.ts" "src/**/*.spec.ts",
"src/import-dotx/import-dotx.ts"
], ],
"reporter": [ "reporter": [
"lcov", "lcov",

View File

@ -1,6 +1,6 @@
language: node_js language: node_js
node_js: node_js:
- 9 - 10
install: install:
- npm install - npm install
- npm install -g codecov - npm install -g codecov
@ -10,7 +10,7 @@ script:
- npm run style - npm run style
- npm run build - npm run build
- npm run ts-node -- ./demo/1-basic.ts - npm run ts-node -- ./demo/1-basic.ts
- npm run e2e "My Document.docx" # - npm run e2e "My Document.docx"
- npm run ts-node -- ./demo/2-declaritive-styles.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/3-numbering-and-bullet-points.ts
- npm run ts-node -- ./demo/4-basic-table.ts - npm run ts-node -- ./demo/4-basic-table.ts
@ -20,7 +20,7 @@ script:
- npm run ts-node -- ./demo/8-header-footer.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/9-images-in-header-and-footer.ts
- npm run ts-node -- ./demo/10-my-cv.ts - npm run ts-node -- ./demo/10-my-cv.ts
- npm run e2e "My Document.docx" # - npm run e2e "My Document.docx"
- npm run ts-node -- ./demo/11-declaritive-styles-2.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/12-scaling-images.ts
- npm run ts-node -- ./demo/13-xml-styles.ts - npm run ts-node -- ./demo/13-xml-styles.ts

View File

@ -11,6 +11,7 @@
[![NPM version][npm-image]][npm-url] [![NPM version][npm-image]][npm-url]
[![Downloads per month][downloads-image]][downloads-url] [![Downloads per month][downloads-image]][downloads-url]
[![Build Status][travis-image]][travis-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] [![Dependency Status][daviddm-image]][daviddm-url]
[![Known Vulnerabilities][snky-image]][snky-url] [![Known Vulnerabilities][snky-image]][snky-url]
[![Chat on Gitter][gitter-image]][gitter-url] [![Chat on Gitter][gitter-image]][gitter-url]
@ -27,13 +28,22 @@
Here are examples of `docx` being used with basic `HTML/JS` in a browser environment: Here are examples of `docx` being used with basic `HTML/JS` in a browser environment:
* https://codepen.io/anon/pen/dqoVgQ * https://codepen.io/dolanmiu/pen/RwNeObg
* https://jsfiddle.net/3xhezb5w/2 * https://jsfiddle.net/dolanmiu/kqxrj35u/1/
Here is an example of `docx` working in `Angular`: Here is an example of `docx` working in `Angular`:
* https://stackblitz.com/edit/angular-afvxtz * https://stackblitz.com/edit/angular-afvxtz
Here is an example of `docx` working in `React`:
* https://stackblitz.com/edit/react-ts-qq25sp
* https://stackblitz.com/edit/react-ts-qdqu7z (adding images to Word Document)
Here is an example of `docx` working in `Vue.js`:
* https://stackblitz.com/edit/vuejs-docx
## Node ## Node
Press `endpoint` on the `RunKit` website: Press `endpoint` on the `RunKit` website:
@ -50,7 +60,7 @@ Press `endpoint` on the `RunKit` website:
* https://runkit.com/dolanmiu/docx-demo8 - Header and Footer * https://runkit.com/dolanmiu/docx-demo8 - Header and Footer
* https://runkit.com/dolanmiu/docx-demo10 - **My CV generated with docx** * https://runkit.com/dolanmiu/docx-demo10 - **My CV generated with docx**
More [here](https://docx.js.org/#/examples) and [here](https://github.com/dolanmiu/docx/tree/master/demo) More [here](https://github.com/dolanmiu/docx/tree/master/demo)
# How to use & Documentation # How to use & Documentation
@ -58,7 +68,7 @@ Please refer to the [documentation at https://docx.js.org/](https://docx.js.org/
# Examples # Examples
Check the `examples` section in the [documentation](https://docx.js.org/#/examples) and the [demo folder](https://github.com/dolanmiu/docx/tree/master/demo) for examples. Check the [demo folder](https://github.com/dolanmiu/docx/tree/master/demo) for examples.
# Contributing # Contributing
@ -76,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://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://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/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! ...and many more!
@ -93,6 +104,8 @@ Made with 💖
[downloads-url]: https://npmjs.org/package/docx [downloads-url]: https://npmjs.org/package/docx
[travis-image]: https://travis-ci.org/dolanmiu/docx.svg?branch=master [travis-image]: https://travis-ci.org/dolanmiu/docx.svg?branch=master
[travis-url]: https://travis-ci.org/dolanmiu/docx [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-image]: https://david-dm.org/dolanmiu/docx.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/dolanmiu/docx [daviddm-url]: https://david-dm.org/dolanmiu/docx
[snky-image]: https://snyk.io/test/github/dolanmiu/docx/badge.svg [snky-image]: https://snyk.io/test/github/dolanmiu/docx/badge.svg

View File

@ -204,7 +204,10 @@ class DocumentCreator {
alignment: AlignmentType.CENTER, alignment: AlignmentType.CENTER,
children: [ children: [
new TextRun(`Mobile: ${phoneNumber} | LinkedIn: ${profileUrl} | Email: ${email}`), new TextRun(`Mobile: ${phoneNumber} | LinkedIn: ${profileUrl} | Email: ${email}`),
new TextRun("Address: 58 Elm Avenue, Kent ME4 6ER, UK").break(), new TextRun({
text: "Address: 58 Elm Avenue, Kent ME4 6ER, UK",
break: 1,
}),
], ],
}); });
} }

View File

@ -3,6 +3,7 @@
import * as fs from "fs"; import * as fs from "fs";
import { import {
AlignmentType, AlignmentType,
convertInchesToTwip,
Document, Document,
Footer, Footer,
HeadingLevel, HeadingLevel,
@ -18,13 +19,8 @@ import {
const doc = new Document({ const doc = new Document({
styles: { styles: {
paragraphStyles: [ default: {
{ heading1: {
id: "Heading1",
name: "Heading 1",
basedOn: "Normal",
next: "Normal",
quickFormat: true,
run: { run: {
font: "Calibri", font: "Calibri",
size: 52, size: 52,
@ -40,12 +36,7 @@ const doc = new Document({
spacing: { line: 340 }, spacing: { line: 340 },
}, },
}, },
{ heading2: {
id: "Heading2",
name: "Heading 2",
basedOn: "Normal",
next: "Normal",
quickFormat: true,
run: { run: {
font: "Calibri", font: "Calibri",
size: 26, size: 26,
@ -55,12 +46,7 @@ const doc = new Document({
spacing: { line: 340 }, spacing: { line: 340 },
}, },
}, },
{ heading3: {
id: "Heading3",
name: "Heading 3",
basedOn: "Normal",
next: "Normal",
quickFormat: true,
run: { run: {
font: "Calibri", font: "Calibri",
size: 26, size: 26,
@ -70,12 +56,7 @@ const doc = new Document({
spacing: { line: 276 }, spacing: { line: 276 },
}, },
}, },
{ heading4: {
id: "Heading4",
name: "Heading 4",
basedOn: "Normal",
next: "Normal",
quickFormat: true,
run: { run: {
font: "Calibri", font: "Calibri",
size: 26, size: 26,
@ -85,6 +66,8 @@ const doc = new Document({
alignment: AlignmentType.JUSTIFIED, alignment: AlignmentType.JUSTIFIED,
}, },
}, },
},
paragraphStyles: [
{ {
id: "normalPara", id: "normalPara",
name: "Normal Para", name: "Normal Para",
@ -128,7 +111,7 @@ const doc = new Document({
}, },
paragraph: { paragraph: {
spacing: { line: 276 }, spacing: { line: 276 },
indent: { left: 720 }, indent: { left: convertInchesToTwip(0.5) },
}, },
}, },
{ {
@ -139,12 +122,6 @@ const doc = new Document({
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 }, spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
}, },
}, },
{
id: "ListParagraph",
name: "List Paragraph",
basedOn: "Normal",
quickFormat: true,
},
], ],
}, },
}); });

View File

@ -1,20 +1,25 @@
// Example on how to customise the look at feel using Styles // Example on how to customise the look at feel using Styles
// Import from 'docx' rather than '../build' if you install from npm // Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs"; import * as fs from "fs";
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph, TextRun, UnderlineType } from "../build"; import {
AlignmentType,
convertInchesToTwip,
Document,
HeadingLevel,
LevelFormat,
Packer,
Paragraph,
TextRun,
UnderlineType,
} from "../build";
const doc = new Document({ const doc = new Document({
creator: "Clippy", creator: "Clippy",
title: "Sample Document", title: "Sample Document",
description: "A brief example of using docx", description: "A brief example of using docx",
styles: { styles: {
paragraphStyles: [ default: {
{ heading1: {
id: "Heading1",
name: "Heading 1",
basedOn: "Normal",
next: "Normal",
quickFormat: true,
run: { run: {
size: 28, size: 28,
bold: true, bold: true,
@ -27,12 +32,7 @@ const doc = new Document({
}, },
}, },
}, },
{ heading2: {
id: "Heading2",
name: "Heading 2",
basedOn: "Normal",
next: "Normal",
quickFormat: true,
run: { run: {
size: 26, size: 26,
bold: true, bold: true,
@ -48,6 +48,13 @@ const doc = new Document({
}, },
}, },
}, },
listParagraph: {
run: {
color: "#FF0000",
},
},
},
paragraphStyles: [
{ {
id: "aside", id: "aside",
name: "Aside", name: "Aside",
@ -59,7 +66,7 @@ const doc = new Document({
}, },
paragraph: { paragraph: {
indent: { indent: {
left: 720, left: convertInchesToTwip(0.5),
}, },
spacing: { spacing: {
line: 276, line: 276,
@ -75,12 +82,6 @@ const doc = new Document({
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 }, spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
}, },
}, },
{
id: "ListParagraph",
name: "List Paragraph",
basedOn: "Normal",
quickFormat: true,
},
], ],
}, },
numbering: { numbering: {
@ -90,7 +91,7 @@ const doc = new Document({
levels: [ levels: [
{ {
level: 0, level: 0,
format: "lowerLetter", format: LevelFormat.LOWER_LETTER,
text: "%1)", text: "%1)",
alignment: AlignmentType.LEFT, alignment: AlignmentType.LEFT,
}, },
@ -161,11 +162,26 @@ doc.addSection({
text: "and then underlined ", text: "and then underlined ",
underline: {}, underline: {},
}), }),
new TextRun({
text: "and then emphasis-mark ",
emphasisMark: {},
}),
new TextRun({ new TextRun({
text: "and back to normal.", text: "and back to normal.",
}), }),
], ],
}), }),
new Paragraph({
style: "Strong",
children: [
new TextRun({
text: "Strong Style",
}),
new TextRun({
text: " - Very strong.",
}),
],
}),
], ],
}); });

View File

@ -1,7 +1,7 @@
// Custom styles using JavaScript configuration // Custom styles using JavaScript configuration
// Import from 'docx' rather than '../build' if you install from npm // Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs"; import * as fs from "fs";
import { Document, HeadingLevel, Packer, Paragraph, UnderlineType } from "../build"; import { Document, convertInchesToTwip, HeadingLevel, Packer, Paragraph, UnderlineType } from "../build";
const doc = new Document({ const doc = new Document({
styles: { styles: {
@ -17,7 +17,7 @@ const doc = new Document({
}, },
paragraph: { paragraph: {
indent: { indent: {
left: 720, left: convertInchesToTwip(0.5),
}, },
spacing: { spacing: {
line: 276, line: 276,

View File

@ -1,7 +1,7 @@
// Numbered lists // Numbered lists
// Import from 'docx' rather than '../build' if you install from npm // Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs"; import * as fs from "fs";
import { AlignmentType, Document, Packer, Paragraph } from "../build"; import { AlignmentType, convertInchesToTwip, Document, LevelFormat, Packer, Paragraph } from "../build";
const doc = new Document({ const doc = new Document({
numbering: { numbering: {
@ -10,12 +10,12 @@ const doc = new Document({
levels: [ levels: [
{ {
level: 0, level: 0,
format: "upperRoman", format: LevelFormat.UPPER_ROMAN,
text: "%1", text: "%1",
alignment: AlignmentType.START, alignment: AlignmentType.START,
style: { style: {
paragraph: { paragraph: {
indent: { left: 720, hanging: 260 }, indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
}, },
}, },
}, },
@ -26,18 +26,34 @@ const doc = new Document({
levels: [ levels: [
{ {
level: 0, level: 0,
format: "decimal", format: LevelFormat.DECIMAL,
text: "%1", text: "%1",
alignment: AlignmentType.START, alignment: AlignmentType.START,
style: { style: {
paragraph: { paragraph: {
indent: { left: 720, hanging: 260 }, indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
}, },
}, },
}, },
], ],
reference: "my-number-numbering-reference", reference: "my-number-numbering-reference",
}, },
{
levels: [
{
level: 0,
format: LevelFormat.DECIMAL_ZERO,
text: "[%1]",
alignment: AlignmentType.START,
style: {
paragraph: {
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
},
},
},
],
reference: "padded-numbering-reference",
},
], ],
}, },
}); });
@ -109,6 +125,139 @@ doc.addSection({
level: 0, level: 0,
}, },
}), }),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "test",
numbering: {
reference: "padded-numbering-reference",
level: 0,
},
}),
], ],
}); });

View File

@ -1,7 +1,7 @@
// Numbering and bullet points example // Numbering and bullet points example
// Import from 'docx' rather than '../build' if you install from npm // Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs"; import * as fs from "fs";
import { AlignmentType, Document, Packer, Paragraph } from "../build"; import { AlignmentType, convertInchesToTwip, Document, LevelFormat, Packer, Paragraph } from "../build";
const doc = new Document({ const doc = new Document({
numbering: { numbering: {
@ -11,40 +11,40 @@ const doc = new Document({
levels: [ levels: [
{ {
level: 0, level: 0,
format: "upperRoman", format: LevelFormat.UPPER_ROMAN,
text: "%1", text: "%1",
alignment: AlignmentType.START, alignment: AlignmentType.START,
style: { style: {
paragraph: { paragraph: {
indent: { left: 720, hanging: 260 }, indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
}, },
}, },
}, },
{ {
level: 1, level: 1,
format: "decimal", format: LevelFormat.DECIMAL,
text: "%2.", text: "%2.",
alignment: AlignmentType.START, alignment: AlignmentType.START,
style: { style: {
paragraph: { paragraph: {
indent: { left: 1440, hanging: 980 }, indent: { left: convertInchesToTwip(1), hanging: convertInchesToTwip(0.68) },
}, },
}, },
}, },
{ {
level: 2, level: 2,
format: "lowerLetter", format: LevelFormat.LOWER_LETTER,
text: "%3)", text: "%3)",
alignment: AlignmentType.START, alignment: AlignmentType.START,
style: { style: {
paragraph: { paragraph: {
indent: { left: 2160, hanging: 1700 }, indent: { left: convertInchesToTwip(1.5), hanging: convertInchesToTwip(1.18) },
}, },
}, },
}, },
{ {
level: 3, level: 3,
format: "upperLetter", format: LevelFormat.UPPER_LETTER,
text: "%4)", text: "%4)",
alignment: AlignmentType.START, alignment: AlignmentType.START,
style: { style: {

View File

@ -1,7 +1,7 @@
// Example of how you would create a table and add data to it // Example of how you would create a table and add data to it
// Import from 'docx' rather than '../build' if you install from npm // Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs"; import * as fs from "fs";
import { Document, HeadingLevel, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign } from "../build"; import { Document, HeadingLevel, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign, TextDirection } from "../build";
const doc = new Document(); const doc = new Document();
@ -17,6 +17,14 @@ const table = new Table({
children: [new Paragraph({}), new Paragraph({})], children: [new Paragraph({}), new Paragraph({})],
verticalAlign: VerticalAlign.CENTER, verticalAlign: VerticalAlign.CENTER,
}), }),
new TableCell({
children: [new Paragraph({ text: "bottom to top" }), new Paragraph({})],
textDirection: TextDirection.BOTTOM_TO_TOP_LEFT_TO_RIGHT,
}),
new TableCell({
children: [new Paragraph({ text: "top to bottom" }), new Paragraph({})],
textDirection: TextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT,
}),
], ],
}), }),
new TableRow({ new TableRow({
@ -38,6 +46,22 @@ const table = new Table({
], ],
verticalAlign: VerticalAlign.CENTER, verticalAlign: VerticalAlign.CENTER,
}), }),
new TableCell({
children: [
new Paragraph({
text: "Text above should be vertical from bottom to top",
}),
],
verticalAlign: VerticalAlign.CENTER,
}),
new TableCell({
children: [
new Paragraph({
text: "Text above should be vertical from top to bottom",
}),
],
verticalAlign: VerticalAlign.CENTER,
}),
], ],
}), }),
], ],

View File

@ -2,7 +2,20 @@
// Also includes an example on how to center tables // Also includes an example on how to center tables
// Import from 'docx' rather than '../build' if you install from npm // Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs"; import * as fs from "fs";
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph, ShadingType, Table, TableCell, TableRow, WidthType } from "../build"; import {
AlignmentType,
BorderStyle,
convertInchesToTwip,
Document,
HeadingLevel,
Packer,
Paragraph,
ShadingType,
Table,
TableCell,
TableRow,
WidthType,
} from "../build";
const doc = new Document(); const doc = new Document();
@ -37,10 +50,10 @@ const table2 = new Table({
new TableCell({ new TableCell({
children: [new Paragraph("World")], children: [new Paragraph("World")],
margins: { margins: {
top: 1000, top: convertInchesToTwip(0.69),
bottom: 1000, bottom: convertInchesToTwip(0.69),
left: 1000, left: convertInchesToTwip(0.69),
right: 1000, right: convertInchesToTwip(0.69),
}, },
columnSpan: 3, columnSpan: 3,
}), }),
@ -64,7 +77,7 @@ const table2 = new Table({
size: 100, size: 100,
type: WidthType.AUTO, type: WidthType.AUTO,
}, },
columnWidths: [1000, 1000, 1000], columnWidths: [convertInchesToTwip(0.69), convertInchesToTwip(0.69), convertInchesToTwip(0.69)],
}); });
const table3 = new Table({ const table3 = new Table({
@ -119,14 +132,14 @@ const table3 = new Table({
}), }),
], ],
width: { width: {
size: 7000, size: convertInchesToTwip(4.86),
type: WidthType.DXA, type: WidthType.DXA,
}, },
margins: { margins: {
top: 400, top: convertInchesToTwip(0.27),
bottom: 400, bottom: convertInchesToTwip(0.27),
right: 400, right: convertInchesToTwip(0.27),
left: 400, left: convertInchesToTwip(0.27),
}, },
}); });
@ -184,7 +197,7 @@ const table5 = new Table({
new TableRow({ new TableRow({
children: [ children: [
new TableCell({ new TableCell({
children: [], children: [new Paragraph("1,0")],
}), }),
new TableCell({ new TableCell({
children: [new Paragraph("1,2")], children: [new Paragraph("1,2")],
@ -195,10 +208,10 @@ const table5 = new Table({
new TableRow({ new TableRow({
children: [ children: [
new TableCell({ new TableCell({
children: [], children: [new Paragraph("2,0")],
}), }),
new TableCell({ new TableCell({
children: [], children: [new Paragraph("2,1")],
}), }),
], ],
}), }),
@ -209,6 +222,161 @@ const table5 = new Table({
}, },
}); });
const borders = {
top: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "red",
},
bottom: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "red",
},
left: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "red",
},
right: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "red",
},
};
const table6 = new Table({
rows: [
new TableRow({
children: [
new TableCell({
borders,
children: [new Paragraph("0,0")],
rowSpan: 2,
}),
new TableCell({
borders,
children: [new Paragraph("0,1")],
}),
],
}),
new TableRow({
children: [
new TableCell({
borders,
children: [new Paragraph("1,1")],
rowSpan: 2,
}),
],
}),
new TableRow({
children: [
new TableCell({
borders,
children: [new Paragraph("2,0")],
}),
],
}),
],
width: {
size: 100,
type: WidthType.PERCENTAGE,
},
});
const table7 = new Table({
rows: [
new TableRow({
children: [
new TableCell({
children: [new Paragraph("0,0")],
}),
new TableCell({
children: [new Paragraph("0,1")],
}),
new TableCell({
children: [new Paragraph("0,2")],
rowSpan: 2,
}),
new TableCell({
children: [new Paragraph("0,3")],
rowSpan: 3,
}),
],
}),
new TableRow({
children: [
new TableCell({
children: [new Paragraph("1,0")],
columnSpan: 2,
}),
],
}),
new TableRow({
children: [
new TableCell({
children: [new Paragraph("2,0")],
columnSpan: 2,
}),
new TableCell({
children: [new Paragraph("2,2")],
rowSpan: 2,
}),
],
}),
new TableRow({
children: [
new TableCell({
children: [new Paragraph("3,0")],
}),
new TableCell({
children: [new Paragraph("3,1")],
}),
new TableCell({
children: [new Paragraph("3,3")],
}),
],
}),
],
width: {
size: 100,
type: WidthType.PERCENTAGE,
},
});
const table8 = new Table({
rows: [
new TableRow({
children: [
new TableCell({ children: [new Paragraph("1,1")] }),
new TableCell({ children: [new Paragraph("1,2")] }),
new TableCell({ children: [new Paragraph("1,3")] }),
new TableCell({ children: [new Paragraph("1,4")], rowSpan: 4, borders }),
],
}),
new TableRow({
children: [
new TableCell({ children: [new Paragraph("2,1")] }),
new TableCell({ children: [new Paragraph("2,2")] }),
new TableCell({ children: [new Paragraph("2,3")], rowSpan: 3 }),
],
}),
new TableRow({
children: [
new TableCell({ children: [new Paragraph("3,1")] }),
new TableCell({ children: [new Paragraph("3,2")], rowSpan: 2 }),
],
}),
new TableRow({
children: [new TableCell({ children: [new Paragraph("4,1")] })],
}),
],
width: {
size: 100,
type: WidthType.PERCENTAGE,
},
});
doc.addSection({ doc.addSection({
children: [ children: [
table, table,
@ -222,10 +390,16 @@ doc.addSection({
heading: HeadingLevel.HEADING_2, heading: HeadingLevel.HEADING_2,
}), }),
table3, table3,
new Paragraph("Merging columns"), new Paragraph("Merging columns 1"),
table4, table4,
new Paragraph("More Merging columns"), new Paragraph("Merging columns 2"),
table5, table5,
new Paragraph("Merging columns 3"),
table6,
new Paragraph("Merging columns 4"),
table7,
new Paragraph("Merging columns 5"),
table8,
], ],
}); });

View File

@ -1,7 +1,7 @@
// Example on how to add hyperlinks to websites // Example on how to add hyperlinks to websites
// Import from 'docx' rather than '../build' if you install from npm // Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs"; import * as fs from "fs";
import { Document, HyperlinkRef, HyperlinkType, Packer, Paragraph } from "../build"; import { Document, HyperlinkRef, HyperlinkType, Packer, Paragraph, Media } from "../build";
const doc = new Document({ const doc = new Document({
hyperlinks: { hyperlinks: {
@ -10,14 +10,24 @@ const doc = new Document({
text: "Hyperlink", text: "Hyperlink",
type: HyperlinkType.EXTERNAL, type: HyperlinkType.EXTERNAL,
}, },
myOtherLink: {
link: "http://www.google.com",
text: "Google Link",
type: HyperlinkType.EXTERNAL,
},
}, },
}); });
const image1 = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
doc.addSection({ doc.addSection({
children: [ children: [
new Paragraph({ new Paragraph({
children: [new HyperlinkRef("myCoolLink")], children: [new HyperlinkRef("myCoolLink")],
}), }),
new Paragraph({
children: [image1, new HyperlinkRef("myOtherLink")],
}),
], ],
}); });

View File

@ -28,6 +28,18 @@ doc.addSection({
}), }),
], ],
}), }),
new Paragraph({
shading: {
type: ShadingType.DIAGONAL_CROSS,
color: "00FFFF",
fill: "FF0000",
},
children: [
new TextRun({
text: "Hello World for entire paragraph",
}),
],
}),
], ],
}), }),
}, },

View File

@ -1,7 +1,19 @@
// Add custom borders to the table itself // Add custom borders and no-borders to the table itself
// Import from 'docx' rather than '../build' if you install from npm // Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs"; import * as fs from "fs";
import { BorderStyle, Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build"; import {
BorderStyle,
Document,
HeadingLevel,
Packer,
Paragraph,
Table,
TableBorders,
TableCell,
TableRow,
TextDirection,
VerticalAlign,
} from "../build";
const doc = new Document(); const doc = new Document();
@ -10,6 +22,28 @@ const table = new Table({
new TableRow({ new TableRow({
children: [ children: [
new TableCell({ new TableCell({
borders: {
top: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "red",
},
bottom: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "red",
},
left: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "red",
},
right: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "red",
},
},
children: [new Paragraph("Hello")], children: [new Paragraph("Hello")],
}), }),
new TableCell({ new TableCell({
@ -30,7 +64,103 @@ const table = new Table({
], ],
}); });
doc.addSection({ children: [table] }); // Using the no-border convenience object. It is the same as writing this manually:
// const borders = {
// top: {
// style: BorderStyle.NONE,
// size: 0,
// color: "auto",
// },
// bottom: {
// style: BorderStyle.NONE,
// size: 0,
// color: "auto",
// },
// left: {
// style: BorderStyle.NONE,
// size: 0,
// color: "auto",
// },
// right: {
// style: BorderStyle.NONE,
// size: 0,
// color: "auto",
// },
// insideHorizontal: {
// style: BorderStyle.NONE,
// size: 0,
// color: "auto",
// },
// insideVertical: {
// style: BorderStyle.NONE,
// size: 0,
// color: "auto",
// },
// };
const noBorderTable = new Table({
borders: TableBorders.NONE,
rows: [
new TableRow({
children: [
new TableCell({
children: [new Paragraph({}), new Paragraph({})],
verticalAlign: VerticalAlign.CENTER,
}),
new TableCell({
children: [new Paragraph({}), new Paragraph({})],
verticalAlign: VerticalAlign.CENTER,
}),
new TableCell({
children: [new Paragraph({ text: "bottom to top" }), new Paragraph({})],
textDirection: TextDirection.BOTTOM_TO_TOP_LEFT_TO_RIGHT,
}),
new TableCell({
children: [new Paragraph({ text: "top to bottom" }), new Paragraph({})],
textDirection: TextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT,
}),
],
}),
new TableRow({
children: [
new TableCell({
children: [
new Paragraph({
text:
"Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah",
heading: HeadingLevel.HEADING_1,
}),
],
}),
new TableCell({
children: [
new Paragraph({
text: "This text should be in the middle of the cell",
}),
],
verticalAlign: VerticalAlign.CENTER,
}),
new TableCell({
children: [
new Paragraph({
text: "Text above should be vertical from bottom to top",
}),
],
verticalAlign: VerticalAlign.CENTER,
}),
new TableCell({
children: [
new Paragraph({
text: "Text above should be vertical from top to bottom",
}),
],
verticalAlign: VerticalAlign.CENTER,
}),
],
}),
],
});
doc.addSection({ children: [table, new Paragraph("Hello"), noBorderTable] });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer); fs.writeFileSync("My Document.docx", buffer);

View File

@ -22,6 +22,7 @@ const image4 = Media.addImage(doc, fs.readFileSync("./demo/images/parrots.bmp"))
const image5 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif")); const image5 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
const image6 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 200, 200, { const image6 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 200, 200, {
floating: { floating: {
zIndex: 10,
horizontalPosition: { horizontalPosition: {
offset: 1014400, offset: 1014400,
}, },
@ -33,6 +34,7 @@ const image6 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 2
const image7 = Media.addImage(doc, fs.readFileSync("./demo/images/cat.jpg"), 200, 200, { const image7 = Media.addImage(doc, fs.readFileSync("./demo/images/cat.jpg"), 200, 200, {
floating: { floating: {
zIndex: 5,
horizontalPosition: { horizontalPosition: {
relative: HorizontalPositionRelativeFrom.PAGE, relative: HorizontalPositionRelativeFrom.PAGE,
align: HorizontalPositionAlign.RIGHT, align: HorizontalPositionAlign.RIGHT,

View File

@ -0,0 +1,57 @@
// Custom character styles using JavaScript configuration
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer, Paragraph, TextRun } from "../build";
const doc = new Document({
styles: {
characterStyles: [
{
id: "myRedStyle",
name: "My Wonky Style",
basedOn: "Normal",
run: {
color: "990000",
italics: true,
},
},
{
id: "strong",
name: "Strong",
basedOn: "Normal",
run: {
bold: true,
},
},
],
},
});
doc.addSection({
children: [
new Paragraph({
children: [
new TextRun({
text: "Foo bar",
style: "myRedStyle",
}),
],
}),
new Paragraph({
children: [
new TextRun({
text: "First Word",
style: "strong",
}),
new TextRun({
text:
" - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
}),
],
}),
],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});

37
demo/52-japanese.ts Normal file
View File

@ -0,0 +1,37 @@
// Japanese text - Need to use a Japanese font
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, HeadingLevel, Packer, Paragraph } from "../build";
const doc = new Document({
styles: {
paragraphStyles: [
{
id: "Normal",
name: "Normal",
basedOn: "Normal",
next: "Normal",
quickFormat: true,
run: {
font: "MS Gothic",
},
},
],
},
});
doc.addSection({
children: [
new Paragraph({
text: "KFCを食べるのが好き",
heading: HeadingLevel.HEADING_1,
}),
new Paragraph({
text: "こんにちは",
}),
],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});

55
demo/53-chinese.ts Normal file
View File

@ -0,0 +1,55 @@
// Chinese text - Chinese text need to use a Chinese font. And ascii text need to use a ascii font.
// Different from the `52-japanese.ts`.
// `52-japanese.ts` will set all characters to use Japanese font.
// `53-chinese.ts` will set Chinese characters to use Chinese font, and set ascii characters to use ascii font.
// Note that if the OS have not install `KaiTi` font, this demo doesn't work.
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, HeadingLevel, Packer, Paragraph, TextRun } from "../build";
const doc = new Document({
styles: {
paragraphStyles: [
{
id: "Normal",
name: "Normal",
basedOn: "Normal",
next: "Normal",
quickFormat: true,
run: {
font: {
ascii: "Times",
eastAsia: "KaiTi",
},
},
},
],
},
});
doc.addSection({
children: [
new Paragraph({
text: "中文和英文 Chinese and English",
heading: HeadingLevel.HEADING_1,
}),
new Paragraph({
text: "中文和英文 Chinese and English",
}),
new Paragraph({
children: [
new TextRun({
text: "中文和英文 Chinese and English",
font: { eastAsia: "SimSun" }, // set eastAsia to "SimSun".
// The ascii characters will use the default font ("Times") specified in paragraphStyles
}),
],
}),
],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});

146
demo/54-track-revisions.ts Normal file
View File

@ -0,0 +1,146 @@
// Track Revisions aka. "Track Changes"
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import {
AlignmentType,
DeletedTextRun,
Document,
Footer,
FootnoteReferenceRun,
InsertedTextRun,
Packer,
PageNumber,
Paragraph,
ShadingType,
TextRun,
} from "../build";
/*
For reference, see
- https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.insertedrun
- https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.deletedrun
The method `addTrackRevisions()` adds an element `<w:trackRevisions />` to the `settings.xml` file. This specifies that the application shall track *new* revisions made to the existing document.
See also https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.trackrevisions
Note that this setting enables to track *new changes* after teh file is generated, so this example will still show inserted and deleted text runs when you remove it.
*/
const doc = new Document({
footnotes: [
new Paragraph({
children: [
new TextRun("This is a footnote"),
new DeletedTextRun({
text: " with some extra text which was deleted",
id: 0,
author: "Firstname Lastname",
date: "2020-10-06T09:05:00Z",
}),
new InsertedTextRun({
text: " and new content",
id: 1,
author: "Firstname Lastname",
date: "2020-10-06T09:05:00Z",
}),
],
}),
],
features: {
trackRevisions: true,
},
});
const paragraph = new Paragraph({
children: [
new TextRun("This is a simple demo "),
new TextRun({
text: "on how to ",
}),
new InsertedTextRun({
text: "mark a text as an insertion ",
id: 0,
author: "Firstname Lastname",
date: "2020-10-06T09:00:00Z",
}),
new DeletedTextRun({
text: "or a deletion.",
id: 1,
author: "Firstname Lastname",
date: "2020-10-06T09:00:00Z",
}),
],
});
doc.addSection({
properties: {},
children: [
paragraph,
new Paragraph({
children: [
new TextRun("This is a demo "),
new DeletedTextRun({
break: 1,
text: "in order",
color: "red",
bold: true,
size: 24,
font: {
name: "Garamond",
},
shading: {
type: ShadingType.REVERSE_DIAGONAL_STRIPE,
color: "00FFFF",
fill: "FF0000",
},
id: 2,
author: "Firstname Lastname",
date: "2020-10-06T09:00:00Z",
}),
new InsertedTextRun({
text: "to show how to ",
bold: false,
id: 3,
author: "Firstname Lastname",
date: "2020-10-06T09:05:00Z",
}),
new TextRun({
bold: true,
children: ["\tuse Inserted and Deleted TextRuns.", new FootnoteReferenceRun(1)],
}),
],
}),
],
footers: {
default: new Footer({
children: [
new Paragraph({
alignment: AlignmentType.CENTER,
children: [
new TextRun("Awesome LLC"),
new TextRun({
children: ["Page Number: ", PageNumber.CURRENT],
}),
new DeletedTextRun({
children: [" to ", PageNumber.TOTAL_PAGES],
id: 4,
author: "Firstname Lastname",
date: "2020-10-06T09:05:00Z",
}),
new InsertedTextRun({
children: [" from ", PageNumber.TOTAL_PAGES],
bold: true,
id: 5,
author: "Firstname Lastname",
date: "2020-10-06T09:05:00Z",
}),
],
}),
],
}),
},
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});

294
demo/55-math.ts Normal file
View File

@ -0,0 +1,294 @@
// Simple example to add text to a document
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import {
Document,
Math,
MathAngledBrackets,
MathCurlyBrackets,
MathFraction,
MathFunction,
MathPreSubSuperScript,
MathRadical,
MathRoundBrackets,
MathRun,
MathSquareBrackets,
MathSubScript,
MathSubSuperScript,
MathSum,
MathSuperScript,
Packer,
Paragraph,
TextRun,
} from "../build";
const doc = new Document();
doc.addSection({
properties: {},
children: [
new Paragraph({
children: [
new Math({
children: [
new MathRun("2+2"),
new MathFraction({
numerator: [new MathRun("hi")],
denominator: [new MathRun("2")],
}),
],
}),
new TextRun({
text: "Foo Bar",
bold: true,
}),
],
}),
new Paragraph({
children: [
new Math({
children: [
new MathFraction({
numerator: [
new MathRun("1"),
new MathRadical({
children: [new MathRun("2")],
}),
],
denominator: [new MathRun("2")],
}),
],
}),
],
}),
new Paragraph({
children: [
new Math({
children: [
new MathSum({
children: [new MathRun("test")],
}),
new MathSum({
children: [
new MathSuperScript({
children: [new MathRun("e")],
superScript: [new MathRun("2")],
}),
],
subScript: [new MathRun("i")],
}),
new MathSum({
children: [
new MathRadical({
children: [new MathRun("i")],
}),
],
subScript: [new MathRun("i")],
superScript: [new MathRun("10")],
}),
],
}),
],
}),
new Paragraph({
children: [
new Math({
children: [
new MathSuperScript({
children: [new MathRun("test")],
superScript: [new MathRun("hello")],
}),
],
}),
],
}),
new Paragraph({
children: [
new Math({
children: [
new MathSubScript({
children: [new MathRun("test")],
subScript: [new MathRun("hello")],
}),
],
}),
],
}),
new Paragraph({
children: [
new Math({
children: [
new MathSubScript({
children: [new MathRun("x")],
subScript: [
new MathSuperScript({
children: [new MathRun("y")],
superScript: [new MathRun("2")],
}),
],
}),
],
}),
],
}),
new Paragraph({
children: [
new Math({
children: [
new MathSubSuperScript({
children: [new MathRun("test")],
superScript: [new MathRun("hello")],
subScript: [new MathRun("world")],
}),
],
}),
],
}),
new Paragraph({
children: [
new Math({
children: [
new MathPreSubSuperScript({
children: [new MathRun("test")],
superScript: [new MathRun("hello")],
subScript: [new MathRun("world")],
}),
],
}),
],
}),
new Paragraph({
children: [
new Math({
children: [
new MathSubScript({
children: [
new MathFraction({
numerator: [new MathRun("1")],
denominator: [new MathRun("2")],
}),
],
subScript: [new MathRun("4")],
}),
],
}),
],
}),
new Paragraph({
children: [
new Math({
children: [
new MathSubScript({
children: [
new MathRadical({
children: [
new MathFraction({
numerator: [new MathRun("1")],
denominator: [new MathRun("2")],
}),
],
degree: [new MathRun("4")],
}),
],
subScript: [new MathRun("x")],
}),
],
}),
],
}),
new Paragraph({
children: [
new Math({
children: [
new MathRadical({
children: [new MathRun("4")],
}),
],
}),
],
}),
new Paragraph({
children: [
new Math({
children: [
new MathFunction({
name: [
new MathSuperScript({
children: [new MathRun("cos")],
superScript: [new MathRun("-1")],
}),
],
children: [new MathRun("100")],
}),
new MathRun("×"),
new MathFunction({
name: [new MathRun("sin")],
children: [new MathRun("360")],
}),
new MathRun("= x"),
],
}),
],
}),
new Paragraph({
children: [
new Math({
children: [
new MathRoundBrackets({
children: [
new MathFraction({
numerator: [new MathRun("1")],
denominator: [new MathRun("2")],
}),
],
}),
new MathSquareBrackets({
children: [
new MathFraction({
numerator: [new MathRun("1")],
denominator: [new MathRun("2")],
}),
],
}),
new MathCurlyBrackets({
children: [
new MathFraction({
numerator: [new MathRun("1")],
denominator: [new MathRun("2")],
}),
],
}),
new MathAngledBrackets({
children: [
new MathFraction({
numerator: [new MathRun("1")],
denominator: [new MathRun("2")],
}),
],
}),
],
}),
],
}),
new Paragraph({
children: [
new Math({
children: [
new MathFraction({
numerator: [
new MathRadical({
children: [new MathRun("4")],
}),
],
denominator: [new MathRun("2a")],
}),
],
}),
],
}),
],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});

View File

@ -0,0 +1,33 @@
// Change background colour of whole document
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer, Paragraph, TextRun } from "../build";
const doc = new Document({
background: {
color: "C45911",
},
});
doc.addSection({
properties: {},
children: [
new Paragraph({
children: [
new TextRun("Hello World"),
new TextRun({
text: "Foo Bar",
bold: true,
}),
new TextRun({
text: "\tGithub is the best",
bold: true,
}),
],
}),
],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});

View File

@ -0,0 +1,88 @@
// Numbered lists - Add parent number in sub number
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { AlignmentType, convertInchesToTwip, Document, HeadingLevel, LevelFormat, Packer, Paragraph } from "../build";
const doc = new Document({
numbering: {
config: [
{
levels: [
{
level: 0,
format: LevelFormat.DECIMAL,
text: "%1",
alignment: AlignmentType.START,
style: {
paragraph: {
indent: { left: convertInchesToTwip(0.5), hanging: 260 },
},
},
},
{
level: 1,
format: LevelFormat.DECIMAL,
text: "%1.%2",
alignment: AlignmentType.START,
style: {
paragraph: {
indent: { left: 1.25 * convertInchesToTwip(0.5), hanging: 1.25 * 260 },
},
run: {
bold: true,
size: 18,
font: "Times New Roman",
},
},
},
],
reference: "my-number-numbering-reference",
},
],
},
});
doc.addSection({
children: [
new Paragraph({
text: "How to make cake",
heading: HeadingLevel.HEADING_1,
}),
new Paragraph({
text: "Step 1 - Add sugar",
numbering: {
reference: "my-number-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "Step 2 - Add wheat",
numbering: {
reference: "my-number-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "Step 2a - Stir the wheat in a circle",
numbering: {
reference: "my-number-numbering-reference",
level: 1,
},
}),
new Paragraph({
text: "Step 3 - Put in oven",
numbering: {
reference: "my-number-numbering-reference",
level: 0,
},
}),
new Paragraph({
text: "How to make cake",
heading: HeadingLevel.HEADING_1,
}),
],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});

View File

@ -1,13 +1,3 @@
<p align="center">
<img alt="clippy the assistant" src="https://i.imgur.com/37uBGhO.gif">
</p>
<p align="center">
Easily generate .docx files with JS/TS. Works for Node and on the Browser. :100:
</p>
---
# Welcome # Welcome
## Installation ## Installation
@ -63,17 +53,11 @@ Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer); fs.writeFileSync("My Document.docx", buffer);
}); });
// Done! A file called 'My First Document.docx' will be in your file system. // Done! A file called 'My Document.docx' will be in your file system.
``` ```
## Honoured Mentions
[@felipeochoa](https://github.com/felipeochoa)
[@h4buli](https://github.com/h4buli)
<p align="center"> <p align="center">
<img alt="clippy the assistant" src="http://i60.tinypic.com/339pvtt.png"> <img alt="clippy the assistant" src="./clippy.png">
</p> </p>
--- ---

10
docs/_coverpage.md Normal file
View File

@ -0,0 +1,10 @@
<img src="https://i.imgur.com/37uBGhO.gif" alt="drawing" style="width:200px;"/>
> Easily generate .docx files with JS/TS. Works for Node and on the Browser. :100:
- Simple, declarative API
- 50+ usage examples
- Battle tested, mature, 95%+ coverage
[GitHub](https://github.com/dolanmiu/docx)
[Get Started](#Welcome)

View File

@ -1,6 +1,6 @@
* [Getting Started](/) * [Getting Started](/)
* [Examples](examples.md) * [Examples](https://github.com/dolanmiu/docx/tree/master/demo)
* API * API
@ -20,12 +20,16 @@
* [Tab Stops](usage/tab-stops.md) * [Tab Stops](usage/tab-stops.md)
* [Table of Contents](usage/table-of-contents.md) * [Table of Contents](usage/table-of-contents.md)
* [Page Numbers](usage/page-numbers.md) * [Page Numbers](usage/page-numbers.md)
* [Change Tracking](usage/change-tracking.md)
* [Math](usage/math.md)
* Styling * Styling
* [Styling with JS](usage/styling-with-js.md) * [Styling with JS](usage/styling-with-js.md)
* [Styling with XML](usage/styling-with-xml.md) * [Styling with XML](usage/styling-with-xml.md)
* Exporting * Exporting
* [Packers](usage/packers.md) * [Packers](usage/packers.md)
* Utility
* [Convenience functions](usage/convenience-functions.md)
* [Contribution Guidelines](contribution-guidelines.md) * [Contribution Guidelines](contribution-guidelines.md)

BIN
docs/clippy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
docs/clippy.psd Normal file

Binary file not shown.

View File

@ -1,25 +1,23 @@
# Contribution Guidelines # Contribution Guidelines
* Include documentation reference(s) at the top of each file: - Include documentation reference(s) at the top of each file:
```ts ```ts
// http://officeopenxml.com/WPdocument.php // http://officeopenxml.com/WPdocument.php
``` ```
* Follow Prettier standards, and consider using the [Prettier VSCode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) plugin. - Follow Prettier standards, and consider using the [Prettier VSCode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) plugin.
* Follow the `TSLint` rules - Follow the `TSLint` rules
## Always think about the user ## Always think about the user
The number one pillar for contribution to `docx` is to **ALWAYS** think about how the user will use `docx`.
Put yourself in their position, and imagine how they would feel about your feature you wrote. Put yourself in their position, and imagine how they would feel about your feature you wrote.
1. Is it easy to use? 1. Is it easy to use?
2. Has it been documented well? 2. Has it been documented well?
3. Is it intuitive? 3. Is it intuitive?
4. Is it consistent with the rest of the API? 4. Is it declarative?
5. Is it fun to use? 5. Is it fun to use?
## Good Commit Names ## Good Commit Names
@ -27,6 +25,7 @@ Put yourself in their position, and imagine how they would feel about your featu
Please write good commit messages when making a commit: https://chris.beams.io/posts/git-commit/ Please write good commit messages when making a commit: https://chris.beams.io/posts/git-commit/
**Do not:** **Do not:**
``` ```
c // What? c // What?
rtl // Adding acryonyms without explaining anything else is not helpful rtl // Adding acryonyms without explaining anything else is not helpful
@ -35,34 +34,6 @@ demo updated // Getting better, but capitalize the first letter
Unesesary coment removed // Make sure to use correct spelling Unesesary coment removed // Make sure to use correct spelling
``` ```
## No leaky components in API interface
> This mainly applies to the API the end user will consume.
Try to make method parameters of the outside API accept primitives, or `json` objects, so that child components are created **inside** the component, rather than being **injected** in.
This is so that:
1. Imports are much cleaner for the end user, no need for:
```ts
import { ChildComponent } from "./my-feature/sub-component/deeper/.../my-deep.component";
```
2. This is what I consider "leakage". The code is aware of the underlying implementation of the component.
3. It means the end user does not need to import and create the child component to be injected.
**Do not**
`TableFloatProperties` is a class. The outside world would have to `new` up the object, and inject it in like so:
```ts
public float(tableFloatProperties: TableFloatProperties): Table
```
```ts
table.float(new TableFloatProperties(...));
```
**Do** **Do**
`ITableFloatOptions` is an interface for a JSON of primitives. The end user would need to pass in a json object and not need to worry about the internals: `ITableFloatOptions` is an interface for a JSON of primitives. The end user would need to pass in a json object and not need to worry about the internals:
@ -71,31 +42,29 @@ This is so that:
public float(tableFloatOptions: ITableFloatOptions): Table public float(tableFloatOptions: ITableFloatOptions): Table
``` ```
## Delcariative API
Make sure the API is declarative, so no _method calling_ or _mutation_. This is a design decision, consistent with the rest of the project. There are benefits to delcariative code over other styles of code, explained here: https://dzone.com/articles/why-declarative-coding-makes-you-a-better-programm
**Do not:**
```ts ```ts
table.float({...}); const paragraph = doc.createParagraph();
const text = paragraph.createText();
text.contents = "Hello World";
``` ```
## Add vs Create **Do**
This is just a guideline, and the rules can sometimes be broken. ```ts
doc.addSection({
* Use `create` if the method `new`'s up an element inside: children: [
new Paragraph({
```ts children: [new TextRun("Hello World")],
public createParagraph() { }),
const paragraph = new Paragraph(); ],
this.root.push(paragraph); });
} ```
```
* Use `add` if you add the element into the method as a parameter.
*Note:* This may look like its breaking the previous guideline, but it has semantically different meanings. The previous one is using data to construct an object, whereas this one is simply adding elements into the document:
```ts
public add(paragraph: Paragraph) {
this.root.push(paragraph);
}
```
## Getters and Setters ## Getters and Setters
@ -107,7 +76,7 @@ public get Level() {
} }
``` ```
There is no performance advantage by doing this. It means we don't need to prefix all private variables with the ugly `_`: This is the convention of this project. There is no performance advantage by doing this. It means we don't need to prefix all private variables with `_`:
**Do not:** **Do not:**
@ -121,30 +90,6 @@ private get _level: string;
private get level: string; private get level: string;
``` ```
## Temporal Methods
Some methods are `non-temporal`, which means regardless of when you call the method, it will have the same affect on the document. For example, setting the width of a table at the end of the document will have the same effect as setting the width at the start:
```ts
table.setWidth(1000); // now removed as of version 5.0.0
```
Whereas some methods are `temporal`, which means depending on the time-frame they are called, it would produce a difference result. For example, moving `createParagraph()` around your code will physically alter the document.
```ts
doc.createParagraph("hello");
```
If a method is `non-temporal`, put it in the objects `constructor`. For example:
```ts
const table = new Table(width: number);
```
`Non-temporal` methods are usually methods which can only be used one time and one time only. For example, `.float()`. It does not make sense to call `.float()` again if its already floating.
I am not sure what the real term is, but this will do.
## Interfaces over type alias ## Interfaces over type alias
Do not use `type`, but rather use `Interfaces`. `type` cannot be extended, and a class cannot implement it. Do not use `type`, but rather use `Interfaces`. `type` cannot be extended, and a class cannot implement it.
@ -152,14 +97,14 @@ Do not use `type`, but rather use `Interfaces`. `type` cannot be extended, and a
> "In general, use what you want ( type alias / interface ) just be consistent" > "In general, use what you want ( type alias / interface ) just be consistent"
> "always use interface for public API's definition when authoring a library or 3rd party ambient type definitions" > "always use interface for public API's definition when authoring a library or 3rd party ambient type definitions"
> >
> * https://medium.com/@martin_hotell/interface-vs-type-alias-in-typescript-2-7-2a8f1777af4c > - https://medium.com/@martin_hotell/interface-vs-type-alias-in-typescript-2-7-2a8f1777af4c
`Interface` is generally preferred over `type`: https://stackoverflow.com/questions/37233735/typescript-interfaces-vs-types `Interface` is generally preferred over `type`: https://stackoverflow.com/questions/37233735/typescript-interfaces-vs-types
**Do not:** **Do not:**
```ts ```ts
type RelationshipFileInfo = { id: number, target: string }; type RelationshipFileInfo = { id: number; target: string };
``` ```
**Do:** **Do:**
@ -193,26 +138,26 @@ enum WeaponType = {
## Spell correctly, in full and in American English ## Spell correctly, in full and in American English
I am not sure where these habits in software development come from, but I do not believe it is beneficial:
**Do not:** **Do not:**
```ts ```ts
readdy // misspelling readdy; // misspelling
perm // abbreviation perm; // abbreviation
conf // abbreviation conf; // abbreviation
cnty // abbreviation cnty; // abbreviation
relationFile // abbreviation relationFile; // abbreviation
colour // U.K. English colour; // U.K. English
``` ```
**Do:** **Do:**
```ts ```ts
ready ready;
permission permission;
config config;
country country;
relationshipFile relationshipFile;
color color;
``` ```
## Keep files small (within reason) ## Keep files small (within reason)

View File

@ -1,219 +0,0 @@
# Examples
> All examples can run independently and can be found in the `/demo` folder of the project
All the examples below can be ran locally, to do so, run the following command:
```sh
npm run demo
```
This command will run the `demo selector app` in the `/demo` folder. It will prompt you to select a demo number, which will run a demo from that folder.
## Simple
A simple hello world of the `docx` library:
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo1.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo1.ts_
## Styles
### Styling with JS
This example shows how to customise the look and feel of a document using JS configuration
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo2.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo2.ts_
### Styling with XML
This example shows how to customise the look and feel of a document using XML configuration
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo13.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo13.ts_
## Numbering
This example shows many levels of numbering
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo3.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo3.ts_
## Table
Example of simple table
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo4.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo4.ts_
### Styling table borders
Styling the borders of a table
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo20.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo20.ts_
## Images
### Add image to the document
Importing Images from file system path
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo5.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo5.ts_
### Add images to header and footer
Example showing how to add image to headers and footers
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo9.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo9.ts_
### Scaling images
Example showing how to scale images
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo12.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo12.ts_
### Add Image to media before adding to document
This is the best way to add an image to a document because you can add the same image in two locations without increasing document size by re-using the same image
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo23.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo23.ts_
### Add image to table
As before, to add an image to a table, you would need to add it to the `Media` object first
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo24.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo24.ts_
### Images using Base64 URI
If you want to use a Base64 image instead
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo18.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo18.ts_
## Margins
Example showing how to set custom margins
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo6.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo6.ts_
## Orientation
Example showing how to set the document to `landscape` or `portrait`
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo7.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo7.ts_
## Headers & Footers
Example showing how to add headers and footers
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo8.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo8.ts_
## Multiple headers and footers
Check out `Sections` for this feature
## Page Breaks
### Normal page breaks
Example showing how to page break
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo14.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo14.ts_
### Page break before
Example showing how to page break before like in Word
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo15.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo15.ts_
## Sections
Example of how sections work. Sections allow multiple headers and footers, and `landscape`/`portrait` inside the same document.
Also you can have different page number formats and starts for different sections.
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo16.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo16.ts_
## Footnotes
Example of how to add footnotes. Good for references
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo17.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo17.ts_
## Packers
## Buffer output
Example showing how to use the Buffer packer and then write that buffer to the file system
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo19.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo19.ts_
## Bookmarks
Example showing how to make bookmarks to make internal hyperlinks within the document
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo21.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo21.ts_
## Bidirectional text
Example showing how to use bidirectional text for certain languages such as Hebrew
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo22.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo22.ts_
## Showcase
### My CV
Example showing how to add headers and footers
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo10.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo10.ts_
### Style and Images
This example shows how to customise the look and feel of a document and add images
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo11.ts ':include')
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo11.ts_

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -1,31 +1,36 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head>
<meta charset="UTF-8" />
<title>docx - Generate .docx documents with JavaScript</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="Generate .docx documents with JavaScript" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
<link
rel="stylesheet"
href="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/style.min.css"
title="docsify-darklight-theme"
type="text/css"
/>
</head>
<head> <body>
<meta charset="UTF-8"> <div id="app"></div>
<title>docx - Generate .docx documents with JavaScript</title> <script>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> window.$docsify = {
<meta name="description" content="Generate .docx documents with JavaScript"> name: "docx",
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> repo: "https://github.com/dolanmiu/docx",
<link rel="stylesheet" href="//unpkg.com/docsify/lib/themes/vue.css"> loadSidebar: true,
</head> subMaxLevel: 2,
search: "auto",
<body> coverpage: true,
<div id="app"></div> };
<script> </script>
window.$docsify = { <script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
name: 'docx', <script src="//unpkg.com/docsify/lib/plugins/emoji.min.js"></script>
repo: 'https://github.com/dolanmiu/docx', <script src="https://unpkg.com/docsify-copy-code@2"></script>
loadSidebar: true, <script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
subMaxLevel: 2, <script src="//unpkg.com/prismjs/components/prism-typescript.min.js"></script>
search: 'auto', <script src="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/index.min.js" type="text/javascript"></script>
} </body>
</script>
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
<script src="//unpkg.com/docsify/lib/plugins/emoji.min.js"></script>
<script src="https://unpkg.com/docsify-copy-code@2"></script>
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-typescript.min.js"></script>
</body>
</html> </html>

View File

@ -9,7 +9,7 @@ const text = new TextRun("Bullet points");
const paragraph = new Paragraph({ const paragraph = new Paragraph({
text: "Bullet points", text: "Bullet points",
bullet: { bullet: {
level: 0, // How deep you want the bullet to me level: 0, //How deep you want the bullet to be
}, },
}); });
``` ```

View File

@ -0,0 +1,61 @@
# Change Tracking
> Instead of adding a `TextRun` into a `Paragraph`, you can also add an `InsertedTextRun` or `DeletedTextRun` where you need to supply an `id`, `author` and `date` for the change.
```ts
import { Paragraph, TextRun, InsertedTextRun, DeletedTextRun } from "docx";
const paragraph = new Paragraph({
children: [
new TextRun("This is a simple demo "),
new TextRun({
text: "on how to "
}),
new InsertedTextRun({
text: "mark a text as an insertion ",
id: 0,
author: "Firstname Lastname",
date: "2020-10-06T09:00:00Z",
}),
new DeletedTextRun({
text: "or a deletion.",
id: 1,
author: "Firstname Lastname",
date: "2020-10-06T09:00:00Z",
})
],
});
```
Note that for a `InsertedTextRun` and `DeletedTextRun`, it is not possible to simply call it with only a text as in `new TextRun("some text")`, since the additonal fields for change tracking need to be provided. Similar to a normal `TextRun` you can add additional text properties.
```ts
import { Paragraph, TextRun, InsertedTextRun, DeletedTextRun } from "docx";
const paragraph = new Paragraph({
children: [
new TextRun("This is a simple demo"),
new DeletedTextRun({
text: "with a deletion.",
color: "red",
bold: true,
size: 24,
id: 0,
author: "Firstname Lastname",
date: "2020-10-06T09:00:00Z",
})
],
});
```
In addtion to marking text as inserted or deleted, change tracking can also be added via the document settings. This will enable new changes to be tracked as well.
```ts
import { Document } from "docx";
const doc = new Document({
features: {
trackRevisions: true,
},
});
```

View File

@ -0,0 +1,22 @@
# Convenience functions
OOXML and this library mainly uses a unit called twentieths of a point or `twip` for short. a twip is a typographical measurement, defined as 1/20 of a typographical point. One twip is 1/1440 inch, or 17.64 μm. This unit is not intuitive for many users, so some functions were created to help
More info here: https://en.wikipedia.org/wiki/Twip
## Convert Inches to Twip
```ts
import { convertInchesToTwip } from "docx";
const twip = convertInchesToTwip(1); // returns 1440
const twip = convertInchesToTwip(0.5); // returns 720
```
## Convert Millimeters to Twip
```ts
import { convertMillimetersToTwip } from "docx";
const twip = convertMillimetersToTwip(50); // returns 2834
```

View File

@ -30,6 +30,24 @@ const doc = new docx.Document({
* keywords * keywords
* lastModifiedBy * lastModifiedBy
* revision * revision
* externalStyles
* styles
* numbering
* footnotes
* hyperlinks
* background
### Change background color of Document
Set the hex value in the document like so:
```ts
const doc = new docx.Document({
background: {
color: "C45911",
},
});
```
You can mix and match whatever properties you want, or provide no properties. You can mix and match whatever properties you want, or provide no properties.

View File

@ -125,6 +125,7 @@ Full options you can pass into `floating` are:
| lockAnchor | `boolean` | Optional | | lockAnchor | `boolean` | Optional |
| behindDocument | `boolean` | Optional | | behindDocument | `boolean` | Optional |
| layoutInCell | `boolean` | Optional | | layoutInCell | `boolean` | Optional |
| zIndex | `number` | Optional |
`HorizontalPositionOptions` are: `HorizontalPositionOptions` are:

265
docs/usage/math.md Normal file
View File

@ -0,0 +1,265 @@
# Math
!> Math requires an understanding of [Sections](usage/sections.md) and [Paragraphs](usage/paragraph.md).
## Intro
1. To add math, create a `Math` object
2. Add `MathComponents` inside `Math`
3. `MathComponents` can have nested `MathComponents` inside. e.g. A fraction where the numerator is a square root, and the demoninator as another fraction. More on `MathComponents` below
4. Make sure to add the `Math` object inside a `Paragraph`
## Example
```ts
new Math({
children: [
new MathRun("2+2"),
new MathFraction({
numerator: [new MathRun("hi")],
denominator: [new MathRun("2")],
}),
],
}),
```
This will produce:
<p align="center">
<img alt="clippy the assistant" src="images/math-example.png" width="200">
</p>
## Math Components
`MathComponents` are the unit sized building blocks of an equation in `docx`. A `MathComponent` takes in more nested `MathComponents` until you reach `MathRun`, which has no children. `MathRun` is similar to a [TextRun](usage/text.md).
### Math Run
`MathRun` is the most basic `MathComponent`.
#### Example
```ts
new MathRun("2+2");
```
```ts
new MathRun("hello");
```
An example of it being used inside `Math`:
```ts
new Math({
children: [
new MathRun("2"),
new MathRun("+"),
new MathRun("2"),
],
}),
```
### Math Fraction
`MathFractions` require a `numerator` and a `demoninator`, which are both a list of `MathComponents`
#### Example
```ts
new MathFraction({
numerator: [new MathRun("1")],
denominator: [new MathRun("2")],
}),
```
```ts
new MathFraction({
numerator: [
new MathRun("1"),
new MathRadical({
children: [new MathRun("2")],
}),
],
denominator: [new MathRun("2")],
}),
```
An example of it being used inside `Math`:
```ts
new Math({
children: [
new MathFraction({
numerator: [new MathRun("1")],
denominator: [new MathRun("2")],
}),
new MathText("+"),
new MathFraction({
numerator: [new MathRun("1")],
denominator: [new MathRun("2")],
}),
new MathText("= 1"),
],
}),
```
### Sum
A `MathComponent` for `Σ`. It can take a `superScript` and/or `subScript` as arguments to add `MathComponents` (usually limits) on the top and bottom
```ts
new MathSum({
children: [new MathRun("i")],
}),
```
```ts
new MathSum({
children: [
new MathSuperScript({
children: [new MathRun("e")],
superScript: [new MathRun("2")],
})
],
subScript: [new MathRun("i")],
superScript: [new MathRun("10")],
}),
```
### Radicals
A `MathComponent` for the `√` symbol. Examples include, square root, cube root etc. There is an optional `degree` parameter to specify the number of times the radicand is multiplied by itself. For example, `3` for cube root.
```ts
new MathRadical({
children: [new MathRun("2")],
}),
```
Cube root example:
```ts
new MathRadical({
children: [
new MathFraction({
numerator: [new MathRun("1")],
denominator: [new MathRun("2")],
}),
new MathRun('+ 1'),
],
degree: [new MathRun("3")],
}),
```
### Super Script
`MathSuperScripts` are the little numbers written to the top right of numbers or variables. It means the exponent or power if written by itself with the number or variable.
```ts
new MathSuperScript({
children: [new MathRun("x")],
superScript: [new MathRun("2")],
}),
```
An example with cosine:
```ts
new MathSuperScript({
children: [new MathRun("cos")],
superScript: [new MathRun("-1")],
}),
```
### Sub Script
`MathSubScripts` are similar to `MathSuperScripts`, except the little number is written below.
```ts
new MathSubScript({
children: [new MathRun("F")],
subScript: [new MathRun("n-1")],
}),
```
### Sub-Super Script
`MathSubSuperScripts` are a combination of both `MathSuperScript` and `MathSubScript`.
```ts
new MathSubSuperScript({
children: [new MathRun("test")],
superScript: [new MathRun("hello")],
subScript: [new MathRun("world")],
}),
```
### Function
`MathFunctions` are a way of describing what happens to an input variable, in order to get the output result. It takes a `name` parameter to specify the name of the function.
```ts
new MathFunction({
name: [
new MathSuperScript({
children: [new MathRun("cos")],
superScript: [new MathRun("-1")],
}),
],
children: [new MathRun("100")],
}),
```
### Brackets
#### Square brackets
```ts
new MathSquareBrackets({
children: [
new MathFraction({
numerator: [new MathRun("1")],
denominator: [new MathRun("2")],
}),
],
}),
```
#### Round brackets
```ts
new MathRoundBrackets({
children: [
new MathFraction({
numerator: [new MathRun("1")],
denominator: [new MathRun("2")],
}),
],
}),
```
#### Curly brackets
```ts
new MathCurlyBrackets({
children: [
new MathFraction({
numerator: [new MathRun("1")],
denominator: [new MathRun("2")],
}),
],
}),
```
#### Angled brackets
```ts
new MathAngledBrackets({
children: [
new MathFraction({
numerator: [new MathRun("1")],
denominator: [new MathRun("2")],
}),
],
}),
```

View File

@ -2,11 +2,7 @@
> Packers are the way in which `docx` turns your code into `.docx` format. It is completely decoupled from the `docx.Document`. > Packers are the way in which `docx` turns your code into `.docx` format. It is completely decoupled from the `docx.Document`.
Packers in `version 4` and above are now one single `Packer`. It works in both a node and browser environment (Angular etc). Now, the packer returns a `Buffer`, `Blob` or `base64 string`. It is up to you to take that and persist it with node's `fs`, send it down as a downloadable file, or anything else you wish. As of version 4, this library will not have options to export to PDF. Packers works in both a node and browser environment (Angular etc). Now, the packer returns a `Buffer`, `Blob` or `base64 string`. It is up to you to take that and persist it with node's `fs`, send it down as a downloadable file, or anything else you wish. As of `version 4+`, this library will not have options to export to PDF.
## Version 5
Packers in `version 5` and above are now static methods on `Packer`.
### Export as Buffer ### Export as Buffer
@ -36,117 +32,3 @@ Packer.toBlob(doc).then((blob) => {
saveAs(blob, "example.docx"); saveAs(blob, "example.docx");
}); });
``` ```
## Version 4
The `Packer` in `version 4` requires an instance of `Packer`, so be sure to `new` it.
### Export as Buffer
This will return a NodeJS `Buffer`. If this is used in the browser, it will return a `UInt8Array` instead.
```ts
const packer = new docx.Packer();
packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});
```
### Export as a `base64` string
```ts
const packer = new docx.Packer();
packer.toBase64String(doc).then((string) => {
console.log(string);
});
```
### Export as Blob
This is useful if you want to send it as an downloadable in a browser environment.
```ts
const packer = new docx.Packer();
packer.toBlob(doc).then((blob) => {
// saveAs from FileSaver will download the file
saveAs(blob, "example.docx");
});
```
## Version 3 and below
### File System Packer
```ts
const docx = require("docx");
const doc = new docx.Document();
const exporter = new docx.LocalPacker(doc);
exporter.pack("My Document");
// Word Document is in file system
```
### Buffer Packer
```ts
const docx = require("docx");
const doc = new docx.Document();
const exporter = new docx.BufferPacker(doc);
const buffer = exporter.pack();
```
### Stream Packer
Creates a `node` `Readable` stream
```ts
const docx = require("docx");
const doc = new docx.Document();
const exporter = new docx.StreamPacker(doc);
const stream = exporter.pack();
```
### Express Packer
The old express packer is now deprecated and may disappear soon, so you should upgrade.
The reason for this is because it means this project needs to know about and use `express`, which for a Word document generator, does not sound right. Seperation of concerns.
It will still be usable (for now), but it is ill advised.
I used the express exporter in my [website](http://www.dolan.bio).
The recommended way is to use the `StreamPacker` and handle the `express` magic outside of the library:
```ts
const docx = require("docx");
const doc = new docx.Document();
const exporter = new docx.StreamPacker(doc);
const stream = exporter.pack();
// Express' response object
res.attachment("yourfile.xlsx");
stream.pipe(res);
```
where `res` is the response object obtained through the Express router. It is that simple. The file will begin downloading in the browser.
### PDF Exporting
You can export your word document as a PDF file like so:
```ts
const exporter = new docx.LocalPacker(doc);
exporter.packPdf("My Document");
// Express
const exporter = new docx.ExpressPacker(doc, res);
exporter.packPdf("My Document");
```

View File

@ -142,6 +142,21 @@ const paragraph = new Paragraph({
}); });
``` ```
## Shading
Add color to an entire paragraph block
```ts
const paragraph = new Paragraph({
text: "shading",
shading: {
type: ShadingType.REVERSE_DIAGONAL_STRIPE,
color: "00FFFF",
fill: "FF0000",
},
});
```
## Spacing ## Spacing
Adding spacing between paragraphs Adding spacing between paragraphs

View File

@ -22,10 +22,11 @@ const name = new TextRun({
### Run formatting ### Run formatting
- `bold`, `italics`, `smallCaps`, `allCaps`, `strike`, `doubleStrike`, `subScript`, `superScript`: Set the formatting property to true - `bold`, `italics`, `smallCaps`, `allCaps`, `strike`, `doubleStrike`, `subScript`, `superScript`: Set the formatting property to true
- `underline(style="single", color=null)`: Set the underline style and color - `underline({type="single", color=null})`: Set the underline style and color
- `emphasisMark({type="dot"})`: Set the emphasis mark style
- `color(color)`: Set the text color, using 6 hex characters for RRGGBB (no leading `#`) - `color(color)`: Set the text color, using 6 hex characters for RRGGBB (no leading `#`)
- `size(halfPts)`: Set the font size, measured in half-points - `size(halfPts)`: Set the font size, measured in half-points
- `font(name)`: Set the run's font - `font(name)` or `font({ascii, cs, eastAsia, hAnsi, hint})`: Set the run's font
- `style(name)`: Apply a named run style - `style(name)`: Apply a named run style
- `characterSpacing(value)`: Set the character spacing adjustment (in TWIPs) - `characterSpacing(value)`: Set the character spacing adjustment (in TWIPs)

View File

@ -51,19 +51,6 @@ const table = new Table({
}); });
``` ```
### Pagination
#### Prevent row pagination
To prevent breaking contents of a row across multiple pages, call `cantSplit`:
```ts
const table = new Table({
rows: [],
cantSplit: true,
});
```
## Table Row ## Table Row
A table consists of multiple `table rows`. Table rows have a list of `children` which accepts a list of `table cells` explained below. You can create a simple `table row` like so: A table consists of multiple `table rows`. Table rows have a list of `children` which accepts a list of `table cells` explained below. You can create a simple `table row` like so:
@ -103,7 +90,7 @@ Here is a list of options you can add to the `table row`:
| children | `Array<TableCell>` | Required | | children | `Array<TableCell>` | Required |
| cantSplit | `boolean` | Optional | | cantSplit | `boolean` | Optional |
| tableHeader | `boolean` | Optional | | tableHeader | `boolean` | Optional |
| height | `{ value: number, rule: HeightRule }` | Optional | | height | `{ height: number, rule: HeightRule }` | Optional |
### Repeat row ### Repeat row
@ -116,6 +103,19 @@ const row = new TableRow({
}); });
``` ```
### Pagination
#### Prevent row pagination
To prevent breaking contents of a row across multiple pages, call `cantSplit`:
```ts
const row = new Row({
...,
cantSplit: true,
});
```
## Table Cells ## Table Cells
Cells need to be added in the `table row`, you can create a table cell like: Cells need to be added in the `table row`, you can create a table cell like:

View File

@ -68,40 +68,87 @@ const text = new TextRun({
}); });
``` ```
### Emphasis Mark
```ts
const text = new TextRun({
text: "and then emphasis mark",
emphasisMark: {},
});
```
### Shading and Highlighting
```ts
const text = new TextRun({
text: "shading",
shading: {
type: ShadingType.REVERSE_DIAGONAL_STRIPE,
color: "00FFFF",
fill: "FF0000",
},
});
```
```ts
const text = new TextRun({
text: "highlighting",
highlight: "yellow",
});
```
### Strike through ### Strike through
```ts ```ts
text.strike(); const text = new TextRun({
text: "strike",
strike: true,
});
``` ```
### Double strike through ### Double strike through
```ts ```ts
text.doubleStrike(); const text = new TextRun({
text: "doubleStrike",
doubleStrike: true,
});
``` ```
### Superscript ### Superscript
```ts ```ts
text.superScript(); const text = new TextRun({
text: "superScript",
superScript: true,
});
``` ```
### Subscript ### Subscript
```ts ```ts
text.subScript(); const text = new TextRun({
text: "subScript",
subScript: true,
});
``` ```
### All Capitals ### All Capitals
```ts ```ts
text.allCaps(); const text = new TextRun({
text: "allCaps",
allCaps: true,
});
``` ```
### Small Capitals ### Small Capitals
```ts ```ts
text.smallCaps(); const text = new TextRun({
text: "smallCaps",
smallCaps: true,
});
``` ```
## Break ## Break
@ -109,13 +156,17 @@ text.smallCaps();
Sometimes you would want to put text underneath another line of text but inside the same paragraph. Sometimes you would want to put text underneath another line of text but inside the same paragraph.
```ts ```ts
text.break(); const text = new TextRun({
text: "break",
break: 1,
});
``` ```
## Chaining Adding two breaks:
What if you want to create a paragraph which is **_bold_** and **_italic_**?
```ts ```ts
paragraph.bold().italics(); const text = new TextRun({
text: "break",
break: 2,
});
``` ```

3590
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "docx", "name": "docx",
"version": "5.0.2", "version": "5.5.0",
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.", "description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
"main": "build/index.js", "main": "build/index.js",
"scripts": { "scripts": {
@ -50,7 +50,7 @@
"types": "./build/index.d.ts", "types": "./build/index.d.ts",
"dependencies": { "dependencies": {
"@types/jszip": "^3.1.4", "@types/jszip": "^3.1.4",
"@types/node": "^13.1.6", "@types/node": "^14.0.5",
"jszip": "^3.1.5", "jszip": "^3.1.5",
"shortid": "^2.2.15", "shortid": "^2.2.15",
"xml": "^1.0.1", "xml": "^1.0.1",
@ -64,10 +64,10 @@
"homepage": "https://github.com/dolanmiu/docx#readme", "homepage": "https://github.com/dolanmiu/docx#readme",
"devDependencies": { "devDependencies": {
"@types/chai": "^3.4.35", "@types/chai": "^3.4.35",
"@types/mocha": "^2.2.39", "@types/mocha": "^8.0.0",
"@types/request-promise": "^4.1.42", "@types/request-promise": "^4.1.42",
"@types/shortid": "0.0.29", "@types/shortid": "0.0.29",
"@types/sinon": "^4.3.1", "@types/sinon": "^9.0.4",
"@types/webpack": "^4.4.24", "@types/webpack": "^4.4.24",
"awesome-typescript-loader": "^3.4.1", "awesome-typescript-loader": "^3.4.1",
"chai": "^3.5.0", "chai": "^3.5.0",
@ -77,24 +77,24 @@
"jszip": "^3.1.5", "jszip": "^3.1.5",
"mocha": "^5.2.0", "mocha": "^5.2.0",
"mocha-webpack": "^1.0.1", "mocha-webpack": "^1.0.1",
"nyc": "^14.1.1", "nyc": "^15.1.0",
"pre-commit": "^1.2.2", "pre-commit": "^1.2.2",
"prettier": "^1.15.2", "prettier": "^2.1.2",
"prompt": "^1.0.0", "prompt": "^1.0.0",
"replace-in-file": "^3.1.0", "replace-in-file": "^3.1.0",
"request": "^2.88.0", "request": "^2.88.0",
"request-promise": "^4.2.2", "request-promise": "^4.2.2",
"rimraf": "^2.5.2", "rimraf": "^3.0.2",
"shelljs": "^0.7.7", "shelljs": "^0.8.4",
"sinon": "^5.0.7", "sinon": "^9.0.2",
"ts-node": "^7.0.1", "ts-node": "^9.0.0",
"tslint": "^5.11.0", "tslint": "^6.1.3",
"tslint-immutable": "^4.9.0", "tslint-immutable": "^6.0.1",
"typedoc": "^0.11.1", "typedoc": "^0.16.11",
"typescript": "2.9.2", "typescript": "2.9.2",
"webpack": "^3.10.0" "webpack": "^3.10.0"
}, },
"engines": { "engines": {
"node": ">=8" "node": ">=10"
} }
} }

View File

@ -0,0 +1,18 @@
import { expect } from "chai";
import { convertInchesToTwip, convertMillimetersToTwip } from "./convenience-functions";
describe("Utility", () => {
describe("#convertMillimetersToTwip", () => {
it("should call the underlying header's addChildElement for Paragraph", () => {
expect(convertMillimetersToTwip(1000)).to.equal(56692);
});
});
describe("#convertInchesToTwip", () => {
it("should call the underlying header's addChildElement", () => {
expect(convertInchesToTwip(1)).to.equal(1440);
expect(convertInchesToTwip(0.5)).to.equal(720);
expect(convertInchesToTwip(0.25)).to.equal(360);
});
});
});

View File

@ -0,0 +1,8 @@
// Twip - twentieths of a point
export const convertMillimetersToTwip = (millimeters: number): number => {
return Math.floor((millimeters / 25.4) * 72 * 20);
};
export const convertInchesToTwip = (inches: number): number => {
return Math.floor(inches * 72 * 20);
};

View File

@ -16,7 +16,7 @@ describe("Compiler", () => {
}); });
describe("#compile()", () => { describe("#compile()", () => {
it("should pack all the content", async function() { it("should pack all the content", async function () {
this.timeout(99999999); this.timeout(99999999);
const zipFile = compiler.compile(file); const zipFile = compiler.compile(file);
const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name); const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name);
@ -35,7 +35,7 @@ describe("Compiler", () => {
expect(fileNames).to.include("_rels/.rels"); expect(fileNames).to.include("_rels/.rels");
}); });
it("should pack all additional headers and footers", async function() { it("should pack all additional headers and footers", async function () {
file.addSection({ file.addSection({
headers: { headers: {
default: new Header(), default: new Header(),

View File

@ -36,7 +36,7 @@ describe("Packer", () => {
}); });
describe("#toBuffer()", () => { describe("#toBuffer()", () => {
it("should create a standard docx file", async function() { it("should create a standard docx file", async function () {
this.timeout(99999999); this.timeout(99999999);
const buffer = await Packer.toBuffer(file); const buffer = await Packer.toBuffer(file);
@ -61,7 +61,7 @@ describe("Packer", () => {
}); });
describe("#toBase64String()", () => { describe("#toBase64String()", () => {
it("should create a standard docx file", async function() { it("should create a standard docx file", async function () {
this.timeout(99999999); this.timeout(99999999);
const str = await Packer.toBase64String(file); const str = await Packer.toBase64String(file);

View File

@ -1,4 +1,5 @@
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
import { IDocumentBackgroundOptions } from "../document";
import { DocumentAttributes } from "../document/document-attributes"; import { DocumentAttributes } from "../document/document-attributes";
import { INumberingOptions } from "../numbering"; import { INumberingOptions } from "../numbering";
@ -32,6 +33,10 @@ export interface IPropertiesOptions {
readonly hyperlinks?: { readonly hyperlinks?: {
readonly [key: string]: IInternalHyperlinkDefinition | IExternalHyperlinkDefinition; readonly [key: string]: IInternalHyperlinkDefinition | IExternalHyperlinkDefinition;
}; };
readonly background?: IDocumentBackgroundOptions;
readonly features?: {
readonly trackRevisions?: boolean;
};
} }
export class CoreProperties extends XmlComponent { export class CoreProperties extends XmlComponent {

View File

@ -45,7 +45,7 @@ export class Body extends XmlComponent {
private createSectionParagraph(section: SectionProperties): Paragraph { private createSectionParagraph(section: SectionProperties): Paragraph {
const paragraph = new Paragraph({}); const paragraph = new Paragraph({});
const properties = new ParagraphProperties({}); const properties = new ParagraphProperties({});
properties.addChildElement(section); properties.push(section);
paragraph.addChildElement(properties); paragraph.addChildElement(properties);
return paragraph; return paragraph;
} }

View File

@ -14,6 +14,7 @@ export enum PageNumberFormat {
ORDINAL_TEXT = "ordinalText", ORDINAL_TEXT = "ordinalText",
UPPER_LETTER = "upperLetter", UPPER_LETTER = "upperLetter",
UPPER_ROMAN = "upperRoman", UPPER_ROMAN = "upperRoman",
DECIMAL_FULL_WIDTH = "decimalFullWidth",
} }
export interface IPageNumberTypeAttributes { export interface IPageNumberTypeAttributes {

View File

@ -1,5 +1,6 @@
import { expect } from "chai"; import { expect } from "chai";
import { convertInchesToTwip } from "convenience-functions";
import { Formatter } from "export/formatter"; import { Formatter } from "export/formatter";
import { FooterWrapper } from "file/footer-wrapper"; import { FooterWrapper } from "file/footer-wrapper";
import { HeaderWrapper } from "file/header-wrapper"; import { HeaderWrapper } from "file/header-wrapper";
@ -18,10 +19,10 @@ describe("SectionProperties", () => {
const properties = new SectionProperties({ const properties = new SectionProperties({
width: 11906, width: 11906,
height: 16838, height: 16838,
top: 1440, top: convertInchesToTwip(1),
right: 1440, right: convertInchesToTwip(1),
bottom: 1440, bottom: convertInchesToTwip(1),
left: 1440, left: convertInchesToTwip(1),
header: 708, header: 708,
footer: 708, footer: 708,
gutter: 0, gutter: 0,
@ -30,7 +31,7 @@ describe("SectionProperties", () => {
space: 708, space: 708,
count: 1, count: 1,
}, },
linePitch: 360, linePitch: convertInchesToTwip(0.25),
headers: { headers: {
default: new HeaderWrapper(media, 100), default: new HeaderWrapper(media, 100),
}, },

View File

@ -1,4 +1,5 @@
// http://officeopenxml.com/WPsection.php // http://officeopenxml.com/WPsection.php
import { convertInchesToTwip } from "convenience-functions";
import { FooterWrapper } from "file/footer-wrapper"; import { FooterWrapper } from "file/footer-wrapper";
import { HeaderWrapper } from "file/header-wrapper"; import { HeaderWrapper } from "file/header-wrapper";
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
@ -64,10 +65,10 @@ export class SectionProperties extends XmlComponent {
const { const {
width = 11906, width = 11906,
height = 16838, height = 16838,
top = 1440, top = convertInchesToTwip(1),
right = 1440, right = convertInchesToTwip(1),
bottom = 1440, bottom = convertInchesToTwip(1),
left = 1440, left = convertInchesToTwip(1),
header = 708, header = 708,
footer = 708, footer = 708,
gutter = 0, gutter = 0,

View File

@ -0,0 +1,53 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { DocumentBackground } from "./document-background";
describe("DocumentBackground", () => {
describe("#constructor()", () => {
it("should create a DocumentBackground with no options and set color to auto", () => {
const documentBackground = new DocumentBackground({});
const tree = new Formatter().format(documentBackground);
expect(tree).to.deep.equal({
"w:background": {
_attr: {
"w:color": "FFFFFF",
},
},
});
});
it("should create a DocumentBackground with no options and set color to value", () => {
const documentBackground = new DocumentBackground({ color: "ffff00" });
const tree = new Formatter().format(documentBackground);
expect(tree).to.deep.equal({
"w:background": {
_attr: {
"w:color": "ffff00",
},
},
});
});
it("should create a DocumentBackground with no options and set other values", () => {
const documentBackground = new DocumentBackground({
color: "ffff00",
themeColor: "test",
themeShade: "test",
themeTint: "test",
});
const tree = new Formatter().format(documentBackground);
expect(tree).to.deep.equal({
"w:background": {
_attr: {
"w:color": "ffff00",
"w:themeColor": "test",
"w:themeShade": "test",
"w:themeTint": "test",
},
},
});
});
});
});

View File

@ -0,0 +1,39 @@
// http://officeopenxml.com/WPdocument.php
// http://www.datypic.com/sc/ooxml/e-w_background-1.html
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
export class DocumentBackgroundAttributes extends XmlAttributeComponent<{
readonly color: string;
readonly themeColor?: string;
readonly themeShade?: string;
readonly themeTint?: string;
}> {
protected readonly xmlKeys = {
color: "w:color",
themeColor: "w:themeColor",
themeShade: "w:themeShade",
themeTint: "w:themeTint",
};
}
export interface IDocumentBackgroundOptions {
readonly color?: string;
readonly themeColor?: string;
readonly themeShade?: string;
readonly themeTint?: string;
}
export class DocumentBackground extends XmlComponent {
constructor(options: IDocumentBackgroundOptions) {
super("w:background");
this.root.push(
new DocumentBackgroundAttributes({
color: options.color ? options.color : "FFFFFF",
themeColor: options.themeColor,
themeShade: options.themeShade,
themeTint: options.themeTint,
}),
);
}
}

View File

@ -0,0 +1 @@
export * from "./document-background";

View File

@ -8,7 +8,7 @@ describe("Document", () => {
let document: Document; let document: Document;
beforeEach(() => { beforeEach(() => {
document = new Document(); document = new Document({ background: {} });
}); });
describe("#constructor()", () => { describe("#constructor()", () => {
@ -38,6 +38,13 @@ describe("Document", () => {
"mc:Ignorable": "w14 w15 wp14", "mc:Ignorable": "w14 w15 wp14",
}, },
}, },
{
"w:background": {
_attr: {
"w:color": "FFFFFF",
},
},
},
{ "w:body": {} }, { "w:body": {} },
], ],
}); });

View File

@ -5,11 +5,16 @@ import { Table } from "../table";
import { TableOfContents } from "../table-of-contents"; import { TableOfContents } from "../table-of-contents";
import { Body } from "./body"; import { Body } from "./body";
import { DocumentAttributes } from "./document-attributes"; import { DocumentAttributes } from "./document-attributes";
import { DocumentBackground, IDocumentBackgroundOptions } from "./document-background";
interface IDocumentOptions {
readonly background: IDocumentBackgroundOptions;
}
export class Document extends XmlComponent { export class Document extends XmlComponent {
private readonly body: Body; private readonly body: Body;
constructor() { constructor(options: IDocumentOptions) {
super("w:document"); super("w:document");
this.root.push( this.root.push(
new DocumentAttributes({ new DocumentAttributes({
@ -33,6 +38,7 @@ export class Document extends XmlComponent {
}), }),
); );
this.body = new Body(); this.body = new Body();
this.root.push(new DocumentBackground(options.background));
this.root.push(this.body); this.root.push(this.body);
} }

View File

@ -1,3 +1,4 @@
export * from "./document"; export * from "./document";
export * from "./document-attributes"; export * from "./document-attributes";
export * from "./body"; export * from "./body";
export * from "./document-background";

View File

@ -218,5 +218,150 @@ describe("Anchor", () => {
const textWrap = newJson.root[6]; const textWrap = newJson.root[6];
assert.equal(textWrap.rootKey, "wp:wrapTopAndBottom"); assert.equal(textWrap.rootKey, "wp:wrapTopAndBottom");
}); });
it("should create a Drawing with a margin", () => {
anchor = createAnchor({
floating: {
verticalPosition: {
offset: 0,
},
horizontalPosition: {
offset: 0,
},
margins: {
top: 10,
left: 10,
bottom: 10,
right: 10,
},
},
});
const newJson = Utility.jsonify(anchor);
const anchorAttributes = newJson.root[0].root;
assert.include(anchorAttributes, {
distT: 10,
distB: 10,
distL: 10,
distR: 10,
});
});
it("should create a Drawing with a default margin", () => {
anchor = createAnchor({
floating: {
verticalPosition: {
offset: 0,
},
horizontalPosition: {
offset: 0,
},
margins: {},
},
});
const newJson = Utility.jsonify(anchor);
const anchorAttributes = newJson.root[0].root;
assert.include(anchorAttributes, {
distT: 0,
distB: 0,
distL: 0,
distR: 0,
});
});
it("should create a Drawing with allowOverlap being false", () => {
anchor = createAnchor({
floating: {
verticalPosition: {
offset: 0,
},
horizontalPosition: {
offset: 0,
},
allowOverlap: false,
},
});
const newJson = Utility.jsonify(anchor);
const anchorAttributes = newJson.root[0].root;
assert.include(anchorAttributes, {
allowOverlap: "0",
});
});
it("should create a Drawing with behindDocument being true", () => {
anchor = createAnchor({
floating: {
verticalPosition: {
offset: 0,
},
horizontalPosition: {
offset: 0,
},
behindDocument: true,
},
});
const newJson = Utility.jsonify(anchor);
const anchorAttributes = newJson.root[0].root;
assert.include(anchorAttributes, {
behindDoc: "1",
});
});
it("should create a Drawing with locked being true", () => {
anchor = createAnchor({
floating: {
verticalPosition: {
offset: 0,
},
horizontalPosition: {
offset: 0,
},
lockAnchor: true,
},
});
const newJson = Utility.jsonify(anchor);
const anchorAttributes = newJson.root[0].root;
assert.include(anchorAttributes, {
locked: "1",
});
});
it("should create a Drawing with locked being false", () => {
anchor = createAnchor({
floating: {
verticalPosition: {
offset: 0,
},
horizontalPosition: {
offset: 0,
},
layoutInCell: false,
},
});
const newJson = Utility.jsonify(anchor);
const anchorAttributes = newJson.root[0].root;
assert.include(anchorAttributes, {
layoutInCell: "0",
});
});
it("should create a Drawing with a certain z-index", () => {
anchor = createAnchor({
floating: {
verticalPosition: {
offset: 0,
},
horizontalPosition: {
offset: 0,
},
zIndex: 120,
},
});
const newJson = Utility.jsonify(anchor);
const anchorAttributes = newJson.root[0].root;
assert.include(anchorAttributes, {
relativeHeight: 120,
});
});
}); });
}); });

View File

@ -11,42 +11,32 @@ import { Extent } from "./../extent/extent";
import { GraphicFrameProperties } from "./../graphic-frame/graphic-frame-properties"; import { GraphicFrameProperties } from "./../graphic-frame/graphic-frame-properties";
import { AnchorAttributes } from "./anchor-attributes"; import { AnchorAttributes } from "./anchor-attributes";
const defaultOptions: IFloating = {
allowOverlap: true,
behindDocument: false,
lockAnchor: false,
layoutInCell: true,
verticalPosition: {},
horizontalPosition: {},
};
export class Anchor extends XmlComponent { export class Anchor extends XmlComponent {
constructor(mediaData: IMediaData, dimensions: IMediaDataDimensions, drawingOptions: IDrawingOptions) { constructor(mediaData: IMediaData, dimensions: IMediaDataDimensions, drawingOptions: IDrawingOptions) {
super("wp:anchor"); super("wp:anchor");
const floating = { const floating: IFloating = {
margins: { allowOverlap: true,
top: 0, behindDocument: false,
bottom: 0, lockAnchor: false,
left: 0, layoutInCell: true,
right: 0, verticalPosition: {},
}, horizontalPosition: {},
...defaultOptions,
...drawingOptions.floating, ...drawingOptions.floating,
}; };
this.root.push( this.root.push(
new AnchorAttributes({ new AnchorAttributes({
distT: floating.margins.top || 0, distT: floating.margins ? floating.margins.top || 0 : 0,
distB: floating.margins.bottom || 0, distB: floating.margins ? floating.margins.bottom || 0 : 0,
distL: floating.margins.left || 0, distL: floating.margins ? floating.margins.left || 0 : 0,
distR: floating.margins.right || 0, distR: floating.margins ? floating.margins.right || 0 : 0,
simplePos: "0", // note: word doesn't fully support - so we use 0 simplePos: "0", // note: word doesn't fully support - so we use 0
allowOverlap: floating.allowOverlap === true ? "1" : "0", allowOverlap: floating.allowOverlap === true ? "1" : "0",
behindDoc: floating.behindDocument === true ? "1" : "0", behindDoc: floating.behindDocument === true ? "1" : "0",
locked: floating.lockAnchor === true ? "1" : "0", locked: floating.lockAnchor === true ? "1" : "0",
layoutInCell: floating.layoutInCell === true ? "1" : "0", layoutInCell: floating.layoutInCell === true ? "1" : "0",
relativeHeight: dimensions.emus.y, relativeHeight: floating.zIndex ? floating.zIndex : dimensions.emus.y,
}), }),
); );

View File

@ -1,4 +1,5 @@
// http://officeopenxml.com/drwPicFloating-position.php // http://officeopenxml.com/drwPicFloating-position.php
// http://officeopenxml.com/drwPicFloating.php
import { ITextWrapping } from "../text-wrap"; import { ITextWrapping } from "../text-wrap";
export enum HorizontalPositionRelativeFrom { export enum HorizontalPositionRelativeFrom {
@ -67,4 +68,5 @@ export interface IFloating {
readonly layoutInCell?: boolean; readonly layoutInCell?: boolean;
readonly margins?: IMargins; readonly margins?: IMargins;
readonly wrap?: ITextWrapping; readonly wrap?: ITextWrapping;
readonly zIndex?: number;
} }

View File

@ -12,7 +12,7 @@ export class Inline extends XmlComponent {
private readonly extent: Extent; private readonly extent: Extent;
private readonly graphic: Graphic; private readonly graphic: Graphic;
constructor(readonly mediaData: IMediaData, private readonly dimensions: IMediaDataDimensions) { constructor(mediaData: IMediaData, private readonly dimensions: IMediaDataDimensions) {
super("wp:inline"); super("wp:inline");
this.root.push( this.root.push(

View File

@ -5,7 +5,7 @@ import { Formatter } from "export/formatter";
import { File } from "./file"; import { File } from "./file";
import { Footer, Header } from "./header"; import { Footer, Header } from "./header";
import { HyperlinkRef, Paragraph } from "./paragraph"; import { HyperlinkRef, HyperlinkType, Paragraph } from "./paragraph";
import { Table, TableCell, TableRow } from "./table"; import { Table, TableCell, TableRow } from "./table";
import { TableOfContents } from "./table-of-contents"; import { TableOfContents } from "./table-of-contents";
@ -243,12 +243,40 @@ describe("File", () => {
}); });
}); });
describe("#addTrackRevisionsFeature", () => {
it("should call the underlying document's add", () => {
const file = new File({
features: {
trackRevisions: true,
},
});
// tslint:disable-next-line: no-unused-expression no-string-literal
expect(file.Settings["trackRevisions"]).to.exist;
});
});
describe("#HyperlinkCache", () => { describe("#HyperlinkCache", () => {
it("should initially have empty hyperlink cache", () => { it("should initially have empty hyperlink cache", () => {
const file = new File(); const file = new File();
expect(file.HyperlinkCache).to.deep.equal({}); expect(file.HyperlinkCache).to.deep.equal({});
}); });
it("should have hyperlink cache when option is added", () => {
const file = new File({
hyperlinks: {
myCoolLink: {
link: "http://www.example.com",
text: "Hyperlink",
type: HyperlinkType.EXTERNAL,
},
},
});
// tslint:disable-next-line: no-unused-expression no-string-literal
expect(file.HyperlinkCache["myCoolLink"]).to.exist;
});
}); });
describe("#createFootnote", () => { describe("#createFootnote", () => {

View File

@ -41,7 +41,7 @@ export interface ISectionOptions {
readonly size?: IPageSizeAttributes; readonly size?: IPageSizeAttributes;
readonly margins?: IPageMarginAttributes; readonly margins?: IPageMarginAttributes;
readonly properties?: SectionPropertiesOptions; readonly properties?: SectionPropertiesOptions;
readonly children: Array<Paragraph | Table | TableOfContents | HyperlinkRef>; readonly children: (Paragraph | Table | TableOfContents | HyperlinkRef)[];
} }
export class File { export class File {
@ -85,7 +85,7 @@ export class File {
this.appProperties = new AppProperties(); this.appProperties = new AppProperties();
this.footNotes = new FootNotes(); this.footNotes = new FootNotes();
this.contentTypes = new ContentTypes(); this.contentTypes = new ContentTypes();
this.document = new Document(); this.document = new Document({ background: options.background || {} });
this.settings = new Settings(); this.settings = new Settings();
this.media = fileProperties.template && fileProperties.template.media ? fileProperties.template.media : new Media(); this.media = fileProperties.template && fileProperties.template.media ? fileProperties.template.media : new Media();
@ -106,7 +106,7 @@ export class File {
this.styles = stylesFactory.newInstance(options.externalStyles); this.styles = stylesFactory.newInstance(options.externalStyles);
} else if (options.styles) { } else if (options.styles) {
const stylesFactory = new DefaultStylesFactory(); const stylesFactory = new DefaultStylesFactory();
const defaultStyles = stylesFactory.newInstance(); const defaultStyles = stylesFactory.newInstance(options.styles.default);
this.styles = new Styles({ this.styles = new Styles({
...defaultStyles, ...defaultStyles,
...options.styles, ...options.styles,
@ -170,6 +170,12 @@ export class File {
this.hyperlinkCache = cache; this.hyperlinkCache = cache;
} }
if (options.features) {
if (options.features.trackRevisions) {
this.settings.addTrackRevisions();
}
}
} }
public addSection({ public addSection({

View File

@ -2,7 +2,7 @@ import { Paragraph } from "./paragraph";
import { Table } from "./table"; import { Table } from "./table";
export interface IHeaderOptions { export interface IHeaderOptions {
readonly children: Array<Paragraph | Table>; readonly children: (Paragraph | Table)[];
} }
export class Header { export class Header {

View File

@ -13,3 +13,4 @@ export * from "./header-wrapper";
export * from "./footer-wrapper"; export * from "./footer-wrapper";
export * from "./header"; export * from "./header";
export * from "./footnotes"; export * from "./footnotes";
export * from "./track-revision";

View File

@ -21,14 +21,7 @@ export class Media {
private static generateId(): string { private static generateId(): string {
// https://gist.github.com/6174/6062387 // https://gist.github.com/6174/6062387
return ( return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
Math.random()
.toString(36)
.substring(2, 15) +
Math.random()
.toString(36)
.substring(2, 15)
);
} }
private readonly map: Map<string, IMediaData>; private readonly map: Map<string, IMediaData>;

View File

@ -3,10 +3,11 @@ import { expect } from "chai";
import { Formatter } from "export/formatter"; import { Formatter } from "export/formatter";
import { EMPTY_OBJECT } from "file/xml-components"; import { EMPTY_OBJECT } from "file/xml-components";
import { AlignmentType, TabStopPosition } from "../paragraph"; import { AlignmentType, EmphasisMarkType, TabStopPosition } from "../paragraph";
import { UnderlineType } from "../paragraph/run/underline"; import { UnderlineType } from "../paragraph/run/underline";
import { ShadingType } from "../table"; import { ShadingType } from "../table";
import { AbstractNumbering } from "./abstract-numbering"; import { AbstractNumbering } from "./abstract-numbering";
import { LevelFormat, LevelSuffix } from "./level";
describe("AbstractNumbering", () => { describe("AbstractNumbering", () => {
it("stores its ID at its .id property", () => { it("stores its ID at its .id property", () => {
@ -19,7 +20,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 3, level: 3,
format: "lowerLetter", format: LevelFormat.LOWER_LETTER,
text: "%1)", text: "%1)",
alignment: AlignmentType.END, alignment: AlignmentType.END,
}, },
@ -28,7 +29,7 @@ describe("AbstractNumbering", () => {
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ _attr: { "w:ilvl": 3, "w15:tentative": 1 } }); expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ _attr: { "w:ilvl": 3, "w15:tentative": 1 } });
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:start": { _attr: { "w:val": 1 } } }); expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:start": { _attr: { "w:val": 1 } } });
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:lvlJc": { _attr: { "w:val": "end" } } }); expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:lvlJc": { _attr: { "w:val": "end" } } });
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:numFmt": { _attr: { "w:val": "lowerLetter" } } }); expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:numFmt": { _attr: { "w:val": LevelFormat.LOWER_LETTER } } });
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:lvlText": { _attr: { "w:val": "%1)" } } }); expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:lvlText": { _attr: { "w:val": "%1)" } } });
}); });
@ -36,7 +37,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 3, level: 3,
format: "lowerLetter", format: LevelFormat.LOWER_LETTER,
text: "%1)", text: "%1)",
}, },
]); ]);
@ -44,16 +45,30 @@ describe("AbstractNumbering", () => {
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ _attr: { "w:ilvl": 3, "w15:tentative": 1 } }); expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ _attr: { "w:ilvl": 3, "w15:tentative": 1 } });
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:start": { _attr: { "w:val": 1 } } }); expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:start": { _attr: { "w:val": 1 } } });
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:lvlJc": { _attr: { "w:val": "start" } } }); expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:lvlJc": { _attr: { "w:val": "start" } } });
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:numFmt": { _attr: { "w:val": "lowerLetter" } } }); expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:numFmt": { _attr: { "w:val": LevelFormat.LOWER_LETTER } } });
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:lvlText": { _attr: { "w:val": "%1)" } } }); expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:lvlText": { _attr: { "w:val": "%1)" } } });
}); });
it("has suffix", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 3,
format: LevelFormat.LOWER_LETTER,
text: "%1)",
alignment: AlignmentType.END,
suffix: LevelSuffix.SPACE,
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:suff": { _attr: { "w:val": "space" } } });
});
describe("formatting methods: paragraph properties", () => { describe("formatting methods: paragraph properties", () => {
it("#indent", () => { it("#indent", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
paragraph: { paragraph: {
@ -72,7 +87,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
paragraph: { paragraph: {
@ -91,7 +106,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
paragraph: { paragraph: {
@ -110,7 +125,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
paragraph: { paragraph: {
@ -129,7 +144,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
paragraph: { paragraph: {
@ -148,7 +163,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
paragraph: { paragraph: {
@ -167,7 +182,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
paragraph: { paragraph: {
@ -201,7 +216,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
paragraph: { paragraph: {
@ -224,7 +239,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
paragraph: { paragraph: {
@ -247,7 +262,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
paragraph: { paragraph: {
@ -266,7 +281,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
paragraph: { paragraph: {
@ -283,22 +298,41 @@ describe("AbstractNumbering", () => {
}); });
describe("formatting methods: run properties", () => { describe("formatting methods: run properties", () => {
it("#size", () => { const sizeTests = [
const abstractNumbering = new AbstractNumbering(1, [ {
{ size: 24,
level: 0, expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
format: "lowerRoman", },
text: "%0.", {
style: { size: 24,
run: { sizeComplexScript: true,
size: 24, expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: false,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: 26,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 26 } } }],
},
];
sizeTests.forEach(({ size, sizeComplexScript, expected }) => {
it(`#size ${size} cs ${sizeComplexScript}`, () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
text: "%0.",
style: {
run: { size, sizeComplexScript },
}, },
}, },
}, ]);
]); const tree = new Formatter().format(abstractNumbering);
const tree = new Formatter().format(abstractNumbering); expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:sz": { _attr: { "w:val": 24 } } }],
}); });
}); });
@ -306,7 +340,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
run: { run: {
@ -325,7 +359,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
run: { run: {
@ -344,7 +378,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
run: { run: {
@ -364,7 +398,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
run: { run: {
@ -383,7 +417,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
run: { run: {
@ -402,7 +436,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
run: { run: {
@ -417,11 +451,11 @@ describe("AbstractNumbering", () => {
}); });
}); });
it("#font", () => { it("#font by name", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
run: { run: {
@ -433,80 +467,31 @@ describe("AbstractNumbering", () => {
const tree = new Formatter().format(abstractNumbering); const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [ "w:rPr": [
{ "w:rFonts": { _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } } }, {
"w:rFonts": {
_attr: {
"w:ascii": "Times",
"w:cs": "Times",
"w:eastAsia": "Times",
"w:hAnsi": "Times",
},
},
},
], ],
}); });
}); });
it("#bold", () => { it("#font for ascii and eastAsia", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
run: { run: {
bold: true, font: {
}, ascii: "Times",
}, eastAsia: "KaiTi",
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:b": { _attr: { "w:val": true } } }],
});
});
it("#italics", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: {
italics: true,
},
},
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:i": { _attr: { "w:val": true } } }],
});
});
it("#highlight", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: {
highlight: "005599",
},
},
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:highlight": { _attr: { "w:val": "005599" } } }],
});
});
it("#shadow", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: {
shadow: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
}, },
}, },
}, },
@ -514,7 +499,198 @@ describe("AbstractNumbering", () => {
]); ]);
const tree = new Formatter().format(abstractNumbering); const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }], "w:rPr": [
{
"w:rFonts": {
_attr: {
"w:ascii": "Times",
"w:eastAsia": "KaiTi",
},
},
},
],
});
});
const boldTests = [
{
bold: true,
expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }],
},
{
bold: true,
boldComplexScript: true,
expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }],
},
{
bold: true,
boldComplexScript: false,
expected: [{ "w:b": { _attr: { "w:val": true } } }],
},
];
boldTests.forEach(({ bold, boldComplexScript, expected }) => {
it(`#bold ${bold} cs ${boldComplexScript}`, () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
text: "%0.",
style: {
run: { bold, boldComplexScript },
},
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
});
});
const italicsTests = [
{
italics: true,
expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }],
},
{
italics: true,
italicsComplexScript: true,
expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }],
},
{
italics: true,
italicsComplexScript: false,
expected: [{ "w:i": { _attr: { "w:val": true } } }],
},
];
italicsTests.forEach(({ italics, italicsComplexScript, expected }) => {
it(`#italics ${italics} cs ${italicsComplexScript}`, () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
text: "%0.",
style: {
run: { italics, italicsComplexScript },
},
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
});
});
const highlightTests = [
{
highlight: "005599",
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }],
},
{
highlight: "005599",
highlightComplexScript: true,
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }],
},
{
highlight: "005599",
highlightComplexScript: false,
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }],
},
{
highlight: "005599",
highlightComplexScript: "550099",
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "550099" } } }],
},
];
highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => {
it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
text: "%0.",
style: {
run: { highlight, highlightComplexScript },
},
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
});
});
const shadingTests = [
{
shadow: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: true,
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: false,
expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "00FF00",
},
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "00FF00" } } },
],
},
];
shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => {
it("#shadow correctly", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
text: "%0.",
style: {
run: { shadow, shading, shadingComplexScript },
},
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
}); });
}); });
@ -523,7 +699,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
run: { run: {
@ -542,7 +718,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
run: { run: {
@ -563,7 +739,7 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
run: { run: {
@ -582,11 +758,53 @@ describe("AbstractNumbering", () => {
}); });
}); });
describe("#emphasisMark", () => {
it("should set emphasisMark to 'dot' if no arguments are given", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
text: "%0.",
style: {
run: {
emphasisMark: {},
},
},
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }],
});
});
it("should set the style if given", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: LevelFormat.LOWER_ROMAN,
text: "%0.",
style: {
run: {
emphasisMark: {
type: EmphasisMarkType.DOT,
},
},
},
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }],
});
});
});
it("#color", () => { it("#color", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: LevelFormat.LOWER_ROMAN,
text: "%0.", text: "%0.",
style: { style: {
run: { run: {

View File

@ -1,19 +1,25 @@
// http://officeopenxml.com/WPnumbering-numFmt.php
import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components";
import { import { AlignmentType } from "../paragraph/formatting";
Alignment, import { IParagraphStylePropertiesOptions, ParagraphProperties } from "../paragraph/properties";
AlignmentType, import { IRunStylePropertiesOptions, RunProperties } from "../paragraph/run/properties";
Indent,
KeepLines, export enum LevelFormat {
KeepNext, BULLET = "bullet",
Spacing, CARDINAL_TEXT = "cardinalText",
TabStop, CHICAGO = "chicago",
TabStopType, DECIMAL = "decimal",
ThematicBreak, DECIMAL_ENCLOSED_CIRCLE = "decimalEnclosedCircle",
} from "../paragraph/formatting"; DECIMAL_ENCLOSED_FULLSTOP = "decimalEnclosedFullstop",
import { ParagraphProperties } from "../paragraph/properties"; DECIMAL_ENCLOSED_PARENTHESES = "decimalEnclosedParen",
import * as formatting from "../paragraph/run/formatting"; DECIMAL_ZERO = "decimalZero",
import { RunProperties } from "../paragraph/run/properties"; LOWER_LETTER = "lowerLetter",
import { IParagraphStyleOptions2, IRunStyleOptions } from "../styles/style-options"; LOWER_ROMAN = "lowerRoman",
NONE = "none",
ORDINAL_TEXT = "ordinalText",
UPPER_LETTER = "upperLetter",
UPPER_ROMAN = "upperRoman",
}
interface ILevelAttributesProperties { interface ILevelAttributesProperties {
readonly ilvl?: number; readonly ilvl?: number;
@ -79,14 +85,14 @@ export enum LevelSuffix {
export interface ILevelsOptions { export interface ILevelsOptions {
readonly level: number; readonly level: number;
readonly format?: string; readonly format?: LevelFormat;
readonly text?: string; readonly text?: string;
readonly alignment?: AlignmentType; readonly alignment?: AlignmentType;
readonly start?: number; readonly start?: number;
readonly suffix?: LevelSuffix; readonly suffix?: LevelSuffix;
readonly style?: { readonly style?: {
readonly run?: IRunStyleOptions; readonly run?: IRunStylePropertiesOptions;
readonly paragraph?: IParagraphStyleOptions2; readonly paragraph?: IParagraphStylePropertiesOptions;
}; };
} }
@ -125,8 +131,8 @@ export class LevelBase extends XmlComponent {
this.root.push(new LevelText(text)); this.root.push(new LevelText(text));
} }
this.paragraphProperties = new ParagraphProperties({}); this.paragraphProperties = new ParagraphProperties(style && style.paragraph);
this.runProperties = new RunProperties(); this.runProperties = new RunProperties(style && style.run);
this.root.push(this.paragraphProperties); this.root.push(this.paragraphProperties);
this.root.push(this.runProperties); this.root.push(this.runProperties);
@ -134,100 +140,6 @@ export class LevelBase extends XmlComponent {
if (suffix) { if (suffix) {
this.root.push(new Suffix(suffix)); this.root.push(new Suffix(suffix));
} }
if (style) {
if (style.run) {
if (style.run.size) {
this.runProperties.push(new formatting.Size(style.run.size));
}
if (style.run.bold) {
this.runProperties.push(new formatting.Bold());
}
if (style.run.italics) {
this.runProperties.push(new formatting.Italics());
}
if (style.run.smallCaps) {
this.runProperties.push(new formatting.SmallCaps());
}
if (style.run.allCaps) {
this.runProperties.push(new formatting.Caps());
}
if (style.run.strike) {
this.runProperties.push(new formatting.Strike());
}
if (style.run.doubleStrike) {
this.runProperties.push(new formatting.DoubleStrike());
}
if (style.run.subScript) {
this.runProperties.push(new formatting.SubScript());
}
if (style.run.superScript) {
this.runProperties.push(new formatting.SuperScript());
}
if (style.run.underline) {
this.runProperties.push(new formatting.Underline(style.run.underline.type, style.run.underline.color));
}
if (style.run.color) {
this.runProperties.push(new formatting.Color(style.run.color));
}
if (style.run.font) {
this.runProperties.push(new formatting.RunFonts(style.run.font));
}
if (style.run.highlight) {
this.runProperties.push(new formatting.Highlight(style.run.highlight));
}
if (style.run.shadow) {
this.runProperties.push(new formatting.Shading(style.run.shadow.type, style.run.shadow.fill, style.run.shadow.color));
}
}
if (style.paragraph) {
if (style.paragraph.alignment) {
this.paragraphProperties.push(new Alignment(style.paragraph.alignment));
}
if (style.paragraph.thematicBreak) {
this.paragraphProperties.push(new ThematicBreak());
}
if (style.paragraph.rightTabStop) {
this.paragraphProperties.push(new TabStop(TabStopType.RIGHT, style.paragraph.rightTabStop));
}
if (style.paragraph.leftTabStop) {
this.paragraphProperties.push(new TabStop(TabStopType.LEFT, style.paragraph.leftTabStop));
}
if (style.paragraph.indent) {
this.paragraphProperties.push(new Indent(style.paragraph.indent));
}
if (style.paragraph.spacing) {
this.paragraphProperties.push(new Spacing(style.paragraph.spacing));
}
if (style.paragraph.keepNext) {
this.paragraphProperties.push(new KeepNext());
}
if (style.paragraph.keepLines) {
this.paragraphProperties.push(new KeepLines());
}
}
}
} }
} }

View File

@ -1,17 +1,18 @@
// http://officeopenxml.com/WPnumbering.php // http://officeopenxml.com/WPnumbering.php
import { convertInchesToTwip } from "convenience-functions";
import { AlignmentType } from "file/paragraph"; import { AlignmentType } from "file/paragraph";
import { IXmlableObject, XmlComponent } from "file/xml-components"; import { IXmlableObject, XmlComponent } from "file/xml-components";
import { DocumentAttributes } from "../document/document-attributes"; import { DocumentAttributes } from "../document/document-attributes";
import { AbstractNumbering } from "./abstract-numbering"; import { AbstractNumbering } from "./abstract-numbering";
import { ILevelsOptions } from "./level"; import { ILevelsOptions, LevelFormat } from "./level";
import { ConcreteNumbering } from "./num"; import { ConcreteNumbering } from "./num";
export interface INumberingOptions { export interface INumberingOptions {
readonly config: Array<{ readonly config: {
readonly levels: ILevelsOptions[]; readonly levels: ILevelsOptions[];
readonly reference: string; readonly reference: string;
}>; }[];
} }
export class Numbering extends XmlComponent { export class Numbering extends XmlComponent {
@ -50,100 +51,100 @@ export class Numbering extends XmlComponent {
const abstractNumbering = this.createAbstractNumbering([ const abstractNumbering = this.createAbstractNumbering([
{ {
level: 0, level: 0,
format: "bullet", format: LevelFormat.BULLET,
text: "\u25CF", text: "\u25CF",
alignment: AlignmentType.LEFT, alignment: AlignmentType.LEFT,
style: { style: {
paragraph: { paragraph: {
indent: { left: 720, hanging: 360 }, indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.25) },
}, },
}, },
}, },
{ {
level: 1, level: 1,
format: "bullet", format: LevelFormat.BULLET,
text: "\u25CB", text: "\u25CB",
alignment: AlignmentType.LEFT, alignment: AlignmentType.LEFT,
style: { style: {
paragraph: { paragraph: {
indent: { left: 1440, hanging: 360 }, indent: { left: convertInchesToTwip(1), hanging: convertInchesToTwip(0.25) },
}, },
}, },
}, },
{ {
level: 2, level: 2,
format: "bullet", format: LevelFormat.BULLET,
text: "\u25A0", text: "\u25A0",
alignment: AlignmentType.LEFT, alignment: AlignmentType.LEFT,
style: { style: {
paragraph: { paragraph: {
indent: { left: 2160, hanging: 360 }, indent: { left: 2160, hanging: convertInchesToTwip(0.25) },
}, },
}, },
}, },
{ {
level: 3, level: 3,
format: "bullet", format: LevelFormat.BULLET,
text: "\u25CF", text: "\u25CF",
alignment: AlignmentType.LEFT, alignment: AlignmentType.LEFT,
style: { style: {
paragraph: { paragraph: {
indent: { left: 2880, hanging: 360 }, indent: { left: 2880, hanging: convertInchesToTwip(0.25) },
}, },
}, },
}, },
{ {
level: 4, level: 4,
format: "bullet", format: LevelFormat.BULLET,
text: "\u25CB", text: "\u25CB",
alignment: AlignmentType.LEFT, alignment: AlignmentType.LEFT,
style: { style: {
paragraph: { paragraph: {
indent: { left: 3600, hanging: 360 }, indent: { left: 3600, hanging: convertInchesToTwip(0.25) },
}, },
}, },
}, },
{ {
level: 5, level: 5,
format: "bullet", format: LevelFormat.BULLET,
text: "\u25A0", text: "\u25A0",
alignment: AlignmentType.LEFT, alignment: AlignmentType.LEFT,
style: { style: {
paragraph: { paragraph: {
indent: { left: 4320, hanging: 360 }, indent: { left: 4320, hanging: convertInchesToTwip(0.25) },
}, },
}, },
}, },
{ {
level: 6, level: 6,
format: "bullet", format: LevelFormat.BULLET,
text: "\u25CF", text: "\u25CF",
alignment: AlignmentType.LEFT, alignment: AlignmentType.LEFT,
style: { style: {
paragraph: { paragraph: {
indent: { left: 5040, hanging: 360 }, indent: { left: 5040, hanging: convertInchesToTwip(0.25) },
}, },
}, },
}, },
{ {
level: 7, level: 7,
format: "bullet", format: LevelFormat.BULLET,
text: "\u25CF", text: "\u25CF",
alignment: AlignmentType.LEFT, alignment: AlignmentType.LEFT,
style: { style: {
paragraph: { paragraph: {
indent: { left: 5760, hanging: 360 }, indent: { left: 5760, hanging: convertInchesToTwip(0.25) },
}, },
}, },
}, },
{ {
level: 8, level: 8,
format: "bullet", format: LevelFormat.BULLET,
text: "\u25CF", text: "\u25CF",
alignment: AlignmentType.LEFT, alignment: AlignmentType.LEFT,
style: { style: {
paragraph: { paragraph: {
indent: { left: 6480, hanging: 360 }, indent: { left: 6480, hanging: convertInchesToTwip(0.25) },
}, },
}, },
}, },

View File

@ -3,3 +3,4 @@ export * from "./paragraph";
export * from "./properties"; export * from "./properties";
export * from "./run"; export * from "./run";
export * from "./links"; export * from "./links";
export * from "./math";

View File

@ -0,0 +1,4 @@
export * from "./math-round-brackets";
export * from "./math-square-brackets";
export * from "./math-curly-brackets";
export * from "./math-angled-brackets";

View File

@ -0,0 +1,51 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathRun } from "../math-run";
import { MathAngledBrackets } from "./math-angled-brackets";
describe("MathAngledBrackets", () => {
describe("#constructor()", () => {
it("should create a MathAngledBrackets with correct root key", () => {
const mathAngledBrackets = new MathAngledBrackets({
children: [new MathRun("60")],
});
const tree = new Formatter().format(mathAngledBrackets);
expect(tree).to.deep.equal({
"m:d": [
{
"m:dPr": [
{
"m:begChr": {
_attr: {
"m:val": "〈",
},
},
},
{
"m:endChr": {
_attr: {
"m:val": "〉",
},
},
},
],
},
{
"m:e": [
{
"m:r": [
{
"m:t": ["60"],
},
],
},
],
},
],
});
});
});
});

View File

@ -0,0 +1,20 @@
// http://www.datypic.com/sc/ooxml/e-m_d-1.html
import { XmlComponent } from "file/xml-components";
import { MathComponent } from "../math-component";
import { MathBase } from "../n-ary";
import { MathBracketProperties } from "./math-bracket-properties";
export class MathAngledBrackets extends XmlComponent {
constructor(options: { readonly children: MathComponent[] }) {
super("m:d");
this.root.push(
new MathBracketProperties({
beginningCharacter: "〈",
endingCharacter: "〉",
}),
);
this.root.push(new MathBase(options.children));
}
}

View File

@ -0,0 +1,22 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathBeginningCharacter } from "./math-beginning-character";
describe("MathBeginningCharacter", () => {
describe("#constructor()", () => {
it("should create a MathBeginningCharacter with correct root key", () => {
const mathBeginningCharacter = new MathBeginningCharacter("[");
const tree = new Formatter().format(mathBeginningCharacter);
expect(tree).to.deep.equal({
"m:begChr": {
_attr: {
"m:val": "[",
},
},
});
});
});
});

View File

@ -0,0 +1,14 @@
// http://www.datypic.com/sc/ooxml/e-m_begChr-1.html
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
class MathBeginningCharacterAttributes extends XmlAttributeComponent<{ readonly character: string }> {
protected readonly xmlKeys = { character: "m:val" };
}
export class MathBeginningCharacter extends XmlComponent {
constructor(character: string) {
super("m:begChr");
this.root.push(new MathBeginningCharacterAttributes({ character }));
}
}

View File

@ -0,0 +1,45 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathBracketProperties } from "./math-bracket-properties";
describe("MathBracketProperties", () => {
describe("#constructor()", () => {
it("should create a MathBracketProperties with correct root key", () => {
const mathBracketProperties = new MathBracketProperties();
const tree = new Formatter().format(mathBracketProperties);
expect(tree).to.deep.equal({
"m:dPr": {},
});
});
it("should create a MathBracketProperties with correct root key and add brackets", () => {
const mathBracketProperties = new MathBracketProperties({
beginningCharacter: "[",
endingCharacter: "]",
});
const tree = new Formatter().format(mathBracketProperties);
expect(tree).to.deep.equal({
"m:dPr": [
{
"m:begChr": {
_attr: {
"m:val": "[",
},
},
},
{
"m:endChr": {
_attr: {
"m:val": "]",
},
},
},
],
});
});
});
});

View File

@ -0,0 +1,16 @@
// http://www.datypic.com/sc/ooxml/e-m_dPr-1.html
import { XmlComponent } from "file/xml-components";
import { MathBeginningCharacter } from "./math-beginning-character";
import { MathEndingCharacter } from "./math-ending-char";
export class MathBracketProperties extends XmlComponent {
constructor(options?: { readonly beginningCharacter: string; readonly endingCharacter: string }) {
super("m:dPr");
if (!!options) {
this.root.push(new MathBeginningCharacter(options.beginningCharacter));
this.root.push(new MathEndingCharacter(options.endingCharacter));
}
}
}

View File

@ -0,0 +1,51 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathRun } from "../math-run";
import { MathCurlyBrackets } from "./math-curly-brackets";
describe("MathCurlyBrackets", () => {
describe("#constructor()", () => {
it("should create a MathCurlyBrackets with correct root key", () => {
const mathCurlyBrackets = new MathCurlyBrackets({
children: [new MathRun("60")],
});
const tree = new Formatter().format(mathCurlyBrackets);
expect(tree).to.deep.equal({
"m:d": [
{
"m:dPr": [
{
"m:begChr": {
_attr: {
"m:val": "{",
},
},
},
{
"m:endChr": {
_attr: {
"m:val": "}",
},
},
},
],
},
{
"m:e": [
{
"m:r": [
{
"m:t": ["60"],
},
],
},
],
},
],
});
});
});
});

View File

@ -0,0 +1,20 @@
// http://www.datypic.com/sc/ooxml/e-m_d-1.html
import { XmlComponent } from "file/xml-components";
import { MathComponent } from "../math-component";
import { MathBase } from "../n-ary";
import { MathBracketProperties } from "./math-bracket-properties";
export class MathCurlyBrackets extends XmlComponent {
constructor(options: { readonly children: MathComponent[] }) {
super("m:d");
this.root.push(
new MathBracketProperties({
beginningCharacter: "{",
endingCharacter: "}",
}),
);
this.root.push(new MathBase(options.children));
}
}

View File

@ -0,0 +1,14 @@
// http://www.datypic.com/sc/ooxml/e-m_endChr-1.html
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
class MathEndingCharacterAttributes extends XmlAttributeComponent<{ readonly character: string }> {
protected readonly xmlKeys = { character: "m:val" };
}
export class MathEndingCharacter extends XmlComponent {
constructor(character: string) {
super("m:endChr");
this.root.push(new MathEndingCharacterAttributes({ character }));
}
}

View File

@ -0,0 +1,22 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathEndingCharacter } from "./math-ending-char";
describe("MathEndingCharacter", () => {
describe("#constructor()", () => {
it("should create a MathEndingCharacter with correct root key", () => {
const mathEndingCharacter = new MathEndingCharacter("]");
const tree = new Formatter().format(mathEndingCharacter);
expect(tree).to.deep.equal({
"m:endChr": {
_attr: {
"m:val": "]",
},
},
});
});
});
});

View File

@ -0,0 +1,36 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathRun } from "../math-run";
import { MathRoundBrackets } from "./math-round-brackets";
describe("MathRoundBrackets", () => {
describe("#constructor()", () => {
it("should create a MathRoundBrackets with correct root key", () => {
const mathRoundBrackets = new MathRoundBrackets({
children: [new MathRun("60")],
});
const tree = new Formatter().format(mathRoundBrackets);
expect(tree).to.deep.equal({
"m:d": [
{
"m:dPr": {},
},
{
"m:e": [
{
"m:r": [
{
"m:t": ["60"],
},
],
},
],
},
],
});
});
});
});

View File

@ -0,0 +1,15 @@
// http://www.datypic.com/sc/ooxml/e-m_d-1.html
import { XmlComponent } from "file/xml-components";
import { MathComponent } from "../math-component";
import { MathBase } from "../n-ary";
import { MathBracketProperties } from "./math-bracket-properties";
export class MathRoundBrackets extends XmlComponent {
constructor(options: { readonly children: MathComponent[] }) {
super("m:d");
this.root.push(new MathBracketProperties());
this.root.push(new MathBase(options.children));
}
}

View File

@ -0,0 +1,51 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathRun } from "../math-run";
import { MathSquareBrackets } from "./math-square-brackets";
describe("MathSquareBrackets", () => {
describe("#constructor()", () => {
it("should create a MathSquareBrackets with correct root key", () => {
const mathSquareBrackets = new MathSquareBrackets({
children: [new MathRun("60")],
});
const tree = new Formatter().format(mathSquareBrackets);
expect(tree).to.deep.equal({
"m:d": [
{
"m:dPr": [
{
"m:begChr": {
_attr: {
"m:val": "[",
},
},
},
{
"m:endChr": {
_attr: {
"m:val": "]",
},
},
},
],
},
{
"m:e": [
{
"m:r": [
{
"m:t": ["60"],
},
],
},
],
},
],
});
});
});
});

View File

@ -0,0 +1,20 @@
// http://www.datypic.com/sc/ooxml/e-m_d-1.html
import { XmlComponent } from "file/xml-components";
import { MathComponent } from "../math-component";
import { MathBase } from "../n-ary";
import { MathBracketProperties } from "./math-bracket-properties";
export class MathSquareBrackets extends XmlComponent {
constructor(options: { readonly children: MathComponent[] }) {
super("m:d");
this.root.push(
new MathBracketProperties({
beginningCharacter: "[",
endingCharacter: "]",
}),
);
this.root.push(new MathBase(options.children));
}
}

View File

@ -0,0 +1,3 @@
export * from "./math-fraction";
export * from "./math-denominator";
export * from "./math-numerator";

View File

@ -0,0 +1,26 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathRun } from "../math-run";
import { MathDenominator } from "./math-denominator";
describe("MathDenominator", () => {
describe("#constructor()", () => {
it("should create a MathDenominator with correct root key", () => {
const mathDenominator = new MathDenominator([new MathRun("2+2")]);
const tree = new Formatter().format(mathDenominator);
expect(tree).to.deep.equal({
"m:den": [
{
"m:r": [
{
"m:t": ["2+2"],
},
],
},
],
});
});
});
});

View File

@ -0,0 +1,13 @@
import { XmlComponent } from "file/xml-components";
import { MathComponent } from "../math-component";
export class MathDenominator extends XmlComponent {
constructor(children: MathComponent[]) {
super("m:den");
for (const child of children) {
this.root.push(child);
}
}
}

View File

@ -0,0 +1,44 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathRun } from "../math-run";
import { MathFraction } from "./math-fraction";
describe("MathFraction", () => {
describe("#constructor()", () => {
it("should create a MathFraction with correct root key", () => {
const mathFraction = new MathFraction({
numerator: [new MathRun("2")],
denominator: [new MathRun("2")],
});
const tree = new Formatter().format(mathFraction);
expect(tree).to.deep.equal({
"m:f": [
{
"m:num": [
{
"m:r": [
{
"m:t": ["2"],
},
],
},
],
},
{
"m:den": [
{
"m:r": [
{
"m:t": ["2"],
},
],
},
],
},
],
});
});
});
});

View File

@ -0,0 +1,19 @@
import { XmlComponent } from "file/xml-components";
import { MathComponent } from "../math-component";
import { MathDenominator } from "./math-denominator";
import { MathNumerator } from "./math-numerator";
export interface IMathFractionOptions {
readonly numerator: MathComponent[];
readonly denominator: MathComponent[];
}
export class MathFraction extends XmlComponent {
constructor(options: IMathFractionOptions) {
super("m:f");
this.root.push(new MathNumerator(options.numerator));
this.root.push(new MathDenominator(options.denominator));
}
}

View File

@ -0,0 +1,26 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathRun } from "../math-run";
import { MathNumerator } from "./math-numerator";
describe("MathNumerator", () => {
describe("#constructor()", () => {
it("should create a MathNumerator with correct root key", () => {
const mathNumerator = new MathNumerator([new MathRun("2+2")]);
const tree = new Formatter().format(mathNumerator);
expect(tree).to.deep.equal({
"m:num": [
{
"m:r": [
{
"m:t": ["2+2"],
},
],
},
],
});
});
});
});

View File

@ -0,0 +1,13 @@
import { XmlComponent } from "file/xml-components";
import { MathComponent } from "../math-component";
export class MathNumerator extends XmlComponent {
constructor(children: MathComponent[]) {
super("m:num");
for (const child of children) {
this.root.push(child);
}
}
}

View File

@ -0,0 +1,3 @@
export * from "./math-function";
export * from "./math-function-name";
export * from "./math-function-properties";

View File

@ -0,0 +1,27 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathRun } from "../math-run";
import { MathFunctionName } from "./math-function-name";
describe("MathFunctionName", () => {
describe("#constructor()", () => {
it("should create a MathFunctionName with correct root key", () => {
const mathFunctionName = new MathFunctionName([new MathRun("2")]);
const tree = new Formatter().format(mathFunctionName);
expect(tree).to.deep.equal({
"m:fName": [
{
"m:r": [
{
"m:t": ["2"],
},
],
},
],
});
});
});
});

View File

@ -0,0 +1,13 @@
// http://www.datypic.com/sc/ooxml/e-m_fName-1.html
import { XmlComponent } from "file/xml-components";
import { MathComponent } from "../math-component";
export class MathFunctionName extends XmlComponent {
constructor(children: MathComponent[]) {
super("m:fName");
for (const child of children) {
this.root.push(child);
}
}
}

Some files were not shown because too many files have changed in this diff Show More