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
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
end_of_line = lf
|
||||
|
||||
[*.md]
|
||||
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]
|
||||
[![Downloads per month][downloads-image]][downloads-url]
|
||||
[![Build Status][travis-image]][travis-url]
|
||||
[![GitHub Action Workflow Status][github-actions-workflow-image]][github-actions-workflow-url]
|
||||
[![Dependency Status][daviddm-image]][daviddm-url]
|
||||
[![Known Vulnerabilities][snky-image]][snky-url]
|
||||
[![Chat on Gitter][gitter-image]][gitter-url]
|
||||
@ -85,6 +86,7 @@ Read the contribution guidelines [here](https://docx.js.org/#/contribution-guide
|
||||
[<img src="https://i.imgur.com/QEZXU5b.png" alt="drawing" height="50"/>](https://www.beekast.com/)
|
||||
[<img src="https://imgur.com/XVU6aoi.png" alt="drawing" height="50"/>](https://herraizsoto.com/)
|
||||
[<img src="https://i.imgur.com/fn1xccG.png" alt="drawing" height="50"/>](http://www.ativer.com.br/)
|
||||
[<img src="https://i.imgur.com/cmykN7c.png" alt="drawing"/>](https://www.arity.co/)
|
||||
|
||||
|
||||
...and many more!
|
||||
@ -102,6 +104,8 @@ Made with 💖
|
||||
[downloads-url]: https://npmjs.org/package/docx
|
||||
[travis-image]: https://travis-ci.org/dolanmiu/docx.svg?branch=master
|
||||
[travis-url]: https://travis-ci.org/dolanmiu/docx
|
||||
[github-actions-workflow-image]: https://github.com/dolanmiu/docx/workflows/Default/badge.svg
|
||||
[github-actions-workflow-url]: https://github.com/dolanmiu/docx/actions
|
||||
[daviddm-image]: https://david-dm.org/dolanmiu/docx.svg?theme=shields.io
|
||||
[daviddm-url]: https://david-dm.org/dolanmiu/docx
|
||||
[snky-image]: https://snyk.io/test/github/dolanmiu/docx/badge.svg
|
||||
|
@ -204,7 +204,10 @@ class DocumentCreator {
|
||||
alignment: AlignmentType.CENTER,
|
||||
children: [
|
||||
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 {
|
||||
AlignmentType,
|
||||
convertInchesToTwip,
|
||||
Document,
|
||||
Footer,
|
||||
HeadingLevel,
|
||||
@ -18,13 +19,8 @@ import {
|
||||
|
||||
const doc = new Document({
|
||||
styles: {
|
||||
paragraphStyles: [
|
||||
{
|
||||
id: "Heading1",
|
||||
name: "Heading 1",
|
||||
basedOn: "Normal",
|
||||
next: "Normal",
|
||||
quickFormat: true,
|
||||
default: {
|
||||
heading1: {
|
||||
run: {
|
||||
font: "Calibri",
|
||||
size: 52,
|
||||
@ -40,12 +36,7 @@ const doc = new Document({
|
||||
spacing: { line: 340 },
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "Heading2",
|
||||
name: "Heading 2",
|
||||
basedOn: "Normal",
|
||||
next: "Normal",
|
||||
quickFormat: true,
|
||||
heading2: {
|
||||
run: {
|
||||
font: "Calibri",
|
||||
size: 26,
|
||||
@ -55,12 +46,7 @@ const doc = new Document({
|
||||
spacing: { line: 340 },
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "Heading3",
|
||||
name: "Heading 3",
|
||||
basedOn: "Normal",
|
||||
next: "Normal",
|
||||
quickFormat: true,
|
||||
heading3: {
|
||||
run: {
|
||||
font: "Calibri",
|
||||
size: 26,
|
||||
@ -70,12 +56,7 @@ const doc = new Document({
|
||||
spacing: { line: 276 },
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "Heading4",
|
||||
name: "Heading 4",
|
||||
basedOn: "Normal",
|
||||
next: "Normal",
|
||||
quickFormat: true,
|
||||
heading4: {
|
||||
run: {
|
||||
font: "Calibri",
|
||||
size: 26,
|
||||
@ -85,6 +66,8 @@ const doc = new Document({
|
||||
alignment: AlignmentType.JUSTIFIED,
|
||||
},
|
||||
},
|
||||
},
|
||||
paragraphStyles: [
|
||||
{
|
||||
id: "normalPara",
|
||||
name: "Normal Para",
|
||||
@ -128,7 +111,7 @@ const doc = new Document({
|
||||
},
|
||||
paragraph: {
|
||||
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 },
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "ListParagraph",
|
||||
name: "List Paragraph",
|
||||
basedOn: "Normal",
|
||||
quickFormat: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
@ -1,20 +1,25 @@
|
||||
// Example on how to customise the look at feel using Styles
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
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({
|
||||
creator: "Clippy",
|
||||
title: "Sample Document",
|
||||
description: "A brief example of using docx",
|
||||
styles: {
|
||||
paragraphStyles: [
|
||||
{
|
||||
id: "Heading1",
|
||||
name: "Heading 1",
|
||||
basedOn: "Normal",
|
||||
next: "Normal",
|
||||
quickFormat: true,
|
||||
default: {
|
||||
heading1: {
|
||||
run: {
|
||||
size: 28,
|
||||
bold: true,
|
||||
@ -27,12 +32,7 @@ const doc = new Document({
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "Heading2",
|
||||
name: "Heading 2",
|
||||
basedOn: "Normal",
|
||||
next: "Normal",
|
||||
quickFormat: true,
|
||||
heading2: {
|
||||
run: {
|
||||
size: 26,
|
||||
bold: true,
|
||||
@ -48,6 +48,13 @@ const doc = new Document({
|
||||
},
|
||||
},
|
||||
},
|
||||
listParagraph: {
|
||||
run: {
|
||||
color: "#FF0000",
|
||||
},
|
||||
},
|
||||
},
|
||||
paragraphStyles: [
|
||||
{
|
||||
id: "aside",
|
||||
name: "Aside",
|
||||
@ -59,7 +66,7 @@ const doc = new Document({
|
||||
},
|
||||
paragraph: {
|
||||
indent: {
|
||||
left: 720,
|
||||
left: convertInchesToTwip(0.5),
|
||||
},
|
||||
spacing: {
|
||||
line: 276,
|
||||
@ -75,12 +82,6 @@ const doc = new Document({
|
||||
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "ListParagraph",
|
||||
name: "List Paragraph",
|
||||
basedOn: "Normal",
|
||||
quickFormat: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
numbering: {
|
||||
@ -90,7 +91,7 @@ const doc = new Document({
|
||||
levels: [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerLetter",
|
||||
format: LevelFormat.LOWER_LETTER,
|
||||
text: "%1)",
|
||||
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
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
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({
|
||||
styles: {
|
||||
@ -17,7 +17,7 @@ const doc = new Document({
|
||||
},
|
||||
paragraph: {
|
||||
indent: {
|
||||
left: 720,
|
||||
left: convertInchesToTwip(0.5),
|
||||
},
|
||||
spacing: {
|
||||
line: 276,
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Numbered lists
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
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({
|
||||
numbering: {
|
||||
@ -10,12 +10,12 @@ const doc = new Document({
|
||||
levels: [
|
||||
{
|
||||
level: 0,
|
||||
format: "upperRoman",
|
||||
format: LevelFormat.UPPER_ROMAN,
|
||||
text: "%1",
|
||||
alignment: AlignmentType.START,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 720, hanging: 260 },
|
||||
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -26,18 +26,34 @@ const doc = new Document({
|
||||
levels: [
|
||||
{
|
||||
level: 0,
|
||||
format: "decimal",
|
||||
format: LevelFormat.DECIMAL,
|
||||
text: "%1",
|
||||
alignment: AlignmentType.START,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 720, hanging: 260 },
|
||||
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
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,
|
||||
},
|
||||
}),
|
||||
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
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
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({
|
||||
numbering: {
|
||||
@ -11,40 +11,40 @@ const doc = new Document({
|
||||
levels: [
|
||||
{
|
||||
level: 0,
|
||||
format: "upperRoman",
|
||||
format: LevelFormat.UPPER_ROMAN,
|
||||
text: "%1",
|
||||
alignment: AlignmentType.START,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 720, hanging: 260 },
|
||||
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 1,
|
||||
format: "decimal",
|
||||
format: LevelFormat.DECIMAL,
|
||||
text: "%2.",
|
||||
alignment: AlignmentType.START,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 1440, hanging: 980 },
|
||||
indent: { left: convertInchesToTwip(1), hanging: convertInchesToTwip(0.68) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 2,
|
||||
format: "lowerLetter",
|
||||
format: LevelFormat.LOWER_LETTER,
|
||||
text: "%3)",
|
||||
alignment: AlignmentType.START,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 2160, hanging: 1700 },
|
||||
indent: { left: convertInchesToTwip(1.5), hanging: convertInchesToTwip(1.18) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 3,
|
||||
format: "upperLetter",
|
||||
format: LevelFormat.UPPER_LETTER,
|
||||
text: "%4)",
|
||||
alignment: AlignmentType.START,
|
||||
style: {
|
||||
|
@ -2,7 +2,20 @@
|
||||
// Also includes an example on how to center tables
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
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();
|
||||
|
||||
@ -37,10 +50,10 @@ const table2 = new Table({
|
||||
new TableCell({
|
||||
children: [new Paragraph("World")],
|
||||
margins: {
|
||||
top: 1000,
|
||||
bottom: 1000,
|
||||
left: 1000,
|
||||
right: 1000,
|
||||
top: convertInchesToTwip(0.69),
|
||||
bottom: convertInchesToTwip(0.69),
|
||||
left: convertInchesToTwip(0.69),
|
||||
right: convertInchesToTwip(0.69),
|
||||
},
|
||||
columnSpan: 3,
|
||||
}),
|
||||
@ -64,7 +77,7 @@ const table2 = new Table({
|
||||
size: 100,
|
||||
type: WidthType.AUTO,
|
||||
},
|
||||
columnWidths: [1000, 1000, 1000],
|
||||
columnWidths: [convertInchesToTwip(0.69), convertInchesToTwip(0.69), convertInchesToTwip(0.69)],
|
||||
});
|
||||
|
||||
const table3 = new Table({
|
||||
@ -119,14 +132,14 @@ const table3 = new Table({
|
||||
}),
|
||||
],
|
||||
width: {
|
||||
size: 7000,
|
||||
size: convertInchesToTwip(4.86),
|
||||
type: WidthType.DXA,
|
||||
},
|
||||
margins: {
|
||||
top: 400,
|
||||
bottom: 400,
|
||||
right: 400,
|
||||
left: 400,
|
||||
top: convertInchesToTwip(0.27),
|
||||
bottom: convertInchesToTwip(0.27),
|
||||
right: convertInchesToTwip(0.27),
|
||||
left: convertInchesToTwip(0.27),
|
||||
},
|
||||
});
|
||||
|
||||
@ -355,9 +368,7 @@ const table8 = new Table({
|
||||
],
|
||||
}),
|
||||
new TableRow({
|
||||
children: [
|
||||
new TableCell({ children: [new Paragraph("4,1")] }),
|
||||
],
|
||||
children: [new TableCell({ children: [new Paragraph("4,1")] })],
|
||||
}),
|
||||
],
|
||||
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 * 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();
|
||||
|
||||
@ -10,6 +22,28 @@ const table = new Table({
|
||||
new TableRow({
|
||||
children: [
|
||||
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")],
|
||||
}),
|
||||
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) => {
|
||||
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 image6 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 200, 200, {
|
||||
floating: {
|
||||
zIndex: 10,
|
||||
horizontalPosition: {
|
||||
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, {
|
||||
floating: {
|
||||
zIndex: 5,
|
||||
horizontalPosition: {
|
||||
relative: HorizontalPositionRelativeFrom.PAGE,
|
||||
align: HorizontalPositionAlign.RIGHT,
|
||||
|
@ -15,6 +15,14 @@ const doc = new Document({
|
||||
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: [
|
||||
new TextRun("This is a demo "),
|
||||
new DeletedTextRun({
|
||||
break: 1,
|
||||
text: "in order",
|
||||
color: "red",
|
||||
bold: true,
|
||||
@ -95,7 +96,7 @@ doc.addSection({
|
||||
id: 2,
|
||||
author: "Firstname Lastname",
|
||||
date: "2020-10-06T09:00:00Z",
|
||||
}).break(),
|
||||
}),
|
||||
new InsertedTextRun({
|
||||
text: "to show how to ",
|
||||
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
|
||||
|
||||
* [Packers](usage/packers.md)
|
||||
* Utility
|
||||
|
||||
* [Convenience functions](usage/convenience-functions.md)
|
||||
|
||||
* [Contribution Guidelines](contribution-guidelines.md)
|
||||
|
@ -9,7 +9,7 @@ const text = new TextRun("Bullet points");
|
||||
const paragraph = new Paragraph({
|
||||
text: "Bullet points",
|
||||
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 |
|
||||
| behindDocument | `boolean` | Optional |
|
||||
| layoutInCell | `boolean` | Optional |
|
||||
| zIndex | `number` | Optional |
|
||||
|
||||
`HorizontalPositionOptions` are:
|
||||
|
||||
|
@ -158,6 +158,15 @@ Sometimes you would want to put text underneath another line of text but inside
|
||||
```ts
|
||||
const text = new TextRun({
|
||||
text: "break",
|
||||
break: true,
|
||||
break: 1,
|
||||
});
|
||||
```
|
||||
|
||||
Adding two breaks:
|
||||
|
||||
```ts
|
||||
const text = new TextRun({
|
||||
text: "break",
|
||||
break: 2,
|
||||
});
|
||||
```
|
||||
|
681
package-lock.json
generated
681
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
{
|
||||
"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.",
|
||||
"main": "build/index.js",
|
||||
"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 { convertInchesToTwip } from "convenience-functions";
|
||||
import { Formatter } from "export/formatter";
|
||||
import { FooterWrapper } from "file/footer-wrapper";
|
||||
import { HeaderWrapper } from "file/header-wrapper";
|
||||
@ -18,10 +19,10 @@ describe("SectionProperties", () => {
|
||||
const properties = new SectionProperties({
|
||||
width: 11906,
|
||||
height: 16838,
|
||||
top: 1440,
|
||||
right: 1440,
|
||||
bottom: 1440,
|
||||
left: 1440,
|
||||
top: convertInchesToTwip(1),
|
||||
right: convertInchesToTwip(1),
|
||||
bottom: convertInchesToTwip(1),
|
||||
left: convertInchesToTwip(1),
|
||||
header: 708,
|
||||
footer: 708,
|
||||
gutter: 0,
|
||||
@ -30,7 +31,7 @@ describe("SectionProperties", () => {
|
||||
space: 708,
|
||||
count: 1,
|
||||
},
|
||||
linePitch: 360,
|
||||
linePitch: convertInchesToTwip(0.25),
|
||||
headers: {
|
||||
default: new HeaderWrapper(media, 100),
|
||||
},
|
||||
|
@ -1,4 +1,5 @@
|
||||
// http://officeopenxml.com/WPsection.php
|
||||
import { convertInchesToTwip } from "convenience-functions";
|
||||
import { FooterWrapper } from "file/footer-wrapper";
|
||||
import { HeaderWrapper } from "file/header-wrapper";
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
@ -64,10 +65,10 @@ export class SectionProperties extends XmlComponent {
|
||||
const {
|
||||
width = 11906,
|
||||
height = 16838,
|
||||
top = 1440,
|
||||
right = 1440,
|
||||
bottom = 1440,
|
||||
left = 1440,
|
||||
top = convertInchesToTwip(1),
|
||||
right = convertInchesToTwip(1),
|
||||
bottom = convertInchesToTwip(1),
|
||||
left = convertInchesToTwip(1),
|
||||
header = 708,
|
||||
footer = 708,
|
||||
gutter = 0,
|
||||
|
@ -218,5 +218,150 @@ describe("Anchor", () => {
|
||||
const textWrap = newJson.root[6];
|
||||
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 { AnchorAttributes } from "./anchor-attributes";
|
||||
|
||||
const defaultOptions: IFloating = {
|
||||
allowOverlap: true,
|
||||
behindDocument: false,
|
||||
lockAnchor: false,
|
||||
layoutInCell: true,
|
||||
verticalPosition: {},
|
||||
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,
|
||||
const floating: IFloating = {
|
||||
allowOverlap: true,
|
||||
behindDocument: false,
|
||||
lockAnchor: false,
|
||||
layoutInCell: true,
|
||||
verticalPosition: {},
|
||||
horizontalPosition: {},
|
||||
...drawingOptions.floating,
|
||||
};
|
||||
|
||||
this.root.push(
|
||||
new AnchorAttributes({
|
||||
distT: floating.margins.top || 0,
|
||||
distB: floating.margins.bottom || 0,
|
||||
distL: floating.margins.left || 0,
|
||||
distR: floating.margins.right || 0,
|
||||
distT: floating.margins ? floating.margins.top || 0 : 0,
|
||||
distB: floating.margins ? floating.margins.bottom || 0 : 0,
|
||||
distL: floating.margins ? floating.margins.left || 0 : 0,
|
||||
distR: floating.margins ? floating.margins.right || 0 : 0,
|
||||
simplePos: "0", // note: word doesn't fully support - so we use 0
|
||||
allowOverlap: floating.allowOverlap === true ? "1" : "0",
|
||||
behindDoc: floating.behindDocument === true ? "1" : "0",
|
||||
locked: floating.lockAnchor === 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.php
|
||||
import { ITextWrapping } from "../text-wrap";
|
||||
|
||||
export enum HorizontalPositionRelativeFrom {
|
||||
@ -67,4 +68,5 @@ export interface IFloating {
|
||||
readonly layoutInCell?: boolean;
|
||||
readonly margins?: IMargins;
|
||||
readonly wrap?: ITextWrapping;
|
||||
readonly zIndex?: number;
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ export class File {
|
||||
this.styles = stylesFactory.newInstance(options.externalStyles);
|
||||
} else if (options.styles) {
|
||||
const stylesFactory = new DefaultStylesFactory();
|
||||
const defaultStyles = stylesFactory.newInstance();
|
||||
const defaultStyles = stylesFactory.newInstance(options.styles.default);
|
||||
this.styles = new Styles({
|
||||
...defaultStyles,
|
||||
...options.styles,
|
||||
|
@ -7,7 +7,7 @@ import { AlignmentType, EmphasisMarkType, TabStopPosition } from "../paragraph";
|
||||
import { UnderlineType } from "../paragraph/run/underline";
|
||||
import { ShadingType } from "../table";
|
||||
import { AbstractNumbering } from "./abstract-numbering";
|
||||
import { LevelSuffix } from "./level";
|
||||
import { LevelFormat, LevelSuffix } from "./level";
|
||||
|
||||
describe("AbstractNumbering", () => {
|
||||
it("stores its ID at its .id property", () => {
|
||||
@ -20,7 +20,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 3,
|
||||
format: "lowerLetter",
|
||||
format: LevelFormat.LOWER_LETTER,
|
||||
text: "%1)",
|
||||
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({ "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: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)" } } });
|
||||
});
|
||||
|
||||
@ -37,7 +37,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 3,
|
||||
format: "lowerLetter",
|
||||
format: LevelFormat.LOWER_LETTER,
|
||||
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({ "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: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)" } } });
|
||||
});
|
||||
|
||||
@ -53,7 +53,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 3,
|
||||
format: "lowerLetter",
|
||||
format: LevelFormat.LOWER_LETTER,
|
||||
text: "%1)",
|
||||
alignment: AlignmentType.END,
|
||||
suffix: LevelSuffix.SPACE,
|
||||
@ -68,7 +68,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -87,7 +87,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -106,7 +106,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -125,7 +125,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -144,7 +144,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -163,7 +163,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -182,7 +182,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -216,7 +216,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -239,7 +239,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -262,7 +262,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -281,7 +281,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
paragraph: {
|
||||
@ -324,7 +324,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: { size, sizeComplexScript },
|
||||
@ -340,7 +340,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -359,7 +359,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -378,7 +378,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -398,7 +398,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -417,7 +417,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -436,7 +436,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -455,7 +455,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -485,7 +485,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -533,7 +533,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: { bold, boldComplexScript },
|
||||
@ -566,7 +566,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: { italics, italicsComplexScript },
|
||||
@ -604,7 +604,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: { highlight, highlightComplexScript },
|
||||
@ -682,7 +682,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: { shadow, shading, shadingComplexScript },
|
||||
@ -699,7 +699,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -718,7 +718,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -739,7 +739,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -763,7 +763,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -782,7 +782,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
@ -804,7 +804,7 @@ describe("AbstractNumbering", () => {
|
||||
const abstractNumbering = new AbstractNumbering(1, [
|
||||
{
|
||||
level: 0,
|
||||
format: "lowerRoman",
|
||||
format: LevelFormat.LOWER_ROMAN,
|
||||
text: "%0.",
|
||||
style: {
|
||||
run: {
|
||||
|
@ -1,8 +1,26 @@
|
||||
// http://officeopenxml.com/WPnumbering-numFmt.php
|
||||
import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
import { AlignmentType } from "../paragraph/formatting";
|
||||
import { IParagraphStylePropertiesOptions, ParagraphProperties } from "../paragraph/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 {
|
||||
readonly ilvl?: number;
|
||||
readonly tentative?: number;
|
||||
@ -67,7 +85,7 @@ export enum LevelSuffix {
|
||||
|
||||
export interface ILevelsOptions {
|
||||
readonly level: number;
|
||||
readonly format?: string;
|
||||
readonly format?: LevelFormat;
|
||||
readonly text?: string;
|
||||
readonly alignment?: AlignmentType;
|
||||
readonly start?: number;
|
||||
|
@ -1,10 +1,11 @@
|
||||
// http://officeopenxml.com/WPnumbering.php
|
||||
import { convertInchesToTwip } from "convenience-functions";
|
||||
import { AlignmentType } from "file/paragraph";
|
||||
import { IXmlableObject, XmlComponent } from "file/xml-components";
|
||||
|
||||
import { DocumentAttributes } from "../document/document-attributes";
|
||||
import { AbstractNumbering } from "./abstract-numbering";
|
||||
import { ILevelsOptions } from "./level";
|
||||
import { ILevelsOptions, LevelFormat } from "./level";
|
||||
import { ConcreteNumbering } from "./num";
|
||||
|
||||
export interface INumberingOptions {
|
||||
@ -50,100 +51,100 @@ export class Numbering extends XmlComponent {
|
||||
const abstractNumbering = this.createAbstractNumbering([
|
||||
{
|
||||
level: 0,
|
||||
format: "bullet",
|
||||
format: LevelFormat.BULLET,
|
||||
text: "\u25CF",
|
||||
alignment: AlignmentType.LEFT,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 720, hanging: 360 },
|
||||
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.25) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 1,
|
||||
format: "bullet",
|
||||
format: LevelFormat.BULLET,
|
||||
text: "\u25CB",
|
||||
alignment: AlignmentType.LEFT,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 1440, hanging: 360 },
|
||||
indent: { left: convertInchesToTwip(1), hanging: convertInchesToTwip(0.25) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 2,
|
||||
format: "bullet",
|
||||
format: LevelFormat.BULLET,
|
||||
text: "\u25A0",
|
||||
alignment: AlignmentType.LEFT,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 2160, hanging: 360 },
|
||||
indent: { left: 2160, hanging: convertInchesToTwip(0.25) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 3,
|
||||
format: "bullet",
|
||||
format: LevelFormat.BULLET,
|
||||
text: "\u25CF",
|
||||
alignment: AlignmentType.LEFT,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 2880, hanging: 360 },
|
||||
indent: { left: 2880, hanging: convertInchesToTwip(0.25) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 4,
|
||||
format: "bullet",
|
||||
format: LevelFormat.BULLET,
|
||||
text: "\u25CB",
|
||||
alignment: AlignmentType.LEFT,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 3600, hanging: 360 },
|
||||
indent: { left: 3600, hanging: convertInchesToTwip(0.25) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 5,
|
||||
format: "bullet",
|
||||
format: LevelFormat.BULLET,
|
||||
text: "\u25A0",
|
||||
alignment: AlignmentType.LEFT,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 4320, hanging: 360 },
|
||||
indent: { left: 4320, hanging: convertInchesToTwip(0.25) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 6,
|
||||
format: "bullet",
|
||||
format: LevelFormat.BULLET,
|
||||
text: "\u25CF",
|
||||
alignment: AlignmentType.LEFT,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 5040, hanging: 360 },
|
||||
indent: { left: 5040, hanging: convertInchesToTwip(0.25) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 7,
|
||||
format: "bullet",
|
||||
format: LevelFormat.BULLET,
|
||||
text: "\u25CF",
|
||||
alignment: AlignmentType.LEFT,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 5760, hanging: 360 },
|
||||
indent: { left: 5760, hanging: convertInchesToTwip(0.25) },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
level: 8,
|
||||
format: "bullet",
|
||||
format: LevelFormat.BULLET,
|
||||
text: "\u25CF",
|
||||
alignment: AlignmentType.LEFT,
|
||||
style: {
|
||||
paragraph: {
|
||||
indent: { left: 6480, hanging: 360 },
|
||||
indent: { left: 6480, hanging: convertInchesToTwip(0.25) },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -19,3 +19,9 @@ export type MathComponent =
|
||||
| MathCurlyBrackets
|
||||
| MathAngledBrackets
|
||||
| MathSquareBrackets;
|
||||
|
||||
// Needed because of: https://github.com/s-panferov/awesome-typescript-loader/issues/432
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export const WORKAROUND4 = "";
|
||||
|
@ -239,13 +239,29 @@ describe("Run", () => {
|
||||
|
||||
describe("#break()", () => {
|
||||
it("it should add break to the run", () => {
|
||||
const run = new Run({});
|
||||
run.break();
|
||||
const run = new Run({
|
||||
break: 1,
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"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()", () => {
|
||||
|
@ -11,6 +11,7 @@ import { Text } from "./run-components/text";
|
||||
|
||||
export interface IRunOptions extends IRunPropertiesOptions {
|
||||
readonly children?: (Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | string)[];
|
||||
readonly break?: number;
|
||||
readonly text?: string;
|
||||
}
|
||||
|
||||
@ -62,10 +63,11 @@ export class Run extends XmlComponent {
|
||||
} else if (options.text) {
|
||||
this.root.push(new Text(options.text));
|
||||
}
|
||||
}
|
||||
|
||||
public break(): Run {
|
||||
this.root.splice(1, 0, new Break());
|
||||
return this;
|
||||
if (options.break) {
|
||||
for (let i = 0; i < options.break; i++) {
|
||||
this.root.splice(1, 0, new Break());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { DocumentAttributes } from "../document/document-attributes";
|
||||
import { IStylesOptions } from "./styles";
|
||||
|
||||
import { DocumentDefaults } from "./defaults";
|
||||
import { DocumentDefaults, IDocumentDefaultsOptions } from "./defaults";
|
||||
import {
|
||||
FootnoteReferenceStyle,
|
||||
FootnoteText,
|
||||
@ -13,12 +13,32 @@ import {
|
||||
Heading5Style,
|
||||
Heading6Style,
|
||||
HyperlinkStyle,
|
||||
IBaseCharacterStyleOptions,
|
||||
IBaseParagraphStyleOptions,
|
||||
ListParagraph,
|
||||
StrongStyle,
|
||||
TitleStyle,
|
||||
} 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 {
|
||||
public newInstance(): IStylesOptions {
|
||||
public newInstance(options: IDefaultStylesOptions = {}): IStylesOptions {
|
||||
const documentAttributes = new DocumentAttributes({
|
||||
mc: "http://schemas.openxmlformats.org/markup-compatibility/2006",
|
||||
r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
||||
@ -30,51 +50,64 @@ export class DefaultStylesFactory {
|
||||
return {
|
||||
initialStyles: documentAttributes,
|
||||
importedStyles: [
|
||||
new DocumentDefaults(),
|
||||
new DocumentDefaults(options.document),
|
||||
new TitleStyle({
|
||||
run: {
|
||||
size: 56,
|
||||
},
|
||||
...options.title,
|
||||
}),
|
||||
new Heading1Style({
|
||||
run: {
|
||||
color: "2E74B5",
|
||||
size: 32,
|
||||
},
|
||||
...options.heading1,
|
||||
}),
|
||||
new Heading2Style({
|
||||
run: {
|
||||
color: "2E74B5",
|
||||
size: 26,
|
||||
},
|
||||
...options.heading2,
|
||||
}),
|
||||
new Heading3Style({
|
||||
run: {
|
||||
color: "1F4D78",
|
||||
size: 24,
|
||||
},
|
||||
...options.heading3,
|
||||
}),
|
||||
new Heading4Style({
|
||||
run: {
|
||||
color: "2E74B5",
|
||||
italics: true,
|
||||
},
|
||||
...options.heading4,
|
||||
}),
|
||||
new Heading5Style({
|
||||
run: {
|
||||
color: "2E74B5",
|
||||
},
|
||||
...options.heading5,
|
||||
}),
|
||||
new Heading6Style({
|
||||
run: {
|
||||
color: "1F4D78",
|
||||
},
|
||||
...options.heading6,
|
||||
}),
|
||||
new ListParagraph({}),
|
||||
new HyperlinkStyle({}),
|
||||
new FootnoteReferenceStyle({}),
|
||||
new FootnoteText({}),
|
||||
new FootnoteTextChar({}),
|
||||
new StrongStyle({
|
||||
run: {
|
||||
bold: true,
|
||||
},
|
||||
...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 { EMPTY_OBJECT } from "file/xml-components";
|
||||
|
||||
import { CharacterStyle } from "./character-style";
|
||||
import { StyleForCharacter } from "./character-style";
|
||||
|
||||
describe("CharacterStyle", () => {
|
||||
describe("#constructor", () => {
|
||||
it("should set the style type to character and use the given style id", () => {
|
||||
const style = new CharacterStyle({ id: "myStyleId" });
|
||||
const style = new StyleForCharacter({ id: "myStyleId" });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -31,7 +31,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the name of the style, if given", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
name: "Style Name",
|
||||
});
|
||||
@ -55,7 +55,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should add smallCaps", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
smallCaps: true,
|
||||
@ -83,7 +83,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should add allCaps", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
allCaps: true,
|
||||
@ -111,7 +111,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should add strike", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
strike: true,
|
||||
@ -139,7 +139,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should add double strike", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
doubleStrike: true,
|
||||
@ -167,7 +167,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should add sub script", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
subScript: true,
|
||||
@ -203,7 +203,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should add font by name", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
font: "test font",
|
||||
@ -242,7 +242,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should add font for ascii and eastAsia", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
font: {
|
||||
@ -282,7 +282,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should add character spacing", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
characterSpacing: 100,
|
||||
@ -312,7 +312,7 @@ describe("CharacterStyle", () => {
|
||||
|
||||
describe("formatting methods: style attributes", () => {
|
||||
it("#basedOn", () => {
|
||||
const style = new CharacterStyle({ id: "myStyleId", basedOn: "otherId" });
|
||||
const style = new StyleForCharacter({ id: "myStyleId", basedOn: "otherId" });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -357,7 +357,7 @@ describe("CharacterStyle", () => {
|
||||
];
|
||||
sizeTests.forEach(({ size, sizeComplexScript, expected }) => {
|
||||
it(`#size ${size} cs ${sizeComplexScript}`, () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: { size, sizeComplexScript },
|
||||
});
|
||||
@ -385,7 +385,7 @@ describe("CharacterStyle", () => {
|
||||
|
||||
describe("#underline", () => {
|
||||
it("should set underline to 'single' if no arguments are given", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
underline: {},
|
||||
@ -413,7 +413,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the style if given", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
underline: {
|
||||
@ -443,7 +443,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the style and color if given", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
underline: {
|
||||
@ -476,7 +476,7 @@ describe("CharacterStyle", () => {
|
||||
|
||||
describe("#emphasisMark", () => {
|
||||
it("should set emphasisMark to 'dot' if no arguments are given", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
emphasisMark: {},
|
||||
@ -504,7 +504,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the style if given", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
emphasisMark: {
|
||||
@ -535,7 +535,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("#superScript", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
superScript: true,
|
||||
@ -571,7 +571,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("#color", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
color: "123456",
|
||||
@ -616,7 +616,7 @@ describe("CharacterStyle", () => {
|
||||
];
|
||||
boldTests.forEach(({ bold, boldComplexScript, expected }) => {
|
||||
it(`#bold ${bold} cs ${boldComplexScript}`, () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: { bold, boldComplexScript },
|
||||
});
|
||||
@ -660,7 +660,7 @@ describe("CharacterStyle", () => {
|
||||
];
|
||||
italicsTests.forEach(({ italics, italicsComplexScript, expected }) => {
|
||||
it(`#italics ${italics} cs ${italicsComplexScript}`, () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: { italics, italicsComplexScript },
|
||||
});
|
||||
@ -687,7 +687,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("#link", () => {
|
||||
const style = new CharacterStyle({ id: "myStyleId", link: "MyLink" });
|
||||
const style = new StyleForCharacter({ id: "myStyleId", link: "MyLink" });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -708,7 +708,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("#semiHidden", () => {
|
||||
const style = new CharacterStyle({ id: "myStyleId", semiHidden: true });
|
||||
const style = new StyleForCharacter({ id: "myStyleId", semiHidden: true });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -749,7 +749,7 @@ describe("CharacterStyle", () => {
|
||||
];
|
||||
highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => {
|
||||
it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: { highlight, highlightComplexScript },
|
||||
});
|
||||
@ -838,7 +838,7 @@ describe("CharacterStyle", () => {
|
||||
];
|
||||
shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => {
|
||||
it("#shadow correctly", () => {
|
||||
const style = new CharacterStyle({
|
||||
const style = new StyleForCharacter({
|
||||
id: "myStyleId",
|
||||
run: { shadow, shading, shadingComplexScript },
|
||||
});
|
||||
|
@ -15,7 +15,7 @@ export interface ICharacterStyleOptions extends IBaseCharacterStyleOptions {
|
||||
readonly name?: string;
|
||||
}
|
||||
|
||||
export class CharacterStyle extends Style {
|
||||
export class StyleForCharacter extends Style {
|
||||
private readonly runProperties: RunProperties;
|
||||
|
||||
constructor(options: ICharacterStyleOptions) {
|
||||
|
@ -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", () => {
|
||||
const style = new defaultStyles.ListParagraph({});
|
||||
const tree = new Formatter().format(style);
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { UnderlineType } from "file/paragraph/run/underline";
|
||||
|
||||
import { CharacterStyle, IBaseCharacterStyleOptions } from "./character-style";
|
||||
import { IBaseParagraphStyleOptions, IParagraphStyleOptions, ParagraphStyle } from "./paragraph-style";
|
||||
import { IBaseCharacterStyleOptions, StyleForCharacter } from "./character-style";
|
||||
import { IBaseParagraphStyleOptions, IParagraphStyleOptions, StyleForParagraph } from "./paragraph-style";
|
||||
|
||||
export class HeadingStyle extends ParagraphStyle {
|
||||
export class HeadingStyle extends StyleForParagraph {
|
||||
constructor(options: IParagraphStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
@ -84,7 +84,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) {
|
||||
super({
|
||||
...options,
|
||||
@ -96,7 +106,7 @@ export class ListParagraph extends ParagraphStyle {
|
||||
}
|
||||
}
|
||||
|
||||
export class FootnoteText extends ParagraphStyle {
|
||||
export class FootnoteText extends StyleForParagraph {
|
||||
constructor(options: IBaseParagraphStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
@ -121,7 +131,7 @@ export class FootnoteText extends ParagraphStyle {
|
||||
}
|
||||
}
|
||||
|
||||
export class FootnoteReferenceStyle extends CharacterStyle {
|
||||
export class FootnoteReferenceStyle extends StyleForCharacter {
|
||||
constructor(options: IBaseCharacterStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
@ -136,7 +146,7 @@ export class FootnoteReferenceStyle extends CharacterStyle {
|
||||
}
|
||||
}
|
||||
|
||||
export class FootnoteTextChar extends CharacterStyle {
|
||||
export class FootnoteTextChar extends StyleForCharacter {
|
||||
constructor(options: IBaseCharacterStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
@ -152,7 +162,7 @@ export class FootnoteTextChar extends CharacterStyle {
|
||||
}
|
||||
}
|
||||
|
||||
export class HyperlinkStyle extends CharacterStyle {
|
||||
export class HyperlinkStyle extends StyleForCharacter {
|
||||
constructor(options: IBaseCharacterStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
|
@ -6,12 +6,12 @@ import { UnderlineType } from "file/paragraph/run/underline";
|
||||
import { ShadingType } from "file/table";
|
||||
import { EMPTY_OBJECT } from "file/xml-components";
|
||||
|
||||
import { ParagraphStyle } from "./paragraph-style";
|
||||
import { StyleForParagraph } from "./paragraph-style";
|
||||
|
||||
describe("ParagraphStyle", () => {
|
||||
describe("#constructor", () => {
|
||||
it("should set the style type to paragraph and use the given style id", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId" });
|
||||
const style = new StyleForParagraph({ id: "myStyleId" });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||
@ -19,7 +19,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the name of the style, if given", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
name: "Style Name",
|
||||
});
|
||||
@ -35,7 +35,7 @@ describe("ParagraphStyle", () => {
|
||||
|
||||
describe("formatting methods: style attributes", () => {
|
||||
it("#basedOn", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId", basedOn: "otherId" });
|
||||
const style = new StyleForParagraph({ id: "myStyleId", basedOn: "otherId" });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -46,7 +46,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#quickFormat", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId", quickFormat: true });
|
||||
const style = new StyleForParagraph({ id: "myStyleId", quickFormat: true });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -62,7 +62,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#next", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId", next: "otherId" });
|
||||
const style = new StyleForParagraph({ id: "myStyleId", next: "otherId" });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -75,7 +75,7 @@ describe("ParagraphStyle", () => {
|
||||
|
||||
describe("formatting methods: paragraph properties", () => {
|
||||
it("#indent", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
indent: { left: 720 },
|
||||
@ -93,7 +93,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#spacing", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId", paragraph: { spacing: { before: 50, after: 150 } } });
|
||||
const style = new StyleForParagraph({ id: "myStyleId", paragraph: { spacing: { before: 50, after: 150 } } });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -106,7 +106,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#center", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
alignment: AlignmentType.CENTER,
|
||||
@ -124,7 +124,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#character spacing", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
characterSpacing: 24,
|
||||
@ -142,7 +142,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#left", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
alignment: AlignmentType.LEFT,
|
||||
@ -160,7 +160,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#right", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
alignment: AlignmentType.RIGHT,
|
||||
@ -178,7 +178,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#justified", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
alignment: AlignmentType.JUSTIFIED,
|
||||
@ -196,7 +196,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#thematicBreak", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
thematicBreak: true,
|
||||
@ -229,7 +229,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#contextualSpacing", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
contextualSpacing: true,
|
||||
@ -255,7 +255,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#leftTabStop", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
leftTabStop: 1200,
|
||||
@ -277,7 +277,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#maxRightTabStop", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
rightTabStop: TabStopPosition.MAX,
|
||||
@ -299,7 +299,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#keepLines", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
keepLines: true,
|
||||
@ -320,7 +320,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#keepNext", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
keepNext: true,
|
||||
@ -341,7 +341,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#outlineLevel", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
paragraph: {
|
||||
outlineLevel: 1,
|
||||
@ -381,7 +381,7 @@ describe("ParagraphStyle", () => {
|
||||
];
|
||||
sizeTests.forEach(({ size, sizeComplexScript, expected }) => {
|
||||
it(`#size ${size} cs ${sizeComplexScript}`, () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: { size, sizeComplexScript },
|
||||
});
|
||||
@ -393,7 +393,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#smallCaps", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
smallCaps: true,
|
||||
@ -411,7 +411,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#allCaps", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
allCaps: true,
|
||||
@ -429,7 +429,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#strike", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
strike: true,
|
||||
@ -447,7 +447,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#doubleStrike", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
doubleStrike: true,
|
||||
@ -465,7 +465,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#subScript", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
subScript: true,
|
||||
@ -483,7 +483,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#superScript", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
superScript: true,
|
||||
@ -501,7 +501,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#font by name", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
font: "Times",
|
||||
@ -530,7 +530,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#font for ascii and eastAsia", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
font: {
|
||||
@ -577,7 +577,7 @@ describe("ParagraphStyle", () => {
|
||||
];
|
||||
boldTests.forEach(({ bold, boldComplexScript, expected }) => {
|
||||
it(`#bold ${bold} cs ${boldComplexScript}`, () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: { bold, boldComplexScript },
|
||||
});
|
||||
@ -606,7 +606,7 @@ describe("ParagraphStyle", () => {
|
||||
];
|
||||
italicsTests.forEach(({ italics, italicsComplexScript, expected }) => {
|
||||
it(`#italics ${italics} cs ${italicsComplexScript}`, () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: { italics, italicsComplexScript },
|
||||
});
|
||||
@ -640,7 +640,7 @@ describe("ParagraphStyle", () => {
|
||||
];
|
||||
highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => {
|
||||
it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: { highlight, highlightComplexScript },
|
||||
});
|
||||
@ -714,7 +714,7 @@ describe("ParagraphStyle", () => {
|
||||
];
|
||||
shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => {
|
||||
it("#shadow correctly", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: { shadow, shading, shadingComplexScript },
|
||||
});
|
||||
@ -727,7 +727,7 @@ describe("ParagraphStyle", () => {
|
||||
|
||||
describe("#underline", () => {
|
||||
it("should set underline to 'single' if no arguments are given", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
underline: {},
|
||||
@ -745,7 +745,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the style if given", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
underline: {
|
||||
@ -765,7 +765,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the style and color if given", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
underline: {
|
||||
@ -788,7 +788,7 @@ describe("ParagraphStyle", () => {
|
||||
|
||||
describe("#emphasisMark", () => {
|
||||
it("should set emphasisMark to 'dot' if no arguments are given", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
emphasisMark: {},
|
||||
@ -806,7 +806,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the style if given", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
emphasisMark: {
|
||||
@ -827,7 +827,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#color", () => {
|
||||
const style = new ParagraphStyle({
|
||||
const style = new StyleForParagraph({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
color: "123456",
|
||||
@ -845,7 +845,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#link", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId", link: "MyLink" });
|
||||
const style = new StyleForParagraph({ id: "myStyleId", link: "MyLink" });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -861,7 +861,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#semiHidden", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId", semiHidden: true });
|
||||
const style = new StyleForParagraph({ id: "myStyleId", semiHidden: true });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -877,7 +877,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#uiPriority", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId", uiPriority: 99 });
|
||||
const style = new StyleForParagraph({ id: "myStyleId", uiPriority: 99 });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -894,7 +894,7 @@ describe("ParagraphStyle", () => {
|
||||
});
|
||||
|
||||
it("#unhideWhenUsed", () => {
|
||||
const style = new ParagraphStyle({ id: "myStyleId", unhideWhenUsed: true });
|
||||
const style = new StyleForParagraph({ id: "myStyleId", unhideWhenUsed: true });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
|
@ -21,7 +21,7 @@ export interface IParagraphStyleOptions extends IBaseParagraphStyleOptions {
|
||||
readonly name?: string;
|
||||
}
|
||||
|
||||
export class ParagraphStyle extends Style {
|
||||
export class StyleForParagraph extends Style {
|
||||
private readonly paragraphProperties: ParagraphProperties;
|
||||
private readonly runProperties: RunProperties;
|
||||
|
||||
|
@ -1,15 +1,16 @@
|
||||
import { IDefaultStylesOptions } from "file/styles/factory";
|
||||
import { BaseXmlComponent, ImportedXmlComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
import { CharacterStyle, ParagraphStyle } from "./style";
|
||||
import { StyleForCharacter, StyleForParagraph } from "./style";
|
||||
import { ICharacterStyleOptions } from "./style/character-style";
|
||||
import { IParagraphStyleOptions } from "./style/paragraph-style";
|
||||
export * from "./border";
|
||||
|
||||
export interface IStylesOptions {
|
||||
readonly default?: IDefaultStylesOptions;
|
||||
readonly initialStyles?: BaseXmlComponent;
|
||||
readonly paragraphStyles?: IParagraphStyleOptions[];
|
||||
readonly characterStyles?: ICharacterStyleOptions[];
|
||||
readonly importedStyles?: (XmlComponent | ParagraphStyle | CharacterStyle | ImportedXmlComponent)[];
|
||||
readonly importedStyles?: (XmlComponent | StyleForParagraph | StyleForCharacter | ImportedXmlComponent)[];
|
||||
}
|
||||
|
||||
export class Styles extends XmlComponent {
|
||||
@ -28,13 +29,13 @@ export class Styles extends XmlComponent {
|
||||
|
||||
if (options.paragraphStyles) {
|
||||
for (const style of options.paragraphStyles) {
|
||||
this.root.push(new ParagraphStyle(style));
|
||||
this.root.push(new StyleForParagraph(style));
|
||||
}
|
||||
}
|
||||
|
||||
if (options.characterStyles) {
|
||||
for (const style of options.characterStyles) {
|
||||
this.root.push(new CharacterStyle(style));
|
||||
this.root.push(new StyleForCharacter(style));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
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) {
|
||||
super("w:tblBorders");
|
||||
|
||||
|
@ -89,11 +89,12 @@ describe("DeletedTextRun", () => {
|
||||
describe("#break()", () => {
|
||||
it("should add a break", () => {
|
||||
const deletedTextRun = new DeletedTextRun({
|
||||
break: 1,
|
||||
children: ["some text"],
|
||||
id: 0,
|
||||
date: "123",
|
||||
author: "Author",
|
||||
}).break();
|
||||
});
|
||||
const tree = new Formatter().format(deletedTextRun);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:del": [
|
||||
|
@ -1,6 +1,6 @@
|
||||
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 { Begin, End, Separate } from "../../paragraph/run/field";
|
||||
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 { DeletedText } from "./deleted-text";
|
||||
|
||||
interface IDeletedRunOptions extends IRunPropertiesOptions, IChangedAttributesProperties {
|
||||
readonly children?: (Begin | Separate | End | PageNumber | FootnoteReferenceRun | string)[];
|
||||
readonly text?: string;
|
||||
}
|
||||
interface IDeletedRunOptions extends IRunOptions, IChangedAttributesProperties {}
|
||||
|
||||
export class DeletedTextRun extends XmlComponent {
|
||||
protected readonly deletedTextRunWrapper: DeletedTextRunWrapper;
|
||||
@ -25,14 +22,9 @@ export class DeletedTextRun extends XmlComponent {
|
||||
date: options.date,
|
||||
}),
|
||||
);
|
||||
this.deletedTextRunWrapper = new DeletedTextRunWrapper(options as IRunOptions);
|
||||
this.deletedTextRunWrapper = new DeletedTextRunWrapper(options);
|
||||
this.addChildElement(this.deletedTextRunWrapper);
|
||||
}
|
||||
|
||||
public break(): DeletedTextRun {
|
||||
this.deletedTextRunWrapper.break();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
class DeletedTextRunWrapper extends XmlComponent {
|
||||
@ -74,9 +66,11 @@ class DeletedTextRunWrapper extends XmlComponent {
|
||||
} else if (options.text) {
|
||||
this.root.push(new DeletedText(options.text));
|
||||
}
|
||||
}
|
||||
|
||||
public break(): void {
|
||||
this.root.splice(1, 0, new Break());
|
||||
if (options.break) {
|
||||
for (let i = 0; i < options.break; i++) {
|
||||
this.root.splice(1, 0, new Break());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,9 @@ export interface IDocumentTemplate {
|
||||
}
|
||||
|
||||
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 documentContent = await zipContent.files["word/document.xml"].async("text");
|
||||
|
@ -4,3 +4,4 @@ export { File as Document } from "./file";
|
||||
export * from "./file";
|
||||
export * from "./export";
|
||||
export * from "./import-dotx";
|
||||
export * from "./convenience-functions";
|
||||
|
Reference in New Issue
Block a user