Compare commits
69 Commits
Author | SHA1 | Date | |
---|---|---|---|
d6f363b275 | |||
118ea57412 | |||
7c8be4c8a7 | |||
fa9021596f | |||
3ccf4bdfe3 | |||
f2480673ec | |||
e93b8032d8 | |||
5de2d8c7fb | |||
e355fd3d2e | |||
d41ef99c85 | |||
5ec18d6e01 | |||
b4cd3a319c | |||
d894bfa167 | |||
d74db948ba | |||
3ef26c747b | |||
38c8220e9e | |||
86f8259b33 | |||
502db14bba | |||
ef12ada5d7 | |||
977b2b302d | |||
17d02a3d1c | |||
6100ff4c4e | |||
8bb73fb25e | |||
d6cce4ae15 | |||
058304d16b | |||
345d34a2e1 | |||
3839a49d47 | |||
0afe0929a3 | |||
a14a1fbd10 | |||
52f0a6958a | |||
8bdde98db1 | |||
19fc900045 | |||
6bdd9b882a | |||
0d97d428fa | |||
a0b42d7bdb | |||
69ba312a96 | |||
a0c13214e6 | |||
4c8829df28 | |||
3ee3e95410 | |||
806deeaf78 | |||
feb121707d | |||
31c7f034ec | |||
30ab92652c | |||
0407548113 | |||
277845626c | |||
b2af8b970e | |||
542866e18b | |||
f54192809f | |||
f3ba62fd88 | |||
8d4a07302b | |||
d504231124 | |||
173b1e118c | |||
ffba276f0d | |||
b210608e56 | |||
74353104dc | |||
825136d1c9 | |||
b2fea471f1 | |||
e9adb8b0ed | |||
5d6bc039d0 | |||
27638063c8 | |||
f6a4d78ab7 | |||
4061e31400 | |||
74db67689f | |||
2213eb28cb | |||
d1b45d416b | |||
f72f7e7514 | |||
0165cfb3e5 | |||
ef747486c0 | |||
e0b2f59c2f |
@ -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
104
.github/workflows/default.yml
vendored
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
name: Default
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Build
|
||||||
|
run: npm run build
|
||||||
|
- name: Archive Production Artifact
|
||||||
|
uses: actions/upload-artifact@master
|
||||||
|
with:
|
||||||
|
name: build
|
||||||
|
path: build
|
||||||
|
test:
|
||||||
|
name: Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Test
|
||||||
|
run: npm run test.coverage
|
||||||
|
lint:
|
||||||
|
name: Lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Lint
|
||||||
|
run: npm run lint
|
||||||
|
prettier:
|
||||||
|
name: Prettier
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Prettier
|
||||||
|
run: npm run style
|
||||||
|
demos:
|
||||||
|
name: Run Demos
|
||||||
|
needs: [build]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Download Artifact
|
||||||
|
uses: actions/download-artifact@master
|
||||||
|
with:
|
||||||
|
name: build
|
||||||
|
path: build
|
||||||
|
- name: Run demos
|
||||||
|
run: |
|
||||||
|
npm run ts-node -- ./demo/1-basic.ts
|
||||||
|
npm run ts-node -- ./demo/2-declaritive-styles.ts
|
||||||
|
npm run ts-node -- ./demo/3-numbering-and-bullet-points.ts
|
||||||
|
npm run ts-node -- ./demo/4-basic-table.ts
|
||||||
|
npm run ts-node -- ./demo/5-images.ts
|
||||||
|
npm run ts-node -- ./demo/6-page-borders.ts
|
||||||
|
npm run ts-node -- ./demo/7-landscape.ts
|
||||||
|
npm run ts-node -- ./demo/8-header-footer.ts
|
||||||
|
npm run ts-node -- ./demo/9-images-in-header-and-footer.ts
|
||||||
|
npm run ts-node -- ./demo/10-my-cv.ts
|
||||||
|
npm run ts-node -- ./demo/11-declaritive-styles-2.ts
|
||||||
|
npm run ts-node -- ./demo/12-scaling-images.ts
|
||||||
|
npm run ts-node -- ./demo/13-xml-styles.ts
|
||||||
|
npm run ts-node -- ./demo/14-page-numbers.ts
|
||||||
|
npm run ts-node -- ./demo/15-page-break-before.ts
|
||||||
|
npm run ts-node -- ./demo/16-multiple-sections.ts
|
||||||
|
npm run ts-node -- ./demo/17-footnotes.ts
|
||||||
|
npm run ts-node -- ./demo/18-image-from-buffer.ts
|
||||||
|
npm run ts-node -- ./demo/19-export-to-base64.ts
|
||||||
|
npm run ts-node -- ./demo/20-table-cell-borders.ts
|
||||||
|
npm run ts-node -- ./demo/21-bookmarks.ts
|
||||||
|
npm run ts-node -- ./demo/22-right-to-left-text.ts
|
||||||
|
npm run ts-node -- ./demo/23-base64-images.ts
|
||||||
|
npm run ts-node -- ./demo/24-images-to-table-cell.ts
|
||||||
|
npm run ts-node -- ./demo/26-paragraph-borders.ts
|
||||||
|
npm run ts-node -- ./demo/27-declaritive-styles-3.ts
|
||||||
|
npm run ts-node -- ./demo/28-table-of-contents.ts
|
||||||
|
npm run ts-node -- ./demo/29-numbered-lists.ts
|
||||||
|
npm run ts-node -- ./demo/30-template-document.ts
|
||||||
|
npm run ts-node -- ./demo/31-tables.ts
|
||||||
|
npm run ts-node -- ./demo/32-merge-and-shade-table-cells.ts
|
||||||
|
npm run ts-node -- ./demo/33-sequential-captions.ts
|
||||||
|
npm run ts-node -- ./demo/34-floating-tables.ts
|
@ -11,6 +11,7 @@
|
|||||||
[![NPM version][npm-image]][npm-url]
|
[![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]
|
||||||
@ -85,6 +86,7 @@ Read the contribution guidelines [here](https://docx.js.org/#/contribution-guide
|
|||||||
[<img src="https://i.imgur.com/QEZXU5b.png" alt="drawing" height="50"/>](https://www.beekast.com/)
|
[<img src="https://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!
|
||||||
@ -102,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
|
||||||
|
@ -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,
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -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,
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -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,
|
||||||
},
|
},
|
||||||
@ -170,6 +171,17 @@ doc.addSection({
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
style: "Strong",
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Strong Style",
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: " - Very strong.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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,
|
||||||
|
@ -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,
|
||||||
|
},
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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: {
|
||||||
|
@ -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, BorderStyle, 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),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -355,9 +368,7 @@ const table8 = new Table({
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
new TableRow({
|
new TableRow({
|
||||||
children: [
|
children: [new TableCell({ children: [new Paragraph("4,1")] })],
|
||||||
new TableCell({ children: [new Paragraph("4,1")] }),
|
|
||||||
],
|
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
width: {
|
width: {
|
||||||
|
@ -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);
|
||||||
|
@ -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,
|
||||||
|
@ -15,6 +15,14 @@ const doc = new Document({
|
|||||||
italics: true,
|
italics: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "strong",
|
||||||
|
name: "Strong",
|
||||||
|
basedOn: "Normal",
|
||||||
|
run: {
|
||||||
|
bold: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -29,6 +37,18 @@ doc.addSection({
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
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.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -80,6 +80,7 @@ doc.addSection({
|
|||||||
children: [
|
children: [
|
||||||
new TextRun("This is a demo "),
|
new TextRun("This is a demo "),
|
||||||
new DeletedTextRun({
|
new DeletedTextRun({
|
||||||
|
break: 1,
|
||||||
text: "in order",
|
text: "in order",
|
||||||
color: "red",
|
color: "red",
|
||||||
bold: true,
|
bold: true,
|
||||||
@ -95,7 +96,7 @@ doc.addSection({
|
|||||||
id: 2,
|
id: 2,
|
||||||
author: "Firstname Lastname",
|
author: "Firstname Lastname",
|
||||||
date: "2020-10-06T09:00:00Z",
|
date: "2020-10-06T09:00:00Z",
|
||||||
}).break(),
|
}),
|
||||||
new InsertedTextRun({
|
new InsertedTextRun({
|
||||||
text: "to show how to ",
|
text: "to show how to ",
|
||||||
bold: false,
|
bold: false,
|
||||||
|
88
demo/57-add-parent-numbered-lists.ts
Normal file
88
demo/57-add-parent-numbered-lists.ts
Normal 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);
|
||||||
|
});
|
@ -28,5 +28,8 @@
|
|||||||
* 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)
|
||||||
|
@ -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
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
22
docs/usage/convenience-functions.md
Normal file
22
docs/usage/convenience-functions.md
Normal 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
|
||||||
|
```
|
@ -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:
|
||||||
|
|
||||||
|
@ -158,6 +158,15 @@ Sometimes you would want to put text underneath another line of text but inside
|
|||||||
```ts
|
```ts
|
||||||
const text = new TextRun({
|
const text = new TextRun({
|
||||||
text: "break",
|
text: "break",
|
||||||
break: true,
|
break: 1,
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Adding two breaks:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const text = new TextRun({
|
||||||
|
text: "break",
|
||||||
|
break: 2,
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
679
package-lock.json
generated
679
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "docx",
|
"name": "docx",
|
||||||
"version": "5.4.0",
|
"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": {
|
||||||
|
18
src/convenience-functions.spec.ts
Normal file
18
src/convenience-functions.spec.ts
Normal 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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
8
src/convenience-functions.ts
Normal file
8
src/convenience-functions.ts
Normal 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);
|
||||||
|
};
|
@ -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),
|
||||||
},
|
},
|
||||||
|
@ -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,
|
||||||
|
@ -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,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -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 = {
|
export class Anchor extends XmlComponent {
|
||||||
|
constructor(mediaData: IMediaData, dimensions: IMediaDataDimensions, drawingOptions: IDrawingOptions) {
|
||||||
|
super("wp:anchor");
|
||||||
|
|
||||||
|
const floating: IFloating = {
|
||||||
allowOverlap: true,
|
allowOverlap: true,
|
||||||
behindDocument: false,
|
behindDocument: false,
|
||||||
lockAnchor: false,
|
lockAnchor: false,
|
||||||
layoutInCell: true,
|
layoutInCell: true,
|
||||||
verticalPosition: {},
|
verticalPosition: {},
|
||||||
horizontalPosition: {},
|
horizontalPosition: {},
|
||||||
};
|
|
||||||
|
|
||||||
export class Anchor extends XmlComponent {
|
|
||||||
constructor(mediaData: IMediaData, dimensions: IMediaDataDimensions, drawingOptions: IDrawingOptions) {
|
|
||||||
super("wp:anchor");
|
|
||||||
|
|
||||||
const floating = {
|
|
||||||
margins: {
|
|
||||||
top: 0,
|
|
||||||
bottom: 0,
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
},
|
|
||||||
...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,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
|
@ -7,7 +7,7 @@ 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 { LevelSuffix } from "./level";
|
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", () => {
|
||||||
@ -20,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,
|
||||||
},
|
},
|
||||||
@ -29,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)" } } });
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -37,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)",
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@ -45,7 +45,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": "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)" } } });
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -53,7 +53,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,
|
||||||
suffix: LevelSuffix.SPACE,
|
suffix: LevelSuffix.SPACE,
|
||||||
@ -68,7 +68,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: {
|
||||||
@ -87,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: {
|
||||||
@ -106,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: {
|
||||||
@ -125,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: {
|
||||||
@ -144,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: {
|
||||||
@ -163,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: {
|
||||||
@ -182,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: {
|
||||||
@ -216,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: {
|
||||||
@ -239,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: {
|
||||||
@ -262,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: {
|
||||||
@ -281,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: {
|
||||||
@ -324,7 +324,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: { size, sizeComplexScript },
|
run: { size, sizeComplexScript },
|
||||||
@ -340,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: {
|
||||||
@ -359,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: {
|
||||||
@ -378,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: {
|
||||||
@ -398,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: {
|
||||||
@ -417,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: {
|
||||||
@ -436,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: {
|
||||||
@ -455,7 +455,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: {
|
||||||
@ -485,7 +485,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: {
|
||||||
@ -533,7 +533,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: { bold, boldComplexScript },
|
run: { bold, boldComplexScript },
|
||||||
@ -566,7 +566,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: { italics, italicsComplexScript },
|
run: { italics, italicsComplexScript },
|
||||||
@ -604,7 +604,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: { highlight, highlightComplexScript },
|
run: { highlight, highlightComplexScript },
|
||||||
@ -682,7 +682,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: { shadow, shading, shadingComplexScript },
|
run: { shadow, shading, shadingComplexScript },
|
||||||
@ -699,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: {
|
||||||
@ -718,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: {
|
||||||
@ -739,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: {
|
||||||
@ -763,7 +763,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: {
|
||||||
@ -782,7 +782,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: {
|
||||||
@ -804,7 +804,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: {
|
||||||
|
@ -1,8 +1,26 @@
|
|||||||
|
// http://officeopenxml.com/WPnumbering-numFmt.php
|
||||||
import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||||
import { AlignmentType } from "../paragraph/formatting";
|
import { AlignmentType } from "../paragraph/formatting";
|
||||||
import { IParagraphStylePropertiesOptions, ParagraphProperties } from "../paragraph/properties";
|
import { IParagraphStylePropertiesOptions, ParagraphProperties } from "../paragraph/properties";
|
||||||
import { IRunStylePropertiesOptions, RunProperties } from "../paragraph/run/properties";
|
import { IRunStylePropertiesOptions, RunProperties } from "../paragraph/run/properties";
|
||||||
|
|
||||||
|
export enum LevelFormat {
|
||||||
|
BULLET = "bullet",
|
||||||
|
CARDINAL_TEXT = "cardinalText",
|
||||||
|
CHICAGO = "chicago",
|
||||||
|
DECIMAL = "decimal",
|
||||||
|
DECIMAL_ENCLOSED_CIRCLE = "decimalEnclosedCircle",
|
||||||
|
DECIMAL_ENCLOSED_FULLSTOP = "decimalEnclosedFullstop",
|
||||||
|
DECIMAL_ENCLOSED_PARENTHESES = "decimalEnclosedParen",
|
||||||
|
DECIMAL_ZERO = "decimalZero",
|
||||||
|
LOWER_LETTER = "lowerLetter",
|
||||||
|
LOWER_ROMAN = "lowerRoman",
|
||||||
|
NONE = "none",
|
||||||
|
ORDINAL_TEXT = "ordinalText",
|
||||||
|
UPPER_LETTER = "upperLetter",
|
||||||
|
UPPER_ROMAN = "upperRoman",
|
||||||
|
}
|
||||||
|
|
||||||
interface ILevelAttributesProperties {
|
interface ILevelAttributesProperties {
|
||||||
readonly ilvl?: number;
|
readonly ilvl?: number;
|
||||||
readonly tentative?: number;
|
readonly tentative?: number;
|
||||||
@ -67,7 +85,7 @@ 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;
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
// 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 {
|
||||||
@ -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) },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -19,3 +19,9 @@ export type MathComponent =
|
|||||||
| MathCurlyBrackets
|
| MathCurlyBrackets
|
||||||
| MathAngledBrackets
|
| MathAngledBrackets
|
||||||
| MathSquareBrackets;
|
| MathSquareBrackets;
|
||||||
|
|
||||||
|
// Needed because of: https://github.com/s-panferov/awesome-typescript-loader/issues/432
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
export const WORKAROUND4 = "";
|
||||||
|
@ -239,13 +239,29 @@ describe("Run", () => {
|
|||||||
|
|
||||||
describe("#break()", () => {
|
describe("#break()", () => {
|
||||||
it("it should add break to the run", () => {
|
it("it should add break to the run", () => {
|
||||||
const run = new Run({});
|
const run = new Run({
|
||||||
run.break();
|
break: 1,
|
||||||
|
});
|
||||||
const tree = new Formatter().format(run);
|
const tree = new Formatter().format(run);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:r": [{ "w:br": {} }],
|
"w:r": [{ "w:br": {} }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("it should add two breaks to the run", () => {
|
||||||
|
const run = new Run({
|
||||||
|
break: 2,
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(run);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [
|
||||||
|
{ "w:br": {} },
|
||||||
|
{
|
||||||
|
"w:br": {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#font()", () => {
|
describe("#font()", () => {
|
||||||
|
@ -11,6 +11,7 @@ import { Text } from "./run-components/text";
|
|||||||
|
|
||||||
export interface IRunOptions extends IRunPropertiesOptions {
|
export interface IRunOptions extends IRunPropertiesOptions {
|
||||||
readonly children?: (Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | string)[];
|
readonly children?: (Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | string)[];
|
||||||
|
readonly break?: number;
|
||||||
readonly text?: string;
|
readonly text?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,10 +63,11 @@ export class Run extends XmlComponent {
|
|||||||
} else if (options.text) {
|
} else if (options.text) {
|
||||||
this.root.push(new Text(options.text));
|
this.root.push(new Text(options.text));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public break(): Run {
|
if (options.break) {
|
||||||
|
for (let i = 0; i < options.break; i++) {
|
||||||
this.root.splice(1, 0, new Break());
|
this.root.splice(1, 0, new Break());
|
||||||
return this;
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { DocumentAttributes } from "../document/document-attributes";
|
import { DocumentAttributes } from "../document/document-attributes";
|
||||||
import { IStylesOptions } from "./styles";
|
import { IStylesOptions } from "./styles";
|
||||||
|
|
||||||
import { DocumentDefaults } from "./defaults";
|
import { DocumentDefaults, IDocumentDefaultsOptions } from "./defaults";
|
||||||
import {
|
import {
|
||||||
FootnoteReferenceStyle,
|
FootnoteReferenceStyle,
|
||||||
FootnoteText,
|
FootnoteText,
|
||||||
@ -13,12 +13,32 @@ import {
|
|||||||
Heading5Style,
|
Heading5Style,
|
||||||
Heading6Style,
|
Heading6Style,
|
||||||
HyperlinkStyle,
|
HyperlinkStyle,
|
||||||
|
IBaseCharacterStyleOptions,
|
||||||
|
IBaseParagraphStyleOptions,
|
||||||
ListParagraph,
|
ListParagraph,
|
||||||
|
StrongStyle,
|
||||||
TitleStyle,
|
TitleStyle,
|
||||||
} from "./style";
|
} from "./style";
|
||||||
|
|
||||||
|
export interface IDefaultStylesOptions {
|
||||||
|
readonly document?: IDocumentDefaultsOptions;
|
||||||
|
readonly title?: IBaseParagraphStyleOptions;
|
||||||
|
readonly heading1?: IBaseParagraphStyleOptions;
|
||||||
|
readonly heading2?: IBaseParagraphStyleOptions;
|
||||||
|
readonly heading3?: IBaseParagraphStyleOptions;
|
||||||
|
readonly heading4?: IBaseParagraphStyleOptions;
|
||||||
|
readonly heading5?: IBaseParagraphStyleOptions;
|
||||||
|
readonly heading6?: IBaseParagraphStyleOptions;
|
||||||
|
readonly strong?: IBaseParagraphStyleOptions;
|
||||||
|
readonly listParagraph?: IBaseParagraphStyleOptions;
|
||||||
|
readonly hyperlink?: IBaseCharacterStyleOptions;
|
||||||
|
readonly footnoteReference?: IBaseCharacterStyleOptions;
|
||||||
|
readonly footnoteText?: IBaseParagraphStyleOptions;
|
||||||
|
readonly footnoteTextChar?: IBaseCharacterStyleOptions;
|
||||||
|
}
|
||||||
|
|
||||||
export class DefaultStylesFactory {
|
export class DefaultStylesFactory {
|
||||||
public newInstance(): IStylesOptions {
|
public newInstance(options: IDefaultStylesOptions = {}): IStylesOptions {
|
||||||
const documentAttributes = new DocumentAttributes({
|
const documentAttributes = new DocumentAttributes({
|
||||||
mc: "http://schemas.openxmlformats.org/markup-compatibility/2006",
|
mc: "http://schemas.openxmlformats.org/markup-compatibility/2006",
|
||||||
r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
||||||
@ -30,51 +50,64 @@ export class DefaultStylesFactory {
|
|||||||
return {
|
return {
|
||||||
initialStyles: documentAttributes,
|
initialStyles: documentAttributes,
|
||||||
importedStyles: [
|
importedStyles: [
|
||||||
new DocumentDefaults(),
|
new DocumentDefaults(options.document),
|
||||||
new TitleStyle({
|
new TitleStyle({
|
||||||
run: {
|
run: {
|
||||||
size: 56,
|
size: 56,
|
||||||
},
|
},
|
||||||
|
...options.title,
|
||||||
}),
|
}),
|
||||||
new Heading1Style({
|
new Heading1Style({
|
||||||
run: {
|
run: {
|
||||||
color: "2E74B5",
|
color: "2E74B5",
|
||||||
size: 32,
|
size: 32,
|
||||||
},
|
},
|
||||||
|
...options.heading1,
|
||||||
}),
|
}),
|
||||||
new Heading2Style({
|
new Heading2Style({
|
||||||
run: {
|
run: {
|
||||||
color: "2E74B5",
|
color: "2E74B5",
|
||||||
size: 26,
|
size: 26,
|
||||||
},
|
},
|
||||||
|
...options.heading2,
|
||||||
}),
|
}),
|
||||||
new Heading3Style({
|
new Heading3Style({
|
||||||
run: {
|
run: {
|
||||||
color: "1F4D78",
|
color: "1F4D78",
|
||||||
size: 24,
|
size: 24,
|
||||||
},
|
},
|
||||||
|
...options.heading3,
|
||||||
}),
|
}),
|
||||||
new Heading4Style({
|
new Heading4Style({
|
||||||
run: {
|
run: {
|
||||||
color: "2E74B5",
|
color: "2E74B5",
|
||||||
italics: true,
|
italics: true,
|
||||||
},
|
},
|
||||||
|
...options.heading4,
|
||||||
}),
|
}),
|
||||||
new Heading5Style({
|
new Heading5Style({
|
||||||
run: {
|
run: {
|
||||||
color: "2E74B5",
|
color: "2E74B5",
|
||||||
},
|
},
|
||||||
|
...options.heading5,
|
||||||
}),
|
}),
|
||||||
new Heading6Style({
|
new Heading6Style({
|
||||||
run: {
|
run: {
|
||||||
color: "1F4D78",
|
color: "1F4D78",
|
||||||
},
|
},
|
||||||
|
...options.heading6,
|
||||||
}),
|
}),
|
||||||
new ListParagraph({}),
|
new StrongStyle({
|
||||||
new HyperlinkStyle({}),
|
run: {
|
||||||
new FootnoteReferenceStyle({}),
|
bold: true,
|
||||||
new FootnoteText({}),
|
},
|
||||||
new FootnoteTextChar({}),
|
...options.strong,
|
||||||
|
}),
|
||||||
|
new ListParagraph(options.listParagraph || {}),
|
||||||
|
new HyperlinkStyle(options.hyperlink || {}),
|
||||||
|
new FootnoteReferenceStyle(options.footnoteReference || {}),
|
||||||
|
new FootnoteText(options.footnoteText || {}),
|
||||||
|
new FootnoteTextChar(options.footnoteTextChar || {}),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,12 @@ import { UnderlineType } from "file/paragraph/run/underline";
|
|||||||
import { ShadingType } from "file/table";
|
import { ShadingType } from "file/table";
|
||||||
import { EMPTY_OBJECT } from "file/xml-components";
|
import { EMPTY_OBJECT } from "file/xml-components";
|
||||||
|
|
||||||
import { CharacterStyle } from "./character-style";
|
import { StyleForCharacter } from "./character-style";
|
||||||
|
|
||||||
describe("CharacterStyle", () => {
|
describe("CharacterStyle", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
it("should set the style type to character and use the given style id", () => {
|
it("should set the style type to character and use the given style id", () => {
|
||||||
const style = new CharacterStyle({ id: "myStyleId" });
|
const style = new StyleForCharacter({ id: "myStyleId" });
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
@ -31,7 +31,7 @@ describe("CharacterStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should set the name of the style, if given", () => {
|
it("should set the name of the style, if given", () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
name: "Style Name",
|
name: "Style Name",
|
||||||
});
|
});
|
||||||
@ -55,7 +55,7 @@ describe("CharacterStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should add smallCaps", () => {
|
it("should add smallCaps", () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
smallCaps: true,
|
smallCaps: true,
|
||||||
@ -83,7 +83,7 @@ describe("CharacterStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should add allCaps", () => {
|
it("should add allCaps", () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
allCaps: true,
|
allCaps: true,
|
||||||
@ -111,7 +111,7 @@ describe("CharacterStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should add strike", () => {
|
it("should add strike", () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
strike: true,
|
strike: true,
|
||||||
@ -139,7 +139,7 @@ describe("CharacterStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should add double strike", () => {
|
it("should add double strike", () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
doubleStrike: true,
|
doubleStrike: true,
|
||||||
@ -167,7 +167,7 @@ describe("CharacterStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should add sub script", () => {
|
it("should add sub script", () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
subScript: true,
|
subScript: true,
|
||||||
@ -203,7 +203,7 @@ describe("CharacterStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should add font by name", () => {
|
it("should add font by name", () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
font: "test font",
|
font: "test font",
|
||||||
@ -242,7 +242,7 @@ describe("CharacterStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should add font for ascii and eastAsia", () => {
|
it("should add font for ascii and eastAsia", () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
font: {
|
font: {
|
||||||
@ -282,7 +282,7 @@ describe("CharacterStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should add character spacing", () => {
|
it("should add character spacing", () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
characterSpacing: 100,
|
characterSpacing: 100,
|
||||||
@ -312,7 +312,7 @@ describe("CharacterStyle", () => {
|
|||||||
|
|
||||||
describe("formatting methods: style attributes", () => {
|
describe("formatting methods: style attributes", () => {
|
||||||
it("#basedOn", () => {
|
it("#basedOn", () => {
|
||||||
const style = new CharacterStyle({ id: "myStyleId", basedOn: "otherId" });
|
const style = new StyleForCharacter({ id: "myStyleId", basedOn: "otherId" });
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
@ -357,7 +357,7 @@ describe("CharacterStyle", () => {
|
|||||||
];
|
];
|
||||||
sizeTests.forEach(({ size, sizeComplexScript, expected }) => {
|
sizeTests.forEach(({ size, sizeComplexScript, expected }) => {
|
||||||
it(`#size ${size} cs ${sizeComplexScript}`, () => {
|
it(`#size ${size} cs ${sizeComplexScript}`, () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: { size, sizeComplexScript },
|
run: { size, sizeComplexScript },
|
||||||
});
|
});
|
||||||
@ -385,7 +385,7 @@ describe("CharacterStyle", () => {
|
|||||||
|
|
||||||
describe("#underline", () => {
|
describe("#underline", () => {
|
||||||
it("should set underline to 'single' if no arguments are given", () => {
|
it("should set underline to 'single' if no arguments are given", () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
underline: {},
|
underline: {},
|
||||||
@ -413,7 +413,7 @@ describe("CharacterStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should set the style if given", () => {
|
it("should set the style if given", () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
underline: {
|
underline: {
|
||||||
@ -443,7 +443,7 @@ describe("CharacterStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should set the style and color if given", () => {
|
it("should set the style and color if given", () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
underline: {
|
underline: {
|
||||||
@ -476,7 +476,7 @@ describe("CharacterStyle", () => {
|
|||||||
|
|
||||||
describe("#emphasisMark", () => {
|
describe("#emphasisMark", () => {
|
||||||
it("should set emphasisMark to 'dot' if no arguments are given", () => {
|
it("should set emphasisMark to 'dot' if no arguments are given", () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
emphasisMark: {},
|
emphasisMark: {},
|
||||||
@ -504,7 +504,7 @@ describe("CharacterStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should set the style if given", () => {
|
it("should set the style if given", () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
emphasisMark: {
|
emphasisMark: {
|
||||||
@ -535,7 +535,7 @@ describe("CharacterStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#superScript", () => {
|
it("#superScript", () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
superScript: true,
|
superScript: true,
|
||||||
@ -571,7 +571,7 @@ describe("CharacterStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#color", () => {
|
it("#color", () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
color: "123456",
|
color: "123456",
|
||||||
@ -616,7 +616,7 @@ describe("CharacterStyle", () => {
|
|||||||
];
|
];
|
||||||
boldTests.forEach(({ bold, boldComplexScript, expected }) => {
|
boldTests.forEach(({ bold, boldComplexScript, expected }) => {
|
||||||
it(`#bold ${bold} cs ${boldComplexScript}`, () => {
|
it(`#bold ${bold} cs ${boldComplexScript}`, () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: { bold, boldComplexScript },
|
run: { bold, boldComplexScript },
|
||||||
});
|
});
|
||||||
@ -660,7 +660,7 @@ describe("CharacterStyle", () => {
|
|||||||
];
|
];
|
||||||
italicsTests.forEach(({ italics, italicsComplexScript, expected }) => {
|
italicsTests.forEach(({ italics, italicsComplexScript, expected }) => {
|
||||||
it(`#italics ${italics} cs ${italicsComplexScript}`, () => {
|
it(`#italics ${italics} cs ${italicsComplexScript}`, () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: { italics, italicsComplexScript },
|
run: { italics, italicsComplexScript },
|
||||||
});
|
});
|
||||||
@ -687,7 +687,7 @@ describe("CharacterStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#link", () => {
|
it("#link", () => {
|
||||||
const style = new CharacterStyle({ id: "myStyleId", link: "MyLink" });
|
const style = new StyleForCharacter({ id: "myStyleId", link: "MyLink" });
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
@ -708,7 +708,7 @@ describe("CharacterStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#semiHidden", () => {
|
it("#semiHidden", () => {
|
||||||
const style = new CharacterStyle({ id: "myStyleId", semiHidden: true });
|
const style = new StyleForCharacter({ id: "myStyleId", semiHidden: true });
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
@ -749,7 +749,7 @@ describe("CharacterStyle", () => {
|
|||||||
];
|
];
|
||||||
highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => {
|
highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => {
|
||||||
it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => {
|
it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: { highlight, highlightComplexScript },
|
run: { highlight, highlightComplexScript },
|
||||||
});
|
});
|
||||||
@ -838,7 +838,7 @@ describe("CharacterStyle", () => {
|
|||||||
];
|
];
|
||||||
shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => {
|
shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => {
|
||||||
it("#shadow correctly", () => {
|
it("#shadow correctly", () => {
|
||||||
const style = new CharacterStyle({
|
const style = new StyleForCharacter({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: { shadow, shading, shadingComplexScript },
|
run: { shadow, shading, shadingComplexScript },
|
||||||
});
|
});
|
||||||
|
@ -15,7 +15,7 @@ export interface ICharacterStyleOptions extends IBaseCharacterStyleOptions {
|
|||||||
readonly name?: string;
|
readonly name?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CharacterStyle extends Style {
|
export class StyleForCharacter extends Style {
|
||||||
private readonly runProperties: RunProperties;
|
private readonly runProperties: RunProperties;
|
||||||
|
|
||||||
constructor(options: ICharacterStyleOptions) {
|
constructor(options: ICharacterStyleOptions) {
|
||||||
|
@ -120,6 +120,20 @@ describe("Default Styles", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("StrongStyle#constructor", () => {
|
||||||
|
const style = new defaultStyles.StrongStyle({});
|
||||||
|
const tree = new Formatter().format(style);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:style": [
|
||||||
|
{ _attr: { "w:type": "paragraph", "w:styleId": "Strong" } },
|
||||||
|
{ "w:name": { _attr: { "w:val": "Strong" } } },
|
||||||
|
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||||
|
{ "w:next": { _attr: { "w:val": "Normal" } } },
|
||||||
|
{ "w:qFormat": EMPTY_OBJECT },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("ListParagraph#constructor", () => {
|
it("ListParagraph#constructor", () => {
|
||||||
const style = new defaultStyles.ListParagraph({});
|
const style = new defaultStyles.ListParagraph({});
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { UnderlineType } from "file/paragraph/run/underline";
|
import { UnderlineType } from "file/paragraph/run/underline";
|
||||||
|
|
||||||
import { CharacterStyle, IBaseCharacterStyleOptions } from "./character-style";
|
import { IBaseCharacterStyleOptions, StyleForCharacter } from "./character-style";
|
||||||
import { IBaseParagraphStyleOptions, IParagraphStyleOptions, ParagraphStyle } from "./paragraph-style";
|
import { IBaseParagraphStyleOptions, IParagraphStyleOptions, StyleForParagraph } from "./paragraph-style";
|
||||||
|
|
||||||
export class HeadingStyle extends ParagraphStyle {
|
export class HeadingStyle extends StyleForParagraph {
|
||||||
constructor(options: IParagraphStyleOptions) {
|
constructor(options: IParagraphStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
...options,
|
||||||
@ -84,7 +84,17 @@ export class Heading6Style extends HeadingStyle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ListParagraph extends ParagraphStyle {
|
export class StrongStyle extends HeadingStyle {
|
||||||
|
constructor(options: IBaseParagraphStyleOptions) {
|
||||||
|
super({
|
||||||
|
...options,
|
||||||
|
id: "Strong",
|
||||||
|
name: "Strong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ListParagraph extends StyleForParagraph {
|
||||||
constructor(options: IBaseParagraphStyleOptions) {
|
constructor(options: IBaseParagraphStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
...options,
|
||||||
@ -96,7 +106,7 @@ export class ListParagraph extends ParagraphStyle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FootnoteText extends ParagraphStyle {
|
export class FootnoteText extends StyleForParagraph {
|
||||||
constructor(options: IBaseParagraphStyleOptions) {
|
constructor(options: IBaseParagraphStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
...options,
|
||||||
@ -121,7 +131,7 @@ export class FootnoteText extends ParagraphStyle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FootnoteReferenceStyle extends CharacterStyle {
|
export class FootnoteReferenceStyle extends StyleForCharacter {
|
||||||
constructor(options: IBaseCharacterStyleOptions) {
|
constructor(options: IBaseCharacterStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
...options,
|
||||||
@ -136,7 +146,7 @@ export class FootnoteReferenceStyle extends CharacterStyle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FootnoteTextChar extends CharacterStyle {
|
export class FootnoteTextChar extends StyleForCharacter {
|
||||||
constructor(options: IBaseCharacterStyleOptions) {
|
constructor(options: IBaseCharacterStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
...options,
|
||||||
@ -152,7 +162,7 @@ export class FootnoteTextChar extends CharacterStyle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class HyperlinkStyle extends CharacterStyle {
|
export class HyperlinkStyle extends StyleForCharacter {
|
||||||
constructor(options: IBaseCharacterStyleOptions) {
|
constructor(options: IBaseCharacterStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
...options,
|
||||||
|
@ -6,12 +6,12 @@ import { UnderlineType } from "file/paragraph/run/underline";
|
|||||||
import { ShadingType } from "file/table";
|
import { ShadingType } from "file/table";
|
||||||
import { EMPTY_OBJECT } from "file/xml-components";
|
import { EMPTY_OBJECT } from "file/xml-components";
|
||||||
|
|
||||||
import { ParagraphStyle } from "./paragraph-style";
|
import { StyleForParagraph } from "./paragraph-style";
|
||||||
|
|
||||||
describe("ParagraphStyle", () => {
|
describe("ParagraphStyle", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
it("should set the style type to paragraph and use the given style id", () => {
|
it("should set the style type to paragraph and use the given style id", () => {
|
||||||
const style = new ParagraphStyle({ id: "myStyleId" });
|
const style = new StyleForParagraph({ id: "myStyleId" });
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
"w:style": { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
@ -19,7 +19,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should set the name of the style, if given", () => {
|
it("should set the name of the style, if given", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
name: "Style Name",
|
name: "Style Name",
|
||||||
});
|
});
|
||||||
@ -35,7 +35,7 @@ describe("ParagraphStyle", () => {
|
|||||||
|
|
||||||
describe("formatting methods: style attributes", () => {
|
describe("formatting methods: style attributes", () => {
|
||||||
it("#basedOn", () => {
|
it("#basedOn", () => {
|
||||||
const style = new ParagraphStyle({ id: "myStyleId", basedOn: "otherId" });
|
const style = new StyleForParagraph({ id: "myStyleId", basedOn: "otherId" });
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
@ -46,7 +46,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#quickFormat", () => {
|
it("#quickFormat", () => {
|
||||||
const style = new ParagraphStyle({ id: "myStyleId", quickFormat: true });
|
const style = new StyleForParagraph({ id: "myStyleId", quickFormat: true });
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
@ -62,7 +62,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#next", () => {
|
it("#next", () => {
|
||||||
const style = new ParagraphStyle({ id: "myStyleId", next: "otherId" });
|
const style = new StyleForParagraph({ id: "myStyleId", next: "otherId" });
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
@ -75,7 +75,7 @@ describe("ParagraphStyle", () => {
|
|||||||
|
|
||||||
describe("formatting methods: paragraph properties", () => {
|
describe("formatting methods: paragraph properties", () => {
|
||||||
it("#indent", () => {
|
it("#indent", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
paragraph: {
|
paragraph: {
|
||||||
indent: { left: 720 },
|
indent: { left: 720 },
|
||||||
@ -93,7 +93,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#spacing", () => {
|
it("#spacing", () => {
|
||||||
const style = new ParagraphStyle({ id: "myStyleId", paragraph: { spacing: { before: 50, after: 150 } } });
|
const style = new StyleForParagraph({ id: "myStyleId", paragraph: { spacing: { before: 50, after: 150 } } });
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
@ -106,7 +106,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#center", () => {
|
it("#center", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
paragraph: {
|
paragraph: {
|
||||||
alignment: AlignmentType.CENTER,
|
alignment: AlignmentType.CENTER,
|
||||||
@ -124,7 +124,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#character spacing", () => {
|
it("#character spacing", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
characterSpacing: 24,
|
characterSpacing: 24,
|
||||||
@ -142,7 +142,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#left", () => {
|
it("#left", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
paragraph: {
|
paragraph: {
|
||||||
alignment: AlignmentType.LEFT,
|
alignment: AlignmentType.LEFT,
|
||||||
@ -160,7 +160,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#right", () => {
|
it("#right", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
paragraph: {
|
paragraph: {
|
||||||
alignment: AlignmentType.RIGHT,
|
alignment: AlignmentType.RIGHT,
|
||||||
@ -178,7 +178,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#justified", () => {
|
it("#justified", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
paragraph: {
|
paragraph: {
|
||||||
alignment: AlignmentType.JUSTIFIED,
|
alignment: AlignmentType.JUSTIFIED,
|
||||||
@ -196,7 +196,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#thematicBreak", () => {
|
it("#thematicBreak", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
paragraph: {
|
paragraph: {
|
||||||
thematicBreak: true,
|
thematicBreak: true,
|
||||||
@ -229,7 +229,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#contextualSpacing", () => {
|
it("#contextualSpacing", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
paragraph: {
|
paragraph: {
|
||||||
contextualSpacing: true,
|
contextualSpacing: true,
|
||||||
@ -255,7 +255,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#leftTabStop", () => {
|
it("#leftTabStop", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
paragraph: {
|
paragraph: {
|
||||||
leftTabStop: 1200,
|
leftTabStop: 1200,
|
||||||
@ -277,7 +277,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#maxRightTabStop", () => {
|
it("#maxRightTabStop", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
paragraph: {
|
paragraph: {
|
||||||
rightTabStop: TabStopPosition.MAX,
|
rightTabStop: TabStopPosition.MAX,
|
||||||
@ -299,7 +299,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#keepLines", () => {
|
it("#keepLines", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
paragraph: {
|
paragraph: {
|
||||||
keepLines: true,
|
keepLines: true,
|
||||||
@ -320,7 +320,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#keepNext", () => {
|
it("#keepNext", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
paragraph: {
|
paragraph: {
|
||||||
keepNext: true,
|
keepNext: true,
|
||||||
@ -341,7 +341,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#outlineLevel", () => {
|
it("#outlineLevel", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
paragraph: {
|
paragraph: {
|
||||||
outlineLevel: 1,
|
outlineLevel: 1,
|
||||||
@ -381,7 +381,7 @@ describe("ParagraphStyle", () => {
|
|||||||
];
|
];
|
||||||
sizeTests.forEach(({ size, sizeComplexScript, expected }) => {
|
sizeTests.forEach(({ size, sizeComplexScript, expected }) => {
|
||||||
it(`#size ${size} cs ${sizeComplexScript}`, () => {
|
it(`#size ${size} cs ${sizeComplexScript}`, () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: { size, sizeComplexScript },
|
run: { size, sizeComplexScript },
|
||||||
});
|
});
|
||||||
@ -393,7 +393,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#smallCaps", () => {
|
it("#smallCaps", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
smallCaps: true,
|
smallCaps: true,
|
||||||
@ -411,7 +411,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#allCaps", () => {
|
it("#allCaps", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
allCaps: true,
|
allCaps: true,
|
||||||
@ -429,7 +429,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#strike", () => {
|
it("#strike", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
strike: true,
|
strike: true,
|
||||||
@ -447,7 +447,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#doubleStrike", () => {
|
it("#doubleStrike", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
doubleStrike: true,
|
doubleStrike: true,
|
||||||
@ -465,7 +465,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#subScript", () => {
|
it("#subScript", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
subScript: true,
|
subScript: true,
|
||||||
@ -483,7 +483,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#superScript", () => {
|
it("#superScript", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
superScript: true,
|
superScript: true,
|
||||||
@ -501,7 +501,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#font by name", () => {
|
it("#font by name", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
font: "Times",
|
font: "Times",
|
||||||
@ -530,7 +530,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#font for ascii and eastAsia", () => {
|
it("#font for ascii and eastAsia", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
font: {
|
font: {
|
||||||
@ -577,7 +577,7 @@ describe("ParagraphStyle", () => {
|
|||||||
];
|
];
|
||||||
boldTests.forEach(({ bold, boldComplexScript, expected }) => {
|
boldTests.forEach(({ bold, boldComplexScript, expected }) => {
|
||||||
it(`#bold ${bold} cs ${boldComplexScript}`, () => {
|
it(`#bold ${bold} cs ${boldComplexScript}`, () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: { bold, boldComplexScript },
|
run: { bold, boldComplexScript },
|
||||||
});
|
});
|
||||||
@ -606,7 +606,7 @@ describe("ParagraphStyle", () => {
|
|||||||
];
|
];
|
||||||
italicsTests.forEach(({ italics, italicsComplexScript, expected }) => {
|
italicsTests.forEach(({ italics, italicsComplexScript, expected }) => {
|
||||||
it(`#italics ${italics} cs ${italicsComplexScript}`, () => {
|
it(`#italics ${italics} cs ${italicsComplexScript}`, () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: { italics, italicsComplexScript },
|
run: { italics, italicsComplexScript },
|
||||||
});
|
});
|
||||||
@ -640,7 +640,7 @@ describe("ParagraphStyle", () => {
|
|||||||
];
|
];
|
||||||
highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => {
|
highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => {
|
||||||
it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => {
|
it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: { highlight, highlightComplexScript },
|
run: { highlight, highlightComplexScript },
|
||||||
});
|
});
|
||||||
@ -714,7 +714,7 @@ describe("ParagraphStyle", () => {
|
|||||||
];
|
];
|
||||||
shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => {
|
shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => {
|
||||||
it("#shadow correctly", () => {
|
it("#shadow correctly", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: { shadow, shading, shadingComplexScript },
|
run: { shadow, shading, shadingComplexScript },
|
||||||
});
|
});
|
||||||
@ -727,7 +727,7 @@ describe("ParagraphStyle", () => {
|
|||||||
|
|
||||||
describe("#underline", () => {
|
describe("#underline", () => {
|
||||||
it("should set underline to 'single' if no arguments are given", () => {
|
it("should set underline to 'single' if no arguments are given", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
underline: {},
|
underline: {},
|
||||||
@ -745,7 +745,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should set the style if given", () => {
|
it("should set the style if given", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
underline: {
|
underline: {
|
||||||
@ -765,7 +765,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should set the style and color if given", () => {
|
it("should set the style and color if given", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
underline: {
|
underline: {
|
||||||
@ -788,7 +788,7 @@ describe("ParagraphStyle", () => {
|
|||||||
|
|
||||||
describe("#emphasisMark", () => {
|
describe("#emphasisMark", () => {
|
||||||
it("should set emphasisMark to 'dot' if no arguments are given", () => {
|
it("should set emphasisMark to 'dot' if no arguments are given", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
emphasisMark: {},
|
emphasisMark: {},
|
||||||
@ -806,7 +806,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should set the style if given", () => {
|
it("should set the style if given", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
emphasisMark: {
|
emphasisMark: {
|
||||||
@ -827,7 +827,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#color", () => {
|
it("#color", () => {
|
||||||
const style = new ParagraphStyle({
|
const style = new StyleForParagraph({
|
||||||
id: "myStyleId",
|
id: "myStyleId",
|
||||||
run: {
|
run: {
|
||||||
color: "123456",
|
color: "123456",
|
||||||
@ -845,7 +845,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#link", () => {
|
it("#link", () => {
|
||||||
const style = new ParagraphStyle({ id: "myStyleId", link: "MyLink" });
|
const style = new StyleForParagraph({ id: "myStyleId", link: "MyLink" });
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
@ -861,7 +861,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#semiHidden", () => {
|
it("#semiHidden", () => {
|
||||||
const style = new ParagraphStyle({ id: "myStyleId", semiHidden: true });
|
const style = new StyleForParagraph({ id: "myStyleId", semiHidden: true });
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
@ -877,7 +877,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#uiPriority", () => {
|
it("#uiPriority", () => {
|
||||||
const style = new ParagraphStyle({ id: "myStyleId", uiPriority: 99 });
|
const style = new StyleForParagraph({ id: "myStyleId", uiPriority: 99 });
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
@ -894,7 +894,7 @@ describe("ParagraphStyle", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("#unhideWhenUsed", () => {
|
it("#unhideWhenUsed", () => {
|
||||||
const style = new ParagraphStyle({ id: "myStyleId", unhideWhenUsed: true });
|
const style = new StyleForParagraph({ id: "myStyleId", unhideWhenUsed: true });
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
|
@ -21,7 +21,7 @@ export interface IParagraphStyleOptions extends IBaseParagraphStyleOptions {
|
|||||||
readonly name?: string;
|
readonly name?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ParagraphStyle extends Style {
|
export class StyleForParagraph extends Style {
|
||||||
private readonly paragraphProperties: ParagraphProperties;
|
private readonly paragraphProperties: ParagraphProperties;
|
||||||
private readonly runProperties: RunProperties;
|
private readonly runProperties: RunProperties;
|
||||||
|
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
|
import { IDefaultStylesOptions } from "file/styles/factory";
|
||||||
import { BaseXmlComponent, ImportedXmlComponent, XmlComponent } from "file/xml-components";
|
import { BaseXmlComponent, ImportedXmlComponent, XmlComponent } from "file/xml-components";
|
||||||
|
import { StyleForCharacter, StyleForParagraph } from "./style";
|
||||||
import { CharacterStyle, ParagraphStyle } from "./style";
|
|
||||||
import { ICharacterStyleOptions } from "./style/character-style";
|
import { ICharacterStyleOptions } from "./style/character-style";
|
||||||
import { IParagraphStyleOptions } from "./style/paragraph-style";
|
import { IParagraphStyleOptions } from "./style/paragraph-style";
|
||||||
export * from "./border";
|
export * from "./border";
|
||||||
|
|
||||||
export interface IStylesOptions {
|
export interface IStylesOptions {
|
||||||
|
readonly default?: IDefaultStylesOptions;
|
||||||
readonly initialStyles?: BaseXmlComponent;
|
readonly initialStyles?: BaseXmlComponent;
|
||||||
readonly paragraphStyles?: IParagraphStyleOptions[];
|
readonly paragraphStyles?: IParagraphStyleOptions[];
|
||||||
readonly characterStyles?: ICharacterStyleOptions[];
|
readonly characterStyles?: ICharacterStyleOptions[];
|
||||||
readonly importedStyles?: (XmlComponent | ParagraphStyle | CharacterStyle | ImportedXmlComponent)[];
|
readonly importedStyles?: (XmlComponent | StyleForParagraph | StyleForCharacter | ImportedXmlComponent)[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Styles extends XmlComponent {
|
export class Styles extends XmlComponent {
|
||||||
@ -28,13 +29,13 @@ export class Styles extends XmlComponent {
|
|||||||
|
|
||||||
if (options.paragraphStyles) {
|
if (options.paragraphStyles) {
|
||||||
for (const style of options.paragraphStyles) {
|
for (const style of options.paragraphStyles) {
|
||||||
this.root.push(new ParagraphStyle(style));
|
this.root.push(new StyleForParagraph(style));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.characterStyles) {
|
if (options.characterStyles) {
|
||||||
for (const style of options.characterStyles) {
|
for (const style of options.characterStyles) {
|
||||||
this.root.push(new CharacterStyle(style));
|
this.root.push(new StyleForCharacter(style));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -546,5 +546,77 @@ describe("TableBorders", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("TableBorders.NONE convenience object", () => {
|
||||||
|
it("should add no borders", () => {
|
||||||
|
const tableBorders = new TableBorders(TableBorders.NONE);
|
||||||
|
const tree = new Formatter().format(tableBorders);
|
||||||
|
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:tblBorders": [
|
||||||
|
{
|
||||||
|
"w:top": {
|
||||||
|
_attr: {
|
||||||
|
"w:color": "auto",
|
||||||
|
"w:space": 0,
|
||||||
|
"w:sz": 0,
|
||||||
|
"w:val": "none",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:left": {
|
||||||
|
_attr: {
|
||||||
|
"w:color": "auto",
|
||||||
|
"w:space": 0,
|
||||||
|
"w:sz": 0,
|
||||||
|
"w:val": "none",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:bottom": {
|
||||||
|
_attr: {
|
||||||
|
"w:color": "auto",
|
||||||
|
"w:space": 0,
|
||||||
|
"w:sz": 0,
|
||||||
|
"w:val": "none",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:right": {
|
||||||
|
_attr: {
|
||||||
|
"w:color": "auto",
|
||||||
|
"w:space": 0,
|
||||||
|
"w:sz": 0,
|
||||||
|
"w:val": "none",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:insideH": {
|
||||||
|
_attr: {
|
||||||
|
"w:color": "auto",
|
||||||
|
"w:space": 0,
|
||||||
|
"w:sz": 0,
|
||||||
|
"w:val": "none",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:insideV": {
|
||||||
|
_attr: {
|
||||||
|
"w:color": "auto",
|
||||||
|
"w:space": 0,
|
||||||
|
"w:sz": 0,
|
||||||
|
"w:val": "none",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -36,6 +36,39 @@ export interface ITableBordersOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class TableBorders extends XmlComponent {
|
export class TableBorders extends XmlComponent {
|
||||||
|
public static readonly NONE = {
|
||||||
|
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",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
constructor(options: ITableBordersOptions) {
|
constructor(options: ITableBordersOptions) {
|
||||||
super("w:tblBorders");
|
super("w:tblBorders");
|
||||||
|
|
||||||
|
@ -89,11 +89,12 @@ describe("DeletedTextRun", () => {
|
|||||||
describe("#break()", () => {
|
describe("#break()", () => {
|
||||||
it("should add a break", () => {
|
it("should add a break", () => {
|
||||||
const deletedTextRun = new DeletedTextRun({
|
const deletedTextRun = new DeletedTextRun({
|
||||||
|
break: 1,
|
||||||
children: ["some text"],
|
children: ["some text"],
|
||||||
id: 0,
|
id: 0,
|
||||||
date: "123",
|
date: "123",
|
||||||
author: "Author",
|
author: "Author",
|
||||||
}).break();
|
});
|
||||||
const tree = new Formatter().format(deletedTextRun);
|
const tree = new Formatter().format(deletedTextRun);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:del": [
|
"w:del": [
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { XmlComponent } from "file/xml-components";
|
import { XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
import { FootnoteReferenceRun, IRunOptions, IRunPropertiesOptions, RunProperties } from "../../index";
|
import { IRunOptions, RunProperties } from "../../index";
|
||||||
import { Break } from "../../paragraph/run/break";
|
import { Break } from "../../paragraph/run/break";
|
||||||
import { Begin, End, Separate } from "../../paragraph/run/field";
|
import { Begin, End, Separate } from "../../paragraph/run/field";
|
||||||
import { PageNumber } from "../../paragraph/run/run";
|
import { PageNumber } from "../../paragraph/run/run";
|
||||||
@ -8,10 +8,7 @@ import { ChangeAttributes, IChangedAttributesProperties } from "../track-revisio
|
|||||||
import { DeletedNumberOfPages, DeletedNumberOfPagesSection, DeletedPage } from "./deleted-page-number";
|
import { DeletedNumberOfPages, DeletedNumberOfPagesSection, DeletedPage } from "./deleted-page-number";
|
||||||
import { DeletedText } from "./deleted-text";
|
import { DeletedText } from "./deleted-text";
|
||||||
|
|
||||||
interface IDeletedRunOptions extends IRunPropertiesOptions, IChangedAttributesProperties {
|
interface IDeletedRunOptions extends IRunOptions, IChangedAttributesProperties {}
|
||||||
readonly children?: (Begin | Separate | End | PageNumber | FootnoteReferenceRun | string)[];
|
|
||||||
readonly text?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class DeletedTextRun extends XmlComponent {
|
export class DeletedTextRun extends XmlComponent {
|
||||||
protected readonly deletedTextRunWrapper: DeletedTextRunWrapper;
|
protected readonly deletedTextRunWrapper: DeletedTextRunWrapper;
|
||||||
@ -25,14 +22,9 @@ export class DeletedTextRun extends XmlComponent {
|
|||||||
date: options.date,
|
date: options.date,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
this.deletedTextRunWrapper = new DeletedTextRunWrapper(options as IRunOptions);
|
this.deletedTextRunWrapper = new DeletedTextRunWrapper(options);
|
||||||
this.addChildElement(this.deletedTextRunWrapper);
|
this.addChildElement(this.deletedTextRunWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
public break(): DeletedTextRun {
|
|
||||||
this.deletedTextRunWrapper.break();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class DeletedTextRunWrapper extends XmlComponent {
|
class DeletedTextRunWrapper extends XmlComponent {
|
||||||
@ -74,9 +66,11 @@ class DeletedTextRunWrapper extends XmlComponent {
|
|||||||
} else if (options.text) {
|
} else if (options.text) {
|
||||||
this.root.push(new DeletedText(options.text));
|
this.root.push(new DeletedText(options.text));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public break(): void {
|
if (options.break) {
|
||||||
|
for (let i = 0; i < options.break; i++) {
|
||||||
this.root.splice(1, 0, new Break());
|
this.root.splice(1, 0, new Break());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,9 @@ export interface IDocumentTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ImportDotx {
|
export class ImportDotx {
|
||||||
public async extract(data: Buffer): Promise<IDocumentTemplate> {
|
public async extract(
|
||||||
|
data: Buffer | string | number[] | Uint8Array | ArrayBuffer | Blob | NodeJS.ReadableStream,
|
||||||
|
): Promise<IDocumentTemplate> {
|
||||||
const zipContent = await JSZip.loadAsync(data);
|
const zipContent = await JSZip.loadAsync(data);
|
||||||
|
|
||||||
const documentContent = await zipContent.files["word/document.xml"].async("text");
|
const documentContent = await zipContent.files["word/document.xml"].async("text");
|
||||||
|
@ -4,3 +4,4 @@ export { File as Document } from "./file";
|
|||||||
export * from "./file";
|
export * from "./file";
|
||||||
export * from "./export";
|
export * from "./export";
|
||||||
export * from "./import-dotx";
|
export * from "./import-dotx";
|
||||||
|
export * from "./convenience-functions";
|
||||||
|
Reference in New Issue
Block a user