Compare commits
42 Commits
Author | SHA1 | Date | |
---|---|---|---|
9e8d67c4a9 | |||
cbbc4a80e7 | |||
1f51fd7a31 | |||
120d97bc64 | |||
a531713214 | |||
564a055316 | |||
6c29c4fb1f | |||
552580bc47 | |||
0998d43b8f | |||
b08354494c | |||
f54b9a197d | |||
2d4412ce51 | |||
72c32378c5 | |||
0c79c0ac83 | |||
1dfc27ba08 | |||
58dc6fe389 | |||
34c3285426 | |||
a5afce458d | |||
2f687125d1 | |||
5c1a731314 | |||
622331ad24 | |||
3a593a53d3 | |||
31a9111667 | |||
373c890354 | |||
723d76d06f | |||
a24d745d75 | |||
90891cfafd | |||
29f890918c | |||
b0f8f8ddbd | |||
9c89c1ab59 | |||
7a9cb92955 | |||
77edf8862b | |||
bb1604cd8f | |||
816cb54b14 | |||
920bd3c175 | |||
a2a01edc24 | |||
193d0c4239 | |||
d8cc11c5ab | |||
b874051f32 | |||
272e2496f4 | |||
8f133ff93a | |||
1f12e159ef |
@ -25,7 +25,7 @@ table = doc.createTable({
|
|||||||
table
|
table
|
||||||
.getCell(0, 0)
|
.getCell(0, 0)
|
||||||
.addParagraph(new Paragraph("World"))
|
.addParagraph(new Paragraph("World"))
|
||||||
.setMargains({
|
.setMargins({
|
||||||
top: 1000,
|
top: 1000,
|
||||||
bottom: 1000,
|
bottom: 1000,
|
||||||
left: 1000,
|
left: 1000,
|
||||||
@ -40,7 +40,7 @@ table = doc.createTable({
|
|||||||
columns: 4,
|
columns: 4,
|
||||||
width: 7000,
|
width: 7000,
|
||||||
widthUnitType: WidthType.DXA,
|
widthUnitType: WidthType.DXA,
|
||||||
margains: {
|
margins: {
|
||||||
top: 400,
|
top: 400,
|
||||||
bottom: 400,
|
bottom: 400,
|
||||||
right: 400,
|
right: 400,
|
||||||
|
26
demo/demo40.ts
Normal file
26
demo/demo40.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// Example demonstrating line numbers.
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, LineNumberRestartFormat, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document(
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
lineNumberCountBy: 1,
|
||||||
|
lineNumberRestart: LineNumberRestartFormat.CONTINUOUS,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
doc.addParagraph(new Paragraph("Hello").heading1());
|
||||||
|
doc.createParagraph(
|
||||||
|
"Himenaeos duis luctus nullam fermentum lobortis potenti vivamus non dis, sed facilisis ultricies scelerisque aenean risus hac senectus. Adipiscing id venenatis justo ante gravida placerat, ac curabitur dis pellentesque proin bibendum risus, aliquam porta taciti vulputate primis. Tortor ipsum fermentum quam vel convallis primis nisl praesent tincidunt, lobortis quisque felis vitae condimentum class ut sem nam, aenean potenti pretium ac amet lacinia himenaeos mi. Aliquam nisl turpis hendrerit est morbi malesuada, augue interdum mus inceptos curabitur tristique, parturient feugiat sodales nulla facilisi. Aliquam non pulvinar purus nulla ex integer, velit faucibus vitae at bibendum quam, risus elit aenean adipiscing posuere.",
|
||||||
|
);
|
||||||
|
doc.createParagraph(
|
||||||
|
"Sed laoreet id mattis egestas nam mollis elit lacinia convallis dui tincidunt ultricies habitant, pharetra per maximus interdum neque tempor risus efficitur morbi imperdiet senectus. Lectus laoreet senectus finibus inceptos donec potenti fermentum, ultrices eleifend odio suscipit magnis tellus maximus nibh, ac sit nullam eget felis himenaeos. Diam class sem magnis aenean commodo faucibus id proin mi, nullam sodales nec mus parturient ornare ad inceptos velit hendrerit, bibendum placerat eleifend integer facilisis urna dictumst suspendisse.",
|
||||||
|
);
|
||||||
|
|
||||||
|
const packer = new Packer();
|
||||||
|
|
||||||
|
packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
36
demo/demo44.ts
Normal file
36
demo/demo44.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// Sections with multiple columns
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
column: {
|
||||||
|
width: 708,
|
||||||
|
count: 2,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.createParagraph("This text will be split into 2 columns on a page.");
|
||||||
|
doc.createParagraph(
|
||||||
|
"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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
|
||||||
|
);
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
column: {
|
||||||
|
width: 708,
|
||||||
|
count: 2,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.createParagraph("This text will be split into 3 columns on a page.");
|
||||||
|
doc.createParagraph(
|
||||||
|
"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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
|
||||||
|
);
|
||||||
|
|
||||||
|
const packer = new Packer();
|
||||||
|
|
||||||
|
packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
@ -12,13 +12,13 @@
|
|||||||
|
|
||||||
## Always think about the user
|
## Always think about the user
|
||||||
|
|
||||||
The number one pillar for contribution to `docx` is to **ALWAYS** think about how the user will use `docx`.
|
The number one pillar for contribution to `docx` is to **ALWAYS** think about how the user will use `docx`.
|
||||||
|
|
||||||
Put yourself in their position, and imagine how they would feel about your feature you wrote.
|
Put yourself in their position, and imagine how they would feel about your feature you wrote.
|
||||||
|
|
||||||
1. Is it easy to use?
|
1. Is it easy to use?
|
||||||
2. Has it been documented well?
|
2. Has it been documented well?
|
||||||
3. Is it intuative?
|
3. Is it intuitive?
|
||||||
4. Is it consistent with the rest of the API?
|
4. Is it consistent with the rest of the API?
|
||||||
5. Is it fun to use?
|
5. Is it fun to use?
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ Unesesary coment removed // Make sure to use correct spelling
|
|||||||
|
|
||||||
> This mainly applies to the API the end user will consume.
|
> This mainly applies to the API the end user will consume.
|
||||||
|
|
||||||
Try to make method parameters of the outside API accept primatives, or `json` objects, so that child components are created **inside** the component, rather than being **injected** in.
|
Try to make method parameters of the outside API accept primitives, or `json` objects, so that child components are created **inside** the component, rather than being **injected** in.
|
||||||
|
|
||||||
This is so that:
|
This is so that:
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ This is so that:
|
|||||||
```js
|
```js
|
||||||
import { ChildComponent } from "./my-feature/sub-component/deeper/.../my-deep.component";
|
import { ChildComponent } from "./my-feature/sub-component/deeper/.../my-deep.component";
|
||||||
```
|
```
|
||||||
|
|
||||||
2. This is what I consider "leakage". The code is aware of the underlying implementation of the component.
|
2. This is what I consider "leakage". The code is aware of the underlying implementation of the component.
|
||||||
3. It means the end user does not need to import and create the child component to be injected.
|
3. It means the end user does not need to import and create the child component to be injected.
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ This is so that:
|
|||||||
|
|
||||||
**Do**
|
**Do**
|
||||||
|
|
||||||
`ITableFloatOptions` is an interface for a JSON of primatives. The end user would need to pass in a json object and not need to worry about the internals:
|
`ITableFloatOptions` is an interface for a JSON of primitives. The end user would need to pass in a json object and not need to worry about the internals:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
public float(tableFloatOptions: ITableFloatOptions): Table
|
public float(tableFloatOptions: ITableFloatOptions): Table
|
||||||
@ -88,7 +88,7 @@ This is just a guideline, and the rules can sometimes be broken.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
* Use `add` if you add the element into the method as a parameter.
|
* Use `add` if you add the element into the method as a parameter.
|
||||||
*Note:* This may look like its breaking the previous guideline, but it has semantically different meanings. The previous one is using data to construct an object, whereas this one is simply adding elements into the document:
|
*Note:* This may look like its breaking the previous guideline, but it has semantically different meanings. The previous one is using data to construct an object, whereas this one is simply adding elements into the document:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
@ -112,7 +112,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo18.ts_
|
|||||||
|
|
||||||
## Margins
|
## Margins
|
||||||
|
|
||||||
Example showing how to set custom margains
|
Example showing how to set custom margins
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo6.ts ':include')
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo6.ts ':include')
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ doc.Header.createImage([BUFFER_OF_YOUR_IMAGE]);
|
|||||||
doc.Footer.createImage([BUFFER_OF_YOUR_IMAGE]);
|
doc.Footer.createImage([BUFFER_OF_YOUR_IMAGE]);
|
||||||
```
|
```
|
||||||
|
|
||||||
Refer to `demo8.js` for more information
|
Refer to [`demo8.ts`](https://github.com/dolanmiu/docx/blob/master/demo/demo8.ts) for more information.
|
||||||
|
|
||||||
## Multiple Headers and Footers
|
## Multiple Headers and Footers
|
||||||
|
|
||||||
@ -38,10 +38,10 @@ Also all the supported section properties are implemented according to: http://o
|
|||||||
// Add new section with another header and footer
|
// Add new section with another header and footer
|
||||||
doc.addSection({
|
doc.addSection({
|
||||||
headers: {
|
headers: {
|
||||||
default: header
|
default: header
|
||||||
},
|
},
|
||||||
footers: {
|
footers: {
|
||||||
default: footer
|
default: footer
|
||||||
},
|
},
|
||||||
pageNumberStart: 1,
|
pageNumberStart: 1,
|
||||||
pageNumberFormatType: docx.PageNumberFormat.DECIMAL,
|
pageNumberFormatType: docx.PageNumberFormat.DECIMAL,
|
||||||
|
47
docs/usage/hyperlinks.md
Normal file
47
docs/usage/hyperlinks.md
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# Hyperlinks
|
||||||
|
|
||||||
|
There are two types of hyperlinks: internal (pointing to a bookmark inside the document) and external (pointing to an external url).
|
||||||
|
|
||||||
|
## Internal
|
||||||
|
|
||||||
|
To create an internal hyperlink you need first to create a bookmark (the paragraph that will be the destination of the hyperlink) with `doc.createBookmark(anchor, text)`.
|
||||||
|
|
||||||
|
A bookmark is composed of an anchor (an identifier) and the text displayed. After creating a bookmark just add it to a paragraph with `paragraph.addBookmark(bookmark)`
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = this.doc.createParagraph();
|
||||||
|
const bookmark = this.doc.createBookmark('anchorForChapter1', 'This is chapter1');
|
||||||
|
paragraph.addBookmark(bookmark);
|
||||||
|
```
|
||||||
|
|
||||||
|
Then you can create an hyperlink pointing to that bookmark with `doc.createInternalHyperLink(anchor,text)`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = this.doc.createParagraph();
|
||||||
|
const link = this.doc.createInternalHyperLink('anchorForChapter1', 'This is a link to chapter1');
|
||||||
|
paragraph.addHyperLink(link);
|
||||||
|
```
|
||||||
|
|
||||||
|
## External
|
||||||
|
|
||||||
|
To create an external hyperlink you just need to specify the url and the text of the link, then add it to a paragraph with `doc.createHyperlink(url, text)`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = this.doc.createParagraph();
|
||||||
|
const link = this.doc.createHyperlink('https://docx.js.org', 'This is an external link');
|
||||||
|
paragraph.addHyperLink(link);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Styling an hyperlink
|
||||||
|
|
||||||
|
It is possible to set the style of the text of an hyperlink. This can be done applying run formatting on `TextRun` property of the hyperlink.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const link = this.doc.createHyperlink('https://docx.js.org', 'This is an external link');
|
||||||
|
link.TextRun.bold().italics()
|
||||||
|
```
|
@ -76,6 +76,22 @@ paragraph.heading1().center();
|
|||||||
|
|
||||||
The above will create a `heading 1` which is `centered`.
|
The above will create a `heading 1` which is `centered`.
|
||||||
|
|
||||||
|
### Justified text with breaks
|
||||||
|
|
||||||
|
When a paragraph is justified, you may want to not justify the contents of incomplete lines, which end in a soft line break.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
This is possible to achieve using:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
this.doc.Settings.addCompatibility().doNotExpandShiftReturn();
|
||||||
|
```
|
||||||
|
|
||||||
|
The result is:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Thematic Break
|
## Thematic Break
|
||||||
|
|
||||||
To add a break in the page, simply add `.thematicBreak()` on a paragraph:
|
To add a break in the page, simply add `.thematicBreak()` on a paragraph:
|
||||||
@ -106,7 +122,7 @@ var paragraph = new docx.Paragraph("Hello World on another page").pageBreakBefor
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
Example: https://github.com/dolanmiu/docx/blob/master/demo/demo15.js
|
Example: https://github.com/dolanmiu/docx/blob/master/demo/demo15.ts
|
||||||
|
|
||||||
## Page break control
|
## Page break control
|
||||||
|
|
||||||
|
@ -44,4 +44,4 @@ doc.addParagraph(paragraph);
|
|||||||
doc.createParagraph("Some normal text");
|
doc.createParagraph("Some normal text");
|
||||||
```
|
```
|
||||||
|
|
||||||
Example: https://github.com/dolanmiu/docx/blob/master/demo/demo13.js
|
Example: https://github.com/dolanmiu/docx/blob/master/demo/demo13.ts
|
||||||
|
@ -96,6 +96,28 @@ Once you have got the cell, you can add data to it with the `addParagraph()` met
|
|||||||
cell.addParagraph(new Paragraph("Hello"));
|
cell.addParagraph(new Paragraph("Hello"));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Set width of a cell
|
||||||
|
|
||||||
|
You can specify the width of a cell using:
|
||||||
|
|
||||||
|
`cell.Properties.setWidth(width, format)`
|
||||||
|
|
||||||
|
format can be:
|
||||||
|
* WidthType.AUTO
|
||||||
|
* WidthType.DXA: value is in twentieths of a point
|
||||||
|
* WidthType.NIL: is considered as zero
|
||||||
|
* WidthType.PCT: percent of table width
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
cell.Properties.setWidth(100, WidthType.DXA);
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
cell.Properties.setWidth('50%', WidthType.PCT);
|
||||||
|
```
|
||||||
|
|
||||||
## Borders
|
## Borders
|
||||||
|
|
||||||
BorderStyle can be imported from `docx`. Size determines the thickness. HTML color can be a hex code or alias such as `red`.
|
BorderStyle can be imported from `docx`. Size determines the thickness. HTML color can be a hex code or alias such as `red`.
|
||||||
@ -122,7 +144,18 @@ cell.Borders.addEndBorder([BorderStyle], [SIZE], [HTML COLOR]);
|
|||||||
import { BorderStyle } from "docx";
|
import { BorderStyle } from "docx";
|
||||||
|
|
||||||
cell.Borders.addStartBorder(BorderStyle.DOT_DOT_DASH, 3, "green");
|
cell.Borders.addStartBorder(BorderStyle.DOT_DOT_DASH, 3, "green");
|
||||||
cell.Borders.addStartBorder(BorderStyle.DOT_DOT_DASH, 3, "#ff8000");
|
cell.Borders.addEndBorder(BorderStyle.DOT_DOT_DASH, 3, "#ff8000");
|
||||||
|
```
|
||||||
|
|
||||||
|
### Google DOCS
|
||||||
|
|
||||||
|
Google DOCS does not support start and end borders, instead they use left and right borders. So to set left and right borders for Google DOCS you should use:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { BorderStyle } from "docx";
|
||||||
|
|
||||||
|
cell.Borders.addLeftBorder(BorderStyle.DOT_DOT_DASH, 3, "green");
|
||||||
|
cell.Borders.addRightBorder(BorderStyle.DOT_DOT_DASH, 3, "#ff8000");
|
||||||
```
|
```
|
||||||
|
|
||||||
## Set Width
|
## Set Width
|
||||||
@ -193,6 +226,23 @@ To have a table within a table
|
|||||||
cell.addTable(new Table(1, 1));
|
cell.addTable(new Table(1, 1));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Pagination
|
||||||
|
|
||||||
|
###Prevent row pagination
|
||||||
|
To prevent breaking contents of a row across multiple pages, call `cantSplit()`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
table.getRow(0).setCantSplit();
|
||||||
|
```
|
||||||
|
|
||||||
|
###Repeat row
|
||||||
|
If a table is paginated on multiple pages, it is possible to repeat a row at the top of each new page calling `setTableHeader()`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
table.getRow(0).setTableHeader();
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo4.ts ':include')
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo4.ts ':include')
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "docx",
|
"name": "docx",
|
||||||
"version": "5.0.0-rc1",
|
"version": "5.0.0-rc4",
|
||||||
"description": "Generate .docx documents with JavaScript (formerly Office-Clippy)",
|
"description": "Generate .docx documents with JavaScript (formerly Office-Clippy)",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -19,6 +19,7 @@
|
|||||||
"style.fix": "npm run style -- --write",
|
"style.fix": "npm run style -- --write",
|
||||||
"fix-types": "ts-node scripts/types-absolute-fixer.ts",
|
"fix-types": "ts-node scripts/types-absolute-fixer.ts",
|
||||||
"e2e": "ts-node scripts/e2e.ts",
|
"e2e": "ts-node scripts/e2e.ts",
|
||||||
|
"serve.docs": "cd docs && docsify serve",
|
||||||
"ts-node": "ts-node"
|
"ts-node": "ts-node"
|
||||||
},
|
},
|
||||||
"pre-commit": [
|
"pre-commit": [
|
||||||
@ -67,6 +68,7 @@
|
|||||||
"@types/webpack": "^4.4.24",
|
"@types/webpack": "^4.4.24",
|
||||||
"awesome-typescript-loader": "^3.4.1",
|
"awesome-typescript-loader": "^3.4.1",
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
|
"docsify": "^4.9.1",
|
||||||
"glob": "^7.1.2",
|
"glob": "^7.1.2",
|
||||||
"istanbul-instrumenter-loader": "^3.0.1",
|
"istanbul-instrumenter-loader": "^3.0.1",
|
||||||
"jszip": "^3.1.5",
|
"jszip": "^3.1.5",
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import { assert } from "chai";
|
import { assert, expect } from "chai";
|
||||||
|
|
||||||
import { Formatter } from "../export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
import * as file from "../file";
|
import * as file from "file";
|
||||||
import { CoreProperties } from "../file/core-properties";
|
import { CoreProperties } from "file/core-properties";
|
||||||
import { Attributes } from "../file/xml-components";
|
import { Attributes } from "file/xml-components";
|
||||||
import { Utility } from "../tests/utility";
|
|
||||||
|
|
||||||
describe("Formatter", () => {
|
describe("Formatter", () => {
|
||||||
let formatter: Formatter;
|
let formatter: Formatter;
|
||||||
@ -31,33 +30,31 @@ describe("Formatter", () => {
|
|||||||
const paragraph = new file.Paragraph();
|
const paragraph = new file.Paragraph();
|
||||||
paragraph.addRun(new file.TextRun("test").bold());
|
paragraph.addRun(new file.TextRun("test").bold());
|
||||||
const newJson = formatter.format(paragraph);
|
const newJson = formatter.format(paragraph);
|
||||||
assert.isDefined(newJson["w:p"][1]["w:r"][0]["w:rPr"][0]["w:b"][0]._attr["w:val"]);
|
assert.isDefined(newJson["w:p"][0]["w:r"][0]["w:rPr"][0]["w:b"]._attr["w:val"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should format attributes (rsidSect)", () => {
|
it("should format attributes (rsidSect)", () => {
|
||||||
const attributes = new Attributes({
|
const attributes = new Attributes({
|
||||||
rsidSect: "test2",
|
rsidSect: "test2",
|
||||||
});
|
});
|
||||||
let newJson = formatter.format(attributes);
|
const tree = formatter.format(attributes);
|
||||||
newJson = Utility.jsonify(newJson);
|
expect(tree).to.deep.equal({
|
||||||
if (newJson._attr === undefined) {
|
_attr: {
|
||||||
assert.fail();
|
"w:rsidSect": "test2",
|
||||||
return;
|
},
|
||||||
}
|
});
|
||||||
assert.isDefined(newJson._attr["w:rsidSect"]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should format attributes (val)", () => {
|
it("should format attributes (val)", () => {
|
||||||
const attributes = new Attributes({
|
const attributes = new Attributes({
|
||||||
val: "test",
|
val: "test",
|
||||||
});
|
});
|
||||||
let newJson = formatter.format(attributes);
|
const tree = formatter.format(attributes);
|
||||||
newJson = Utility.jsonify(newJson);
|
expect(tree).to.deep.equal({
|
||||||
if (newJson._attr === undefined) {
|
_attr: {
|
||||||
assert.fail();
|
"w:val": "test",
|
||||||
return;
|
},
|
||||||
}
|
});
|
||||||
assert.isDefined(newJson._attr["w:val"]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should should change 'p' tag into 'w:p' tag", () => {
|
it("should should change 'p' tag into 'w:p' tag", () => {
|
||||||
|
@ -30,10 +30,12 @@ interface IXmlifyedFileMapping {
|
|||||||
export class Compiler {
|
export class Compiler {
|
||||||
private readonly formatter: Formatter;
|
private readonly formatter: Formatter;
|
||||||
private readonly imageReplacer: ImageReplacer;
|
private readonly imageReplacer: ImageReplacer;
|
||||||
|
private readonly prettifyXml?: boolean;
|
||||||
|
|
||||||
constructor() {
|
constructor(prettifyXml?: boolean) {
|
||||||
this.formatter = new Formatter();
|
this.formatter = new Formatter();
|
||||||
this.imageReplacer = new ImageReplacer();
|
this.imageReplacer = new ImageReplacer();
|
||||||
|
this.prettifyXml = prettifyXml;
|
||||||
}
|
}
|
||||||
|
|
||||||
public compile(file: File): JSZip {
|
public compile(file: File): JSZip {
|
||||||
@ -71,7 +73,7 @@ export class Compiler {
|
|||||||
return {
|
return {
|
||||||
Relationships: {
|
Relationships: {
|
||||||
data: (() => {
|
data: (() => {
|
||||||
const xmlData = xml(this.formatter.format(file.Document));
|
const xmlData = xml(this.formatter.format(file.Document), this.prettifyXml);
|
||||||
const mediaDatas = this.imageReplacer.getMediaData(xmlData, file.Media);
|
const mediaDatas = this.imageReplacer.getMediaData(xmlData, file.Media);
|
||||||
|
|
||||||
mediaDatas.forEach((mediaData, i) => {
|
mediaDatas.forEach((mediaData, i) => {
|
||||||
@ -82,13 +84,13 @@ export class Compiler {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
return xml(this.formatter.format(file.DocumentRelationships));
|
return xml(this.formatter.format(file.DocumentRelationships), this.prettifyXml);
|
||||||
})(),
|
})(),
|
||||||
path: "word/_rels/document.xml.rels",
|
path: "word/_rels/document.xml.rels",
|
||||||
},
|
},
|
||||||
Document: {
|
Document: {
|
||||||
data: (() => {
|
data: (() => {
|
||||||
const tempXmlData = xml(this.formatter.format(file.Document), true);
|
const tempXmlData = xml(this.formatter.format(file.Document), this.prettifyXml);
|
||||||
const mediaDatas = this.imageReplacer.getMediaData(tempXmlData, file.Media);
|
const mediaDatas = this.imageReplacer.getMediaData(tempXmlData, file.Media);
|
||||||
const xmlData = this.imageReplacer.replace(tempXmlData, mediaDatas, documentRelationshipCount);
|
const xmlData = this.imageReplacer.replace(tempXmlData, mediaDatas, documentRelationshipCount);
|
||||||
|
|
||||||
@ -97,7 +99,7 @@ export class Compiler {
|
|||||||
path: "word/document.xml",
|
path: "word/document.xml",
|
||||||
},
|
},
|
||||||
Styles: {
|
Styles: {
|
||||||
data: xml(this.formatter.format(file.Styles)),
|
data: xml(this.formatter.format(file.Styles), this.prettifyXml),
|
||||||
path: "word/styles.xml",
|
path: "word/styles.xml",
|
||||||
},
|
},
|
||||||
Properties: {
|
Properties: {
|
||||||
@ -110,15 +112,15 @@ export class Compiler {
|
|||||||
path: "docProps/core.xml",
|
path: "docProps/core.xml",
|
||||||
},
|
},
|
||||||
Numbering: {
|
Numbering: {
|
||||||
data: xml(this.formatter.format(file.Numbering)),
|
data: xml(this.formatter.format(file.Numbering), this.prettifyXml),
|
||||||
path: "word/numbering.xml",
|
path: "word/numbering.xml",
|
||||||
},
|
},
|
||||||
FileRelationships: {
|
FileRelationships: {
|
||||||
data: xml(this.formatter.format(file.FileRelationships)),
|
data: xml(this.formatter.format(file.FileRelationships), this.prettifyXml),
|
||||||
path: "_rels/.rels",
|
path: "_rels/.rels",
|
||||||
},
|
},
|
||||||
HeaderRelationships: file.Headers.map((headerWrapper, index) => {
|
HeaderRelationships: file.Headers.map((headerWrapper, index) => {
|
||||||
const xmlData = xml(this.formatter.format(headerWrapper.Header));
|
const xmlData = xml(this.formatter.format(headerWrapper.Header), this.prettifyXml);
|
||||||
const mediaDatas = this.imageReplacer.getMediaData(xmlData, file.Media);
|
const mediaDatas = this.imageReplacer.getMediaData(xmlData, file.Media);
|
||||||
|
|
||||||
mediaDatas.forEach((mediaData, i) => {
|
mediaDatas.forEach((mediaData, i) => {
|
||||||
@ -130,12 +132,12 @@ export class Compiler {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: xml(this.formatter.format(headerWrapper.Relationships)),
|
data: xml(this.formatter.format(headerWrapper.Relationships), this.prettifyXml),
|
||||||
path: `word/_rels/header${index + 1}.xml.rels`,
|
path: `word/_rels/header${index + 1}.xml.rels`,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
FooterRelationships: file.Footers.map((footerWrapper, index) => {
|
FooterRelationships: file.Footers.map((footerWrapper, index) => {
|
||||||
const xmlData = xml(this.formatter.format(footerWrapper.Footer));
|
const xmlData = xml(this.formatter.format(footerWrapper.Footer), this.prettifyXml);
|
||||||
const mediaDatas = this.imageReplacer.getMediaData(xmlData, file.Media);
|
const mediaDatas = this.imageReplacer.getMediaData(xmlData, file.Media);
|
||||||
|
|
||||||
mediaDatas.forEach((mediaData, i) => {
|
mediaDatas.forEach((mediaData, i) => {
|
||||||
@ -147,12 +149,12 @@ export class Compiler {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: xml(this.formatter.format(footerWrapper.Relationships)),
|
data: xml(this.formatter.format(footerWrapper.Relationships), this.prettifyXml),
|
||||||
path: `word/_rels/footer${index + 1}.xml.rels`,
|
path: `word/_rels/footer${index + 1}.xml.rels`,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
Headers: file.Headers.map((headerWrapper, index) => {
|
Headers: file.Headers.map((headerWrapper, index) => {
|
||||||
const tempXmlData = xml(this.formatter.format(headerWrapper.Header));
|
const tempXmlData = xml(this.formatter.format(headerWrapper.Header), this.prettifyXml);
|
||||||
const mediaDatas = this.imageReplacer.getMediaData(tempXmlData, file.Media);
|
const mediaDatas = this.imageReplacer.getMediaData(tempXmlData, file.Media);
|
||||||
// TODO: 0 needs to be changed when headers get relationships of their own
|
// TODO: 0 needs to be changed when headers get relationships of their own
|
||||||
const xmlData = this.imageReplacer.replace(tempXmlData, mediaDatas, 0);
|
const xmlData = this.imageReplacer.replace(tempXmlData, mediaDatas, 0);
|
||||||
@ -163,7 +165,7 @@ export class Compiler {
|
|||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
Footers: file.Footers.map((footerWrapper, index) => {
|
Footers: file.Footers.map((footerWrapper, index) => {
|
||||||
const tempXmlData = xml(this.formatter.format(footerWrapper.Footer));
|
const tempXmlData = xml(this.formatter.format(footerWrapper.Footer), this.prettifyXml);
|
||||||
const mediaDatas = this.imageReplacer.getMediaData(tempXmlData, file.Media);
|
const mediaDatas = this.imageReplacer.getMediaData(tempXmlData, file.Media);
|
||||||
// TODO: 0 needs to be changed when headers get relationships of their own
|
// TODO: 0 needs to be changed when headers get relationships of their own
|
||||||
const xmlData = this.imageReplacer.replace(tempXmlData, mediaDatas, 0);
|
const xmlData = this.imageReplacer.replace(tempXmlData, mediaDatas, 0);
|
||||||
@ -174,30 +176,21 @@ export class Compiler {
|
|||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
ContentTypes: {
|
ContentTypes: {
|
||||||
data: xml(this.formatter.format(file.ContentTypes)),
|
data: xml(this.formatter.format(file.ContentTypes), this.prettifyXml),
|
||||||
path: "[Content_Types].xml",
|
path: "[Content_Types].xml",
|
||||||
},
|
},
|
||||||
AppProperties: {
|
AppProperties: {
|
||||||
data: xml(this.formatter.format(file.AppProperties)),
|
data: xml(this.formatter.format(file.AppProperties), this.prettifyXml),
|
||||||
path: "docProps/app.xml",
|
path: "docProps/app.xml",
|
||||||
},
|
},
|
||||||
FootNotes: {
|
FootNotes: {
|
||||||
data: xml(this.formatter.format(file.FootNotes)),
|
data: xml(this.formatter.format(file.FootNotes), this.prettifyXml),
|
||||||
path: "word/footnotes.xml",
|
path: "word/footnotes.xml",
|
||||||
},
|
},
|
||||||
Settings: {
|
Settings: {
|
||||||
data: xml(this.formatter.format(file.Settings)),
|
data: xml(this.formatter.format(file.Settings), this.prettifyXml),
|
||||||
path: "word/settings.xml",
|
path: "word/settings.xml",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/* By default docx collapse empty tags. <a></a> -> <a/>. this function mimic it
|
|
||||||
so comparing (diff) original docx file and the library output is easier
|
|
||||||
Currently not used, so commenting out */
|
|
||||||
// private collapseEmptyTags(xmlData: string): string {
|
|
||||||
// const regEx = /<(([^ <>]+)[^<>]*)><\/\2>/g;
|
|
||||||
// const collapsed = xmlData.replace(regEx, "<$1/>");
|
|
||||||
// return collapsed;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,8 @@ import { Compiler } from "./next-compiler";
|
|||||||
export class Packer {
|
export class Packer {
|
||||||
private readonly compiler: Compiler;
|
private readonly compiler: Compiler;
|
||||||
|
|
||||||
constructor() {
|
constructor(prettifyXml?: boolean) {
|
||||||
this.compiler = new Compiler();
|
this.compiler = new Compiler(prettifyXml);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async toBuffer(file: File): Promise<Buffer> {
|
public async toBuffer(file: File): Promise<Buffer> {
|
||||||
|
@ -20,84 +20,70 @@ describe("ContentTypes", () => {
|
|||||||
expect(tree["Types"]).to.be.an.instanceof(Array);
|
expect(tree["Types"]).to.be.an.instanceof(Array);
|
||||||
|
|
||||||
expect(tree["Types"][0]).to.deep.equal({ _attr: { xmlns: "http://schemas.openxmlformats.org/package/2006/content-types" } });
|
expect(tree["Types"][0]).to.deep.equal({ _attr: { xmlns: "http://schemas.openxmlformats.org/package/2006/content-types" } });
|
||||||
expect(tree["Types"][1]).to.deep.equal({ Default: [{ _attr: { ContentType: "image/png", Extension: "png" } }] });
|
expect(tree["Types"][1]).to.deep.equal({ Default: { _attr: { ContentType: "image/png", Extension: "png" } } });
|
||||||
expect(tree["Types"][2]).to.deep.equal({ Default: [{ _attr: { ContentType: "image/jpeg", Extension: "jpeg" } }] });
|
expect(tree["Types"][2]).to.deep.equal({ Default: { _attr: { ContentType: "image/jpeg", Extension: "jpeg" } } });
|
||||||
expect(tree["Types"][3]).to.deep.equal({ Default: [{ _attr: { ContentType: "image/jpeg", Extension: "jpg" } }] });
|
expect(tree["Types"][3]).to.deep.equal({ Default: { _attr: { ContentType: "image/jpeg", Extension: "jpg" } } });
|
||||||
expect(tree["Types"][4]).to.deep.equal({ Default: [{ _attr: { ContentType: "image/bmp", Extension: "bmp" } }] });
|
expect(tree["Types"][4]).to.deep.equal({ Default: { _attr: { ContentType: "image/bmp", Extension: "bmp" } } });
|
||||||
expect(tree["Types"][5]).to.deep.equal({ Default: [{ _attr: { ContentType: "image/gif", Extension: "gif" } }] });
|
expect(tree["Types"][5]).to.deep.equal({ Default: { _attr: { ContentType: "image/gif", Extension: "gif" } } });
|
||||||
expect(tree["Types"][6]).to.deep.equal({
|
expect(tree["Types"][6]).to.deep.equal({
|
||||||
Default: [{ _attr: { ContentType: "application/vnd.openxmlformats-package.relationships+xml", Extension: "rels" } }],
|
Default: { _attr: { ContentType: "application/vnd.openxmlformats-package.relationships+xml", Extension: "rels" } },
|
||||||
});
|
});
|
||||||
expect(tree["Types"][7]).to.deep.equal({ Default: [{ _attr: { ContentType: "application/xml", Extension: "xml" } }] });
|
expect(tree["Types"][7]).to.deep.equal({ Default: { _attr: { ContentType: "application/xml", Extension: "xml" } } });
|
||||||
expect(tree["Types"][8]).to.deep.equal({
|
expect(tree["Types"][8]).to.deep.equal({
|
||||||
Override: [
|
Override: {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",
|
||||||
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",
|
PartName: "/word/document.xml",
|
||||||
PartName: "/word/document.xml",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
expect(tree["Types"][9]).to.deep.equal({
|
expect(tree["Types"][9]).to.deep.equal({
|
||||||
Override: [
|
Override: {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml",
|
||||||
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml",
|
PartName: "/word/styles.xml",
|
||||||
PartName: "/word/styles.xml",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
expect(tree["Types"][10]).to.deep.equal({
|
expect(tree["Types"][10]).to.deep.equal({
|
||||||
Override: [
|
Override: {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
ContentType: "application/vnd.openxmlformats-package.core-properties+xml",
|
||||||
ContentType: "application/vnd.openxmlformats-package.core-properties+xml",
|
PartName: "/docProps/core.xml",
|
||||||
PartName: "/docProps/core.xml",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
expect(tree["Types"][11]).to.deep.equal({
|
expect(tree["Types"][11]).to.deep.equal({
|
||||||
Override: [
|
Override: {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
ContentType: "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
||||||
ContentType: "application/vnd.openxmlformats-officedocument.extended-properties+xml",
|
PartName: "/docProps/app.xml",
|
||||||
PartName: "/docProps/app.xml",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
expect(tree["Types"][12]).to.deep.equal({
|
expect(tree["Types"][12]).to.deep.equal({
|
||||||
Override: [
|
Override: {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml",
|
||||||
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml",
|
PartName: "/word/numbering.xml",
|
||||||
PartName: "/word/numbering.xml",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
expect(tree["Types"][13]).to.deep.equal({
|
expect(tree["Types"][13]).to.deep.equal({
|
||||||
Override: [
|
Override: {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml",
|
||||||
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml",
|
PartName: "/word/footnotes.xml",
|
||||||
PartName: "/word/footnotes.xml",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
expect(tree["Types"][14]).to.deep.equal({
|
expect(tree["Types"][14]).to.deep.equal({
|
||||||
Override: [
|
Override: {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml",
|
||||||
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml",
|
PartName: "/word/settings.xml",
|
||||||
PartName: "/word/settings.xml",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -109,25 +95,21 @@ describe("ContentTypes", () => {
|
|||||||
const tree = new Formatter().format(contentTypes);
|
const tree = new Formatter().format(contentTypes);
|
||||||
|
|
||||||
expect(tree["Types"][15]).to.deep.equal({
|
expect(tree["Types"][15]).to.deep.equal({
|
||||||
Override: [
|
Override: {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml",
|
||||||
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml",
|
PartName: "/word/footer101.xml",
|
||||||
PartName: "/word/footer101.xml",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(tree["Types"][16]).to.deep.equal({
|
expect(tree["Types"][16]).to.deep.equal({
|
||||||
Override: [
|
Override: {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml",
|
||||||
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml",
|
PartName: "/word/footer102.xml",
|
||||||
PartName: "/word/footer102.xml",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -139,25 +121,21 @@ describe("ContentTypes", () => {
|
|||||||
const tree = new Formatter().format(contentTypes);
|
const tree = new Formatter().format(contentTypes);
|
||||||
|
|
||||||
expect(tree["Types"][15]).to.deep.equal({
|
expect(tree["Types"][15]).to.deep.equal({
|
||||||
Override: [
|
Override: {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml",
|
||||||
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml",
|
PartName: "/word/header201.xml",
|
||||||
PartName: "/word/header201.xml",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(tree["Types"][16]).to.deep.equal({
|
expect(tree["Types"][16]).to.deep.equal({
|
||||||
Override: [
|
Override: {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml",
|
||||||
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml",
|
PartName: "/word/header202.xml",
|
||||||
PartName: "/word/header202.xml",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -30,14 +30,14 @@ describe("Body", () => {
|
|||||||
|
|
||||||
const formatted = new Formatter().format(body)["w:body"];
|
const formatted = new Formatter().format(body)["w:body"];
|
||||||
expect(formatted).to.be.an.instanceof(Array);
|
expect(formatted).to.be.an.instanceof(Array);
|
||||||
const defaultSectionPr = formatted[0]["w:p"][1]["w:pPr"][0]["w:sectPr"];
|
const defaultSectionPr = formatted[0]["w:p"][0]["w:pPr"][0]["w:sectPr"];
|
||||||
|
|
||||||
// check that this is the default section and added first in paragraph
|
// check that this is the default section and added first in paragraph
|
||||||
expect(defaultSectionPr[0]).to.deep.equal({ "w:pgSz": [{ _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } }] });
|
expect(defaultSectionPr[0]).to.deep.equal({ "w:pgSz": { _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } } });
|
||||||
|
|
||||||
// check for new section (since it's the last one, it's direct child of body)
|
// check for new section (since it's the last one, it's direct child of body)
|
||||||
const newSection = formatted[1]["w:sectPr"];
|
const newSection = formatted[1]["w:sectPr"];
|
||||||
expect(newSection[0]).to.deep.equal({ "w:pgSz": [{ _attr: { "w:h": 10000, "w:w": 10000, "w:orient": "portrait" } }] });
|
expect(newSection[0]).to.deep.equal({ "w:pgSz": { _attr: { "w:h": 10000, "w:w": 10000, "w:orient": "portrait" } } });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should add section with default parameters", () => {
|
it("should add section with default parameters", () => {
|
||||||
@ -52,30 +52,27 @@ describe("Body", () => {
|
|||||||
"w:body": [
|
"w:body": [
|
||||||
{
|
{
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{ "w:pPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:pPr": [
|
"w:pPr": [
|
||||||
{
|
{
|
||||||
"w:sectPr": [
|
"w:sectPr": [
|
||||||
{ "w:pgSz": [{ _attr: { "w:w": 11906, "w:h": 16838, "w:orient": "portrait" } }] },
|
{ "w:pgSz": { _attr: { "w:w": 11906, "w:h": 16838, "w:orient": "portrait" } } },
|
||||||
{
|
{
|
||||||
"w:pgMar": [
|
"w:pgMar": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:top": 1440,
|
||||||
"w:top": 1440,
|
"w:right": 1440,
|
||||||
"w:right": 1440,
|
"w:bottom": 1440,
|
||||||
"w:bottom": 1440,
|
"w:left": 1440,
|
||||||
"w:left": 1440,
|
"w:header": 708,
|
||||||
"w:header": 708,
|
"w:footer": 708,
|
||||||
"w:footer": 708,
|
"w:gutter": 0,
|
||||||
"w:gutter": 0,
|
"w:mirrorMargins": false,
|
||||||
"w:mirrorMargins": false,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{ "w:cols": [{ _attr: { "w:space": 708 } }] },
|
{ "w:cols": { _attr: { "w:space": 708, "w:num": 1 } } },
|
||||||
{ "w:docGrid": [{ _attr: { "w:linePitch": 360 } }] },
|
{ "w:docGrid": { _attr: { "w:linePitch": 360 } } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -84,25 +81,23 @@ describe("Body", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:sectPr": [
|
"w:sectPr": [
|
||||||
{ "w:pgSz": [{ _attr: { "w:w": 10000, "w:h": 10000, "w:orient": "portrait" } }] },
|
{ "w:pgSz": { _attr: { "w:w": 10000, "w:h": 10000, "w:orient": "portrait" } } },
|
||||||
{
|
{
|
||||||
"w:pgMar": [
|
"w:pgMar": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:top": 1440,
|
||||||
"w:top": 1440,
|
"w:right": 1440,
|
||||||
"w:right": 1440,
|
"w:bottom": 1440,
|
||||||
"w:bottom": 1440,
|
"w:left": 1440,
|
||||||
"w:left": 1440,
|
"w:header": 708,
|
||||||
"w:header": 708,
|
"w:footer": 708,
|
||||||
"w:footer": 708,
|
"w:gutter": 0,
|
||||||
"w:gutter": 0,
|
"w:mirrorMargins": false,
|
||||||
"w:mirrorMargins": false,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{ "w:cols": [{ _attr: { "w:space": 708 } }] },
|
{ "w:cols": { _attr: { "w:space": 708, "w:num": 1 } } },
|
||||||
{ "w:docGrid": [{ _attr: { "w:linePitch": 360 } }] },
|
{ "w:docGrid": { _attr: { "w:linePitch": 360 } } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -37,7 +37,7 @@ export class Body extends XmlComponent {
|
|||||||
}
|
}
|
||||||
public prepForXml(): IXmlableObject | undefined {
|
public prepForXml(): IXmlableObject | undefined {
|
||||||
if (this.sections.length === 1) {
|
if (this.sections.length === 1) {
|
||||||
this.root.push(this.sections[0]);
|
this.root.push(this.sections.pop() as SectionProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.prepForXml();
|
return super.prepForXml();
|
||||||
|
@ -2,10 +2,12 @@ import { XmlAttributeComponent } from "file/xml-components";
|
|||||||
|
|
||||||
export interface IColumnsAttributes {
|
export interface IColumnsAttributes {
|
||||||
readonly space?: number;
|
readonly space?: number;
|
||||||
|
readonly num?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ColumnsAttributes extends XmlAttributeComponent<IColumnsAttributes> {
|
export class ColumnsAttributes extends XmlAttributeComponent<IColumnsAttributes> {
|
||||||
protected readonly xmlKeys = {
|
protected readonly xmlKeys = {
|
||||||
space: "w:space",
|
space: "w:space",
|
||||||
|
num: "w:num",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,12 @@ import { XmlComponent } from "file/xml-components";
|
|||||||
import { ColumnsAttributes } from "./columns-attributes";
|
import { ColumnsAttributes } from "./columns-attributes";
|
||||||
|
|
||||||
export class Columns extends XmlComponent {
|
export class Columns extends XmlComponent {
|
||||||
constructor(space: number) {
|
constructor(space: number, num: number) {
|
||||||
super("w:cols");
|
super("w:cols");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new ColumnsAttributes({
|
new ColumnsAttributes({
|
||||||
space: space,
|
space: space,
|
||||||
|
num: num,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4,3 +4,4 @@ export * from "./header-reference";
|
|||||||
export * from "./page-size";
|
export * from "./page-size";
|
||||||
export * from "./page-number";
|
export * from "./page-number";
|
||||||
export * from "./page-border";
|
export * from "./page-border";
|
||||||
|
export * from "./line-number";
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
export * from "./line-number";
|
@ -0,0 +1,38 @@
|
|||||||
|
// http://officeopenxml.com/WPsectionLineNumbering.php
|
||||||
|
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
|
export enum LineNumberRestartFormat {
|
||||||
|
CONTINUOUS = "continuous",
|
||||||
|
NEW_SECTION = "newSection",
|
||||||
|
NEW_PAGE = "newPage",
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ILineNumberAttributes {
|
||||||
|
readonly lineNumberCountBy?: number;
|
||||||
|
readonly lineNumberStart?: number;
|
||||||
|
readonly lineNumberRestart?: LineNumberRestartFormat;
|
||||||
|
readonly lineNumberDistance?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class LineNumberAttributes extends XmlAttributeComponent<ILineNumberAttributes> {
|
||||||
|
protected readonly xmlKeys = {
|
||||||
|
lineNumberCountBy: "w:countBy",
|
||||||
|
lineNumberStart: "w:start",
|
||||||
|
lineNumberRestart: "w:restart",
|
||||||
|
lineNumberDistance: "w:distance",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export class LineNumberType extends XmlComponent {
|
||||||
|
constructor(countBy?: number, start?: number, restart?: LineNumberRestartFormat, dist?: number) {
|
||||||
|
super("w:lnNumType");
|
||||||
|
this.root.push(
|
||||||
|
new LineNumberAttributes({
|
||||||
|
lineNumberCountBy: countBy,
|
||||||
|
lineNumberStart: start,
|
||||||
|
lineNumberRestart: restart,
|
||||||
|
lineNumberDistance: dist,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -21,8 +21,7 @@ describe("PageBorders", () => {
|
|||||||
const tree = new Formatter().format(properties);
|
const tree = new Formatter().format(properties);
|
||||||
|
|
||||||
expect(Object.keys(tree)).to.deep.equal(["w:pgBorders"]);
|
expect(Object.keys(tree)).to.deep.equal(["w:pgBorders"]);
|
||||||
expect(tree["w:pgBorders"]).to.be.an.instanceof(Array);
|
expect(tree["w:pgBorders"]).to.deep.equal({ _attr: { "w:display": "firstPage" } });
|
||||||
expect(tree["w:pgBorders"][0]).to.deep.equal({ _attr: { "w:display": "firstPage" } });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create page borders with full configuration", () => {
|
it("should create page borders with full configuration", () => {
|
||||||
@ -58,32 +57,24 @@ describe("PageBorders", () => {
|
|||||||
expect(tree["w:pgBorders"]).to.be.an.instanceof(Array);
|
expect(tree["w:pgBorders"]).to.be.an.instanceof(Array);
|
||||||
expect(tree["w:pgBorders"][0]).to.deep.equal({ _attr: { "w:display": "firstPage", "w:zOrder": "back" } });
|
expect(tree["w:pgBorders"][0]).to.deep.equal({ _attr: { "w:display": "firstPage", "w:zOrder": "back" } });
|
||||||
expect(tree["w:pgBorders"][1]).to.deep.equal({
|
expect(tree["w:pgBorders"][1]).to.deep.equal({
|
||||||
"w:top": [
|
"w:top": {
|
||||||
{
|
_attr: { "w:color": "001122", "w:size": 10, "w:val": "doubleWave" },
|
||||||
_attr: { "w:color": "001122", "w:size": 10, "w:val": "doubleWave" },
|
},
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
expect(tree["w:pgBorders"][2]).to.deep.equal({
|
expect(tree["w:pgBorders"][2]).to.deep.equal({
|
||||||
"w:right": [
|
"w:right": {
|
||||||
{
|
_attr: { "w:color": "223344", "w:size": 20, "w:val": "double" },
|
||||||
_attr: { "w:color": "223344", "w:size": 20, "w:val": "double" },
|
},
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
expect(tree["w:pgBorders"][3]).to.deep.equal({
|
expect(tree["w:pgBorders"][3]).to.deep.equal({
|
||||||
"w:bottom": [
|
"w:bottom": {
|
||||||
{
|
_attr: { "w:color": "556677", "w:size": 30, "w:val": "single" },
|
||||||
_attr: { "w:color": "556677", "w:size": 30, "w:val": "single" },
|
},
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
expect(tree["w:pgBorders"][4]).to.deep.equal({
|
expect(tree["w:pgBorders"][4]).to.deep.equal({
|
||||||
"w:left": [
|
"w:left": {
|
||||||
{
|
_attr: { "w:color": "889900", "w:size": 40, "w:val": "dotted" },
|
||||||
_attr: { "w:color": "889900", "w:size": 40, "w:val": "dotted" },
|
},
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// http://officeopenxml.com/WPsectionBorders.php
|
// http://officeopenxml.com/WPsectionBorders.php
|
||||||
import { BorderStyle } from "file/styles";
|
import { BorderStyle } from "file/styles";
|
||||||
import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
export enum PageBorderDisplay {
|
export enum PageBorderDisplay {
|
||||||
ALL_PAGES = "allPages",
|
ALL_PAGES = "allPages",
|
||||||
@ -64,7 +64,7 @@ class PageBordersAttributes extends XmlAttributeComponent<IPageBorderAttributes>
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PageBorders extends XmlComponent {
|
export class PageBorders extends IgnoreIfEmptyXmlComponent {
|
||||||
constructor(options?: IPageBordersOptions) {
|
constructor(options?: IPageBordersOptions) {
|
||||||
super("w:pgBorders");
|
super("w:pgBorders");
|
||||||
|
|
||||||
@ -97,10 +97,4 @@ export class PageBorders extends XmlComponent {
|
|||||||
this.root.push(new PageBorder("w:left", options.pageBorderLeft));
|
this.root.push(new PageBorder("w:left", options.pageBorderLeft));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public prepForXml(): IXmlableObject | undefined {
|
|
||||||
if (this.root.length > 0) {
|
|
||||||
return super.prepForXml();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,7 @@ describe("PageSize", () => {
|
|||||||
const tree = new Formatter().format(properties);
|
const tree = new Formatter().format(properties);
|
||||||
|
|
||||||
expect(Object.keys(tree)).to.deep.equal(["w:pgSz"]);
|
expect(Object.keys(tree)).to.deep.equal(["w:pgSz"]);
|
||||||
expect(tree["w:pgSz"]).to.be.an.instanceof(Array);
|
expect(tree["w:pgSz"]).to.deep.equal({ _attr: { "w:h": 200, "w:w": 100, "w:orient": "portrait" } });
|
||||||
expect(tree["w:pgSz"][0]).to.deep.equal({ _attr: { "w:h": 200, "w:w": 100, "w:orient": "portrait" } });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create page size with horizontal and invert the lengths", () => {
|
it("should create page size with horizontal and invert the lengths", () => {
|
||||||
@ -21,8 +20,7 @@ describe("PageSize", () => {
|
|||||||
const tree = new Formatter().format(properties);
|
const tree = new Formatter().format(properties);
|
||||||
|
|
||||||
expect(Object.keys(tree)).to.deep.equal(["w:pgSz"]);
|
expect(Object.keys(tree)).to.deep.equal(["w:pgSz"]);
|
||||||
expect(tree["w:pgSz"]).to.be.an.instanceof(Array);
|
expect(tree["w:pgSz"]).to.deep.equal({ _attr: { "w:h": 100, "w:w": 200, "w:orient": "landscape" } });
|
||||||
expect(tree["w:pgSz"][0]).to.deep.equal({ _attr: { "w:h": 100, "w:w": 200, "w:orient": "landscape" } });
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -25,7 +25,10 @@ describe("SectionProperties", () => {
|
|||||||
footer: 708,
|
footer: 708,
|
||||||
gutter: 0,
|
gutter: 0,
|
||||||
mirror: false,
|
mirror: false,
|
||||||
space: 708,
|
column: {
|
||||||
|
space: 708,
|
||||||
|
count: 1,
|
||||||
|
},
|
||||||
linePitch: 360,
|
linePitch: 360,
|
||||||
headers: {
|
headers: {
|
||||||
default: new HeaderWrapper(media, 100),
|
default: new HeaderWrapper(media, 100),
|
||||||
@ -39,29 +42,27 @@ describe("SectionProperties", () => {
|
|||||||
const tree = new Formatter().format(properties);
|
const tree = new Formatter().format(properties);
|
||||||
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
||||||
expect(tree["w:sectPr"]).to.be.an.instanceof(Array);
|
expect(tree["w:sectPr"]).to.be.an.instanceof(Array);
|
||||||
expect(tree["w:sectPr"][0]).to.deep.equal({ "w:pgSz": [{ _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } }] });
|
expect(tree["w:sectPr"][0]).to.deep.equal({ "w:pgSz": { _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } } });
|
||||||
expect(tree["w:sectPr"][1]).to.deep.equal({
|
expect(tree["w:sectPr"][1]).to.deep.equal({
|
||||||
"w:pgMar": [
|
"w:pgMar": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:bottom": 1440,
|
||||||
"w:bottom": 1440,
|
"w:footer": 708,
|
||||||
"w:footer": 708,
|
"w:top": 1440,
|
||||||
"w:top": 1440,
|
"w:right": 1440,
|
||||||
"w:right": 1440,
|
"w:left": 1440,
|
||||||
"w:left": 1440,
|
"w:header": 708,
|
||||||
"w:header": 708,
|
"w:gutter": 0,
|
||||||
"w:gutter": 0,
|
"w:mirrorMargins": false,
|
||||||
"w:mirrorMargins": false,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(tree["w:sectPr"][2]).to.deep.equal({ "w:cols": [{ _attr: { "w:space": 708 } }] });
|
expect(tree["w:sectPr"][2]).to.deep.equal({ "w:cols": { _attr: { "w:space": 708, "w:num": 1 } } });
|
||||||
expect(tree["w:sectPr"][3]).to.deep.equal({ "w:docGrid": [{ _attr: { "w:linePitch": 360 } }] });
|
expect(tree["w:sectPr"][3]).to.deep.equal({ "w:docGrid": { _attr: { "w:linePitch": 360 } } });
|
||||||
expect(tree["w:sectPr"][4]).to.deep.equal({ "w:headerReference": [{ _attr: { "r:id": "rId100", "w:type": "default" } }] });
|
expect(tree["w:sectPr"][4]).to.deep.equal({ "w:headerReference": { _attr: { "r:id": "rId100", "w:type": "default" } } });
|
||||||
expect(tree["w:sectPr"][5]).to.deep.equal({ "w:footerReference": [{ _attr: { "r:id": "rId200", "w:type": "even" } }] });
|
expect(tree["w:sectPr"][5]).to.deep.equal({ "w:footerReference": { _attr: { "r:id": "rId200", "w:type": "even" } } });
|
||||||
expect(tree["w:sectPr"][6]).to.deep.equal({ "w:pgNumType": [{ _attr: { "w:fmt": "cardinalText", "w:start": 10 } }] });
|
expect(tree["w:sectPr"][6]).to.deep.equal({ "w:pgNumType": { _attr: { "w:fmt": "cardinalText", "w:start": 10 } } });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create section properties with no options", () => {
|
it("should create section properties with no options", () => {
|
||||||
@ -69,25 +70,23 @@ describe("SectionProperties", () => {
|
|||||||
const tree = new Formatter().format(properties);
|
const tree = new Formatter().format(properties);
|
||||||
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
||||||
expect(tree["w:sectPr"]).to.be.an.instanceof(Array);
|
expect(tree["w:sectPr"]).to.be.an.instanceof(Array);
|
||||||
expect(tree["w:sectPr"][0]).to.deep.equal({ "w:pgSz": [{ _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } }] });
|
expect(tree["w:sectPr"][0]).to.deep.equal({ "w:pgSz": { _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } } });
|
||||||
expect(tree["w:sectPr"][1]).to.deep.equal({
|
expect(tree["w:sectPr"][1]).to.deep.equal({
|
||||||
"w:pgMar": [
|
"w:pgMar": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:bottom": 1440,
|
||||||
"w:bottom": 1440,
|
"w:footer": 708,
|
||||||
"w:footer": 708,
|
"w:top": 1440,
|
||||||
"w:top": 1440,
|
"w:right": 1440,
|
||||||
"w:right": 1440,
|
"w:left": 1440,
|
||||||
"w:left": 1440,
|
"w:header": 708,
|
||||||
"w:header": 708,
|
"w:gutter": 0,
|
||||||
"w:gutter": 0,
|
"w:mirrorMargins": false,
|
||||||
"w:mirrorMargins": false,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
expect(tree["w:sectPr"][2]).to.deep.equal({ "w:cols": [{ _attr: { "w:space": 708 } }] });
|
expect(tree["w:sectPr"][2]).to.deep.equal({ "w:cols": { _attr: { "w:space": 708, "w:num": 1 } } });
|
||||||
expect(tree["w:sectPr"][3]).to.deep.equal({ "w:docGrid": [{ _attr: { "w:linePitch": 360 } }] });
|
expect(tree["w:sectPr"][3]).to.deep.equal({ "w:docGrid": { _attr: { "w:linePitch": 360 } } });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create section properties with changed options", () => {
|
it("should create section properties with changed options", () => {
|
||||||
@ -97,22 +96,20 @@ describe("SectionProperties", () => {
|
|||||||
const tree = new Formatter().format(properties);
|
const tree = new Formatter().format(properties);
|
||||||
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
||||||
expect(tree["w:sectPr"]).to.be.an.instanceof(Array);
|
expect(tree["w:sectPr"]).to.be.an.instanceof(Array);
|
||||||
expect(tree["w:sectPr"][0]).to.deep.equal({ "w:pgSz": [{ _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } }] });
|
expect(tree["w:sectPr"][0]).to.deep.equal({ "w:pgSz": { _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } } });
|
||||||
expect(tree["w:sectPr"][1]).to.deep.equal({
|
expect(tree["w:sectPr"][1]).to.deep.equal({
|
||||||
"w:pgMar": [
|
"w:pgMar": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:bottom": 1440,
|
||||||
"w:bottom": 1440,
|
"w:footer": 708,
|
||||||
"w:footer": 708,
|
"w:top": 0,
|
||||||
"w:top": 0,
|
"w:right": 1440,
|
||||||
"w:right": 1440,
|
"w:left": 1440,
|
||||||
"w:left": 1440,
|
"w:header": 708,
|
||||||
"w:header": 708,
|
"w:gutter": 0,
|
||||||
"w:gutter": 0,
|
"w:mirrorMargins": false,
|
||||||
"w:mirrorMargins": false,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -123,22 +120,20 @@ describe("SectionProperties", () => {
|
|||||||
const tree = new Formatter().format(properties);
|
const tree = new Formatter().format(properties);
|
||||||
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
||||||
expect(tree["w:sectPr"]).to.be.an.instanceof(Array);
|
expect(tree["w:sectPr"]).to.be.an.instanceof(Array);
|
||||||
expect(tree["w:sectPr"][0]).to.deep.equal({ "w:pgSz": [{ _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } }] });
|
expect(tree["w:sectPr"][0]).to.deep.equal({ "w:pgSz": { _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } } });
|
||||||
expect(tree["w:sectPr"][1]).to.deep.equal({
|
expect(tree["w:sectPr"][1]).to.deep.equal({
|
||||||
"w:pgMar": [
|
"w:pgMar": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:bottom": 0,
|
||||||
"w:bottom": 0,
|
"w:footer": 708,
|
||||||
"w:footer": 708,
|
"w:top": 1440,
|
||||||
"w:top": 1440,
|
"w:right": 1440,
|
||||||
"w:right": 1440,
|
"w:left": 1440,
|
||||||
"w:left": 1440,
|
"w:header": 708,
|
||||||
"w:header": 708,
|
"w:gutter": 0,
|
||||||
"w:gutter": 0,
|
"w:mirrorMargins": false,
|
||||||
"w:mirrorMargins": false,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -150,22 +145,20 @@ describe("SectionProperties", () => {
|
|||||||
const tree = new Formatter().format(properties);
|
const tree = new Formatter().format(properties);
|
||||||
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
||||||
expect(tree["w:sectPr"]).to.be.an.instanceof(Array);
|
expect(tree["w:sectPr"]).to.be.an.instanceof(Array);
|
||||||
expect(tree["w:sectPr"][0]).to.deep.equal({ "w:pgSz": [{ _attr: { "w:h": 0, "w:w": 0, "w:orient": "portrait" } }] });
|
expect(tree["w:sectPr"][0]).to.deep.equal({ "w:pgSz": { _attr: { "w:h": 0, "w:w": 0, "w:orient": "portrait" } } });
|
||||||
expect(tree["w:sectPr"][1]).to.deep.equal({
|
expect(tree["w:sectPr"][1]).to.deep.equal({
|
||||||
"w:pgMar": [
|
"w:pgMar": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:bottom": 1440,
|
||||||
"w:bottom": 1440,
|
"w:footer": 708,
|
||||||
"w:footer": 708,
|
"w:top": 1440,
|
||||||
"w:top": 1440,
|
"w:right": 1440,
|
||||||
"w:right": 1440,
|
"w:left": 1440,
|
||||||
"w:left": 1440,
|
"w:header": 708,
|
||||||
"w:header": 708,
|
"w:gutter": 0,
|
||||||
"w:gutter": 0,
|
"w:mirrorMargins": false,
|
||||||
"w:mirrorMargins": false,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -179,7 +172,7 @@ describe("SectionProperties", () => {
|
|||||||
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
||||||
const pgBorders = tree["w:sectPr"].find((item) => item["w:pgBorders"] !== undefined);
|
const pgBorders = tree["w:sectPr"].find((item) => item["w:pgBorders"] !== undefined);
|
||||||
expect(pgBorders).to.deep.equal({
|
expect(pgBorders).to.deep.equal({
|
||||||
"w:pgBorders": [{ _attr: { "w:offsetFrom": "page" } }],
|
"w:pgBorders": { _attr: { "w:offsetFrom": "page" } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -191,7 +184,7 @@ describe("SectionProperties", () => {
|
|||||||
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
||||||
const pgNumType = tree["w:sectPr"].find((item) => item["w:pgNumType"] !== undefined);
|
const pgNumType = tree["w:sectPr"].find((item) => item["w:pgNumType"] !== undefined);
|
||||||
expect(pgNumType).to.deep.equal({
|
expect(pgNumType).to.deep.equal({
|
||||||
"w:pgNumType": [{ _attr: { "w:fmt": "upperRoman" } }],
|
"w:pgNumType": { _attr: { "w:fmt": "upperRoman" } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -4,13 +4,13 @@ import { HeaderWrapper } from "file/header-wrapper";
|
|||||||
import { XmlComponent } from "file/xml-components";
|
import { XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
import { Columns } from "./columns/columns";
|
import { Columns } from "./columns/columns";
|
||||||
import { IColumnsAttributes } from "./columns/columns-attributes";
|
|
||||||
import { DocumentGrid } from "./doc-grid/doc-grid";
|
import { DocumentGrid } from "./doc-grid/doc-grid";
|
||||||
import { IDocGridAttributesProperties } from "./doc-grid/doc-grid-attributes";
|
import { IDocGridAttributesProperties } from "./doc-grid/doc-grid-attributes";
|
||||||
import { FooterReferenceType } from "./footer-reference";
|
import { FooterReferenceType } from "./footer-reference";
|
||||||
import { FooterReference } from "./footer-reference/footer-reference";
|
import { FooterReference } from "./footer-reference/footer-reference";
|
||||||
import { HeaderReferenceType } from "./header-reference";
|
import { HeaderReferenceType } from "./header-reference";
|
||||||
import { HeaderReference } from "./header-reference/header-reference";
|
import { HeaderReference } from "./header-reference/header-reference";
|
||||||
|
import { ILineNumberAttributes, LineNumberType } from "./line-number";
|
||||||
import { IPageBordersOptions, PageBorders } from "./page-border";
|
import { IPageBordersOptions, PageBorders } from "./page-border";
|
||||||
import { PageMargin } from "./page-margin/page-margin";
|
import { PageMargin } from "./page-margin/page-margin";
|
||||||
import { IPageMarginAttributes } from "./page-margin/page-margin-attributes";
|
import { IPageMarginAttributes } from "./page-margin/page-margin-attributes";
|
||||||
@ -39,18 +39,24 @@ interface ITitlePageOptions {
|
|||||||
|
|
||||||
export type SectionPropertiesOptions = IPageSizeAttributes &
|
export type SectionPropertiesOptions = IPageSizeAttributes &
|
||||||
IPageMarginAttributes &
|
IPageMarginAttributes &
|
||||||
IColumnsAttributes &
|
|
||||||
IDocGridAttributesProperties &
|
IDocGridAttributesProperties &
|
||||||
IHeadersOptions &
|
IHeadersOptions &
|
||||||
IFootersOptions &
|
IFootersOptions &
|
||||||
IPageNumberTypeAttributes &
|
IPageNumberTypeAttributes &
|
||||||
|
ILineNumberAttributes &
|
||||||
IPageBordersOptions &
|
IPageBordersOptions &
|
||||||
ITitlePageOptions;
|
ITitlePageOptions & {
|
||||||
|
readonly column?: {
|
||||||
|
readonly space?: number;
|
||||||
|
readonly count?: number;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
// Need to decouple this from the attributes
|
||||||
|
|
||||||
export class SectionProperties extends XmlComponent {
|
export class SectionProperties extends XmlComponent {
|
||||||
private readonly options: SectionPropertiesOptions;
|
private readonly options: SectionPropertiesOptions;
|
||||||
|
|
||||||
constructor(options: SectionPropertiesOptions = {}) {
|
constructor(options: SectionPropertiesOptions = { column: {} }) {
|
||||||
super("w:sectPr");
|
super("w:sectPr");
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -64,13 +70,17 @@ export class SectionProperties extends XmlComponent {
|
|||||||
footer = 708,
|
footer = 708,
|
||||||
gutter = 0,
|
gutter = 0,
|
||||||
mirror = false,
|
mirror = false,
|
||||||
space = 708,
|
column = {},
|
||||||
linePitch = 360,
|
linePitch = 360,
|
||||||
orientation = PageOrientation.PORTRAIT,
|
orientation = PageOrientation.PORTRAIT,
|
||||||
headers,
|
headers,
|
||||||
footers,
|
footers,
|
||||||
pageNumberFormatType,
|
pageNumberFormatType,
|
||||||
pageNumberStart,
|
pageNumberStart,
|
||||||
|
lineNumberCountBy,
|
||||||
|
lineNumberStart,
|
||||||
|
lineNumberRestart,
|
||||||
|
lineNumberDistance,
|
||||||
pageBorders,
|
pageBorders,
|
||||||
pageBorderTop,
|
pageBorderTop,
|
||||||
pageBorderRight,
|
pageBorderRight,
|
||||||
@ -82,7 +92,7 @@ export class SectionProperties extends XmlComponent {
|
|||||||
this.options = options;
|
this.options = options;
|
||||||
this.root.push(new PageSize(width, height, orientation));
|
this.root.push(new PageSize(width, height, orientation));
|
||||||
this.root.push(new PageMargin(top, right, bottom, left, header, footer, gutter, mirror));
|
this.root.push(new PageMargin(top, right, bottom, left, header, footer, gutter, mirror));
|
||||||
this.root.push(new Columns(space));
|
this.root.push(new Columns(column.space ? column.space : 708, column.count ? column.count : 1));
|
||||||
this.root.push(new DocumentGrid(linePitch));
|
this.root.push(new DocumentGrid(linePitch));
|
||||||
|
|
||||||
this.addHeaders(headers);
|
this.addHeaders(headers);
|
||||||
@ -92,6 +102,10 @@ export class SectionProperties extends XmlComponent {
|
|||||||
this.root.push(new PageNumberType(pageNumberStart, pageNumberFormatType));
|
this.root.push(new PageNumberType(pageNumberStart, pageNumberFormatType));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lineNumberCountBy || lineNumberStart || lineNumberRestart || lineNumberDistance) {
|
||||||
|
this.root.push(new LineNumberType(lineNumberCountBy, lineNumberStart, lineNumberRestart, lineNumberDistance));
|
||||||
|
}
|
||||||
|
|
||||||
if (pageBorders || pageBorderTop || pageBorderRight || pageBorderBottom || pageBorderLeft) {
|
if (pageBorders || pageBorderTop || pageBorderRight || pageBorderBottom || pageBorderLeft) {
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new PageBorders({
|
new PageBorders({
|
||||||
|
@ -11,8 +11,7 @@ describe("PageSize", () => {
|
|||||||
const tree = new Formatter().format(properties);
|
const tree = new Formatter().format(properties);
|
||||||
|
|
||||||
expect(Object.keys(tree)).to.deep.equal(["w:titlePg"]);
|
expect(Object.keys(tree)).to.deep.equal(["w:titlePg"]);
|
||||||
expect(tree["w:titlePg"]).to.be.an.instanceof(Array);
|
expect(tree["w:titlePg"]).to.deep.equal({ _attr: { "w:val": "1" } });
|
||||||
expect(tree["w:titlePg"][0]).to.deep.equal({ _attr: { "w:val": "1" } });
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -52,7 +52,7 @@ describe("Document", () => {
|
|||||||
expect(body[0])
|
expect(body[0])
|
||||||
.to.have.property("w:p")
|
.to.have.property("w:p")
|
||||||
.which.includes({
|
.which.includes({
|
||||||
"w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "sample paragraph text"] }],
|
"w:r": [{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "sample paragraph text"] }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -84,9 +84,9 @@ describe("Document", () => {
|
|||||||
.to.have.property("w:tbl")
|
.to.have.property("w:tbl")
|
||||||
.which.includes({
|
.which.includes({
|
||||||
"w:tblGrid": [
|
"w:tblGrid": [
|
||||||
{ "w:gridCol": [{ _attr: { "w:w": 100 } }] },
|
{ "w:gridCol": { _attr: { "w:w": 100 } } },
|
||||||
{ "w:gridCol": [{ _attr: { "w:w": 100 } }] },
|
{ "w:gridCol": { _attr: { "w:w": 100 } } },
|
||||||
{ "w:gridCol": [{ _attr: { "w:w": 100 } }] },
|
{ "w:gridCol": { _attr: { "w:w": 100 } } },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
expect(body[0]["w:tbl"].filter((x) => x["w:tr"])).to.have.length(2);
|
expect(body[0]["w:tbl"].filter((x) => x["w:tr"])).to.have.length(2);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { assert } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Utility } from "tests/utility";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { Drawing, IDrawingOptions } from "./drawing";
|
import { Drawing, IDrawingOptions } from "./drawing";
|
||||||
|
|
||||||
@ -32,16 +32,181 @@ describe("Drawing", () => {
|
|||||||
let currentBreak: Drawing;
|
let currentBreak: Drawing;
|
||||||
|
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a Drawing with correct root key", () => {
|
|
||||||
currentBreak = createDrawing();
|
|
||||||
const newJson = Utility.jsonify(currentBreak);
|
|
||||||
assert.equal(newJson.rootKey, "w:drawing");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should create a drawing with inline element when there are no options passed", () => {
|
it("should create a drawing with inline element when there are no options passed", () => {
|
||||||
currentBreak = createDrawing();
|
currentBreak = createDrawing();
|
||||||
const newJson = Utility.jsonify(currentBreak);
|
const tree = new Formatter().format(currentBreak);
|
||||||
assert.equal(newJson.root[0].rootKey, "wp:inline");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:drawing": [
|
||||||
|
{
|
||||||
|
"wp:inline": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
distB: 0,
|
||||||
|
distL: 0,
|
||||||
|
distR: 0,
|
||||||
|
distT: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:extent": {
|
||||||
|
_attr: {
|
||||||
|
cx: 952500,
|
||||||
|
cy: 952500,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:effectExtent": {
|
||||||
|
_attr: {
|
||||||
|
b: 0,
|
||||||
|
l: 0,
|
||||||
|
r: 0,
|
||||||
|
t: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:docPr": {
|
||||||
|
_attr: {
|
||||||
|
descr: "",
|
||||||
|
id: 0,
|
||||||
|
name: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:cNvGraphicFramePr": [
|
||||||
|
{
|
||||||
|
"a:graphicFrameLocks": {
|
||||||
|
_attr: {
|
||||||
|
// tslint:disable-next-line:object-literal-key-quotes
|
||||||
|
noChangeAspect: 1,
|
||||||
|
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:graphic": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:graphicData": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
uri: "http://schemas.openxmlformats.org/drawingml/2006/picture",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pic:pic": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"xmlns:pic": "http://schemas.openxmlformats.org/drawingml/2006/picture",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pic:nvPicPr": [
|
||||||
|
{
|
||||||
|
"pic:cNvPr": {
|
||||||
|
_attr: {
|
||||||
|
desc: "",
|
||||||
|
id: 0,
|
||||||
|
name: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pic:cNvPicPr": [
|
||||||
|
{
|
||||||
|
"a:picLocks": {
|
||||||
|
_attr: {
|
||||||
|
noChangeArrowheads: 1,
|
||||||
|
noChangeAspect: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pic:blipFill": [
|
||||||
|
{
|
||||||
|
"a:blip": {
|
||||||
|
_attr: {
|
||||||
|
// tslint:disable-next-line:object-literal-key-quotes
|
||||||
|
cstate: "none",
|
||||||
|
"r:embed": "rId{test.jpg}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:srcRect": {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:stretch": [
|
||||||
|
{
|
||||||
|
"a:fillRect": {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pic:spPr": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
bwMode: "auto",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:xfrm": [
|
||||||
|
{
|
||||||
|
"a:ext": {
|
||||||
|
_attr: {
|
||||||
|
cx: 952500,
|
||||||
|
cy: 952500,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:off": {
|
||||||
|
_attr: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:prstGeom": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
prst: "rect",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:avLst": {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create a drawing with anchor element when there options are passed", () => {
|
it("should create a drawing with anchor element when there options are passed", () => {
|
||||||
@ -55,8 +220,220 @@ describe("Drawing", () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const newJson = Utility.jsonify(currentBreak);
|
const tree = new Formatter().format(currentBreak);
|
||||||
assert.equal(newJson.root[0].rootKey, "wp:anchor");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:drawing": [
|
||||||
|
{
|
||||||
|
"wp:anchor": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
allowOverlap: "1",
|
||||||
|
behindDoc: "0",
|
||||||
|
distB: 0,
|
||||||
|
distL: 0,
|
||||||
|
distR: 0,
|
||||||
|
distT: 0,
|
||||||
|
layoutInCell: "1",
|
||||||
|
locked: "0",
|
||||||
|
relativeHeight: 952500,
|
||||||
|
simplePos: "0",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:simplePos": {
|
||||||
|
_attr: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:positionH": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
relativeFrom: "page",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:posOffset": ["0"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:positionV": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
relativeFrom: "page",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:posOffset": ["0"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:extent": {
|
||||||
|
_attr: {
|
||||||
|
cx: 952500,
|
||||||
|
cy: 952500,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:effectExtent": {
|
||||||
|
_attr: {
|
||||||
|
b: 0,
|
||||||
|
l: 0,
|
||||||
|
r: 0,
|
||||||
|
t: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:wrapNone": {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:docPr": {
|
||||||
|
_attr: {
|
||||||
|
descr: "",
|
||||||
|
id: 0,
|
||||||
|
name: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:cNvGraphicFramePr": [
|
||||||
|
{
|
||||||
|
"a:graphicFrameLocks": {
|
||||||
|
_attr: {
|
||||||
|
// tslint:disable-next-line:object-literal-key-quotes
|
||||||
|
noChangeAspect: 1,
|
||||||
|
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:graphic": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:graphicData": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
uri: "http://schemas.openxmlformats.org/drawingml/2006/picture",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pic:pic": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"xmlns:pic": "http://schemas.openxmlformats.org/drawingml/2006/picture",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pic:nvPicPr": [
|
||||||
|
{
|
||||||
|
"pic:cNvPr": {
|
||||||
|
_attr: {
|
||||||
|
desc: "",
|
||||||
|
id: 0,
|
||||||
|
name: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pic:cNvPicPr": [
|
||||||
|
{
|
||||||
|
"a:picLocks": {
|
||||||
|
_attr: {
|
||||||
|
noChangeArrowheads: 1,
|
||||||
|
noChangeAspect: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pic:blipFill": [
|
||||||
|
{
|
||||||
|
"a:blip": {
|
||||||
|
_attr: {
|
||||||
|
// tslint:disable-next-line:object-literal-key-quotes
|
||||||
|
cstate: "none",
|
||||||
|
"r:embed": "rId{test.jpg}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:srcRect": {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:stretch": [
|
||||||
|
{
|
||||||
|
"a:fillRect": {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pic:spPr": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
bwMode: "auto",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:xfrm": [
|
||||||
|
{
|
||||||
|
"a:ext": {
|
||||||
|
_attr: {
|
||||||
|
cx: 952500,
|
||||||
|
cy: 952500,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:off": {
|
||||||
|
_attr: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:prstGeom": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
prst: "rect",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:avLst": {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { assert } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Utility } from "tests/utility";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { Align } from "./align";
|
import { Align } from "./align";
|
||||||
import { VerticalPositionAlign } from "./floating-position";
|
import { VerticalPositionAlign } from "./floating-position";
|
||||||
@ -8,9 +8,10 @@ import { VerticalPositionAlign } from "./floating-position";
|
|||||||
describe("Align", () => {
|
describe("Align", () => {
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a element with correct root key", () => {
|
it("should create a element with correct root key", () => {
|
||||||
const newJson = Utility.jsonify(new Align(VerticalPositionAlign.CENTER));
|
const tree = new Formatter().format(new Align(VerticalPositionAlign.CENTER));
|
||||||
assert.equal(newJson.rootKey, "wp:align");
|
expect(tree).to.deep.equal({
|
||||||
assert.include(newJson.root[0], VerticalPositionAlign.CENTER);
|
"wp:align": ["center"],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { assert } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Utility } from "tests/utility";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { HorizontalPositionAlign, HorizontalPositionRelativeFrom } from "./floating-position";
|
import { HorizontalPositionAlign, HorizontalPositionRelativeFrom } from "./floating-position";
|
||||||
import { HorizontalPosition } from "./horizontal-position";
|
import { HorizontalPosition } from "./horizontal-position";
|
||||||
@ -8,35 +8,45 @@ import { HorizontalPosition } from "./horizontal-position";
|
|||||||
describe("HorizontalPosition", () => {
|
describe("HorizontalPosition", () => {
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a element with position align", () => {
|
it("should create a element with position align", () => {
|
||||||
const newJson = Utility.jsonify(
|
const tree = new Formatter().format(
|
||||||
new HorizontalPosition({
|
new HorizontalPosition({
|
||||||
relative: HorizontalPositionRelativeFrom.MARGIN,
|
relative: HorizontalPositionRelativeFrom.MARGIN,
|
||||||
align: HorizontalPositionAlign.CENTER,
|
align: HorizontalPositionAlign.CENTER,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
assert.equal(newJson.rootKey, "wp:positionH");
|
expect(tree).to.deep.equal({
|
||||||
assert.include(newJson.root[0].root, {
|
"wp:positionH": [
|
||||||
relativeFrom: "margin",
|
{
|
||||||
|
_attr: {
|
||||||
|
relativeFrom: "margin",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:align": ["center"],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(newJson.root[1].rootKey, "wp:align");
|
|
||||||
assert.include(newJson.root[1].root, "center");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create a element with offset", () => {
|
it("should create a element with offset", () => {
|
||||||
const newJson = Utility.jsonify(
|
const tree = new Formatter().format(
|
||||||
new HorizontalPosition({
|
new HorizontalPosition({
|
||||||
relative: HorizontalPositionRelativeFrom.MARGIN,
|
relative: HorizontalPositionRelativeFrom.MARGIN,
|
||||||
offset: 40,
|
offset: 40,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
assert.equal(newJson.rootKey, "wp:positionH");
|
expect(tree).to.deep.equal({
|
||||||
assert.include(newJson.root[0].root, {
|
"wp:positionH": [
|
||||||
relativeFrom: "margin",
|
{
|
||||||
|
_attr: {
|
||||||
|
relativeFrom: "margin",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:posOffset": ["40"],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(newJson.root[1].rootKey, "wp:posOffset");
|
|
||||||
assert.include(newJson.root[1].root[0], 40);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
import { assert } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Utility } from "tests/utility";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { PositionOffset } from "./position-offset";
|
import { PositionOffset } from "./position-offset";
|
||||||
|
|
||||||
describe("PositionOffset", () => {
|
describe("PositionOffset", () => {
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a element with correct root key", () => {
|
it("should create a element with correct root key", () => {
|
||||||
const newJson = Utility.jsonify(new PositionOffset(50));
|
const tree = new Formatter().format(new PositionOffset(50));
|
||||||
assert.equal(newJson.rootKey, "wp:posOffset");
|
expect(tree).to.deep.equal({
|
||||||
assert.equal(newJson.root[0], 50);
|
"wp:posOffset": ["50"],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
import { assert } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Utility } from "tests/utility";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { SimplePos } from "./simple-pos";
|
import { SimplePos } from "./simple-pos";
|
||||||
|
|
||||||
describe("SimplePos", () => {
|
describe("SimplePos", () => {
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a element with correct root key", () => {
|
it("should create a element with correct root key", () => {
|
||||||
const newJson = Utility.jsonify(new SimplePos());
|
const tree = new Formatter().format(new SimplePos());
|
||||||
assert.equal(newJson.rootKey, "wp:simplePos");
|
expect(tree).to.deep.equal({
|
||||||
assert.include(newJson.root[0].root, {
|
"wp:simplePos": {
|
||||||
x: 0,
|
_attr: {
|
||||||
y: 0,
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { assert } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Utility } from "tests/utility";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { VerticalPositionAlign, VerticalPositionRelativeFrom } from "./floating-position";
|
import { VerticalPositionAlign, VerticalPositionRelativeFrom } from "./floating-position";
|
||||||
import { VerticalPosition } from "./vertical-position";
|
import { VerticalPosition } from "./vertical-position";
|
||||||
@ -8,35 +8,45 @@ import { VerticalPosition } from "./vertical-position";
|
|||||||
describe("VerticalPosition", () => {
|
describe("VerticalPosition", () => {
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a element with position align", () => {
|
it("should create a element with position align", () => {
|
||||||
const newJson = Utility.jsonify(
|
const tree = new Formatter().format(
|
||||||
new VerticalPosition({
|
new VerticalPosition({
|
||||||
relative: VerticalPositionRelativeFrom.MARGIN,
|
relative: VerticalPositionRelativeFrom.MARGIN,
|
||||||
align: VerticalPositionAlign.INSIDE,
|
align: VerticalPositionAlign.INSIDE,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
assert.equal(newJson.rootKey, "wp:positionV");
|
expect(tree).to.deep.equal({
|
||||||
assert.include(newJson.root[0].root, {
|
"wp:positionV": [
|
||||||
relativeFrom: "margin",
|
{
|
||||||
|
_attr: {
|
||||||
|
relativeFrom: "margin",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:align": ["inside"],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(newJson.root[1].rootKey, "wp:align");
|
|
||||||
assert.include(newJson.root[1].root, "inside");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create a element with offset", () => {
|
it("should create a element with offset", () => {
|
||||||
const newJson = Utility.jsonify(
|
const tree = new Formatter().format(
|
||||||
new VerticalPosition({
|
new VerticalPosition({
|
||||||
relative: VerticalPositionRelativeFrom.MARGIN,
|
relative: VerticalPositionRelativeFrom.MARGIN,
|
||||||
offset: 40,
|
offset: 40,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
assert.equal(newJson.rootKey, "wp:positionV");
|
expect(tree).to.deep.equal({
|
||||||
assert.include(newJson.root[0].root, {
|
"wp:positionV": [
|
||||||
relativeFrom: "margin",
|
{
|
||||||
|
_attr: {
|
||||||
|
relativeFrom: "margin",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:posOffset": ["40"],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(newJson.root[1].rootKey, "wp:posOffset");
|
|
||||||
assert.include(newJson.root[1].root[0], 40);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -25,8 +25,8 @@ describe("File", () => {
|
|||||||
|
|
||||||
const tree = new Formatter().format(doc.Document.Body);
|
const tree = new Formatter().format(doc.Document.Body);
|
||||||
|
|
||||||
expect(tree["w:body"][1]["w:sectPr"][4]["w:headerReference"][0]._attr["w:type"]).to.equal("default");
|
expect(tree["w:body"][1]["w:sectPr"][4]["w:headerReference"]._attr["w:type"]).to.equal("default");
|
||||||
expect(tree["w:body"][1]["w:sectPr"][5]["w:footerReference"][0]._attr["w:type"]).to.equal("default");
|
expect(tree["w:body"][1]["w:sectPr"][5]["w:footerReference"]._attr["w:type"]).to.equal("default");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create with first headers and footers", () => {
|
it("should create with first headers and footers", () => {
|
||||||
@ -45,8 +45,8 @@ describe("File", () => {
|
|||||||
|
|
||||||
const tree = new Formatter().format(doc.Document.Body);
|
const tree = new Formatter().format(doc.Document.Body);
|
||||||
|
|
||||||
expect(tree["w:body"][1]["w:sectPr"][4]["w:headerReference"][0]._attr["w:type"]).to.equal("first");
|
expect(tree["w:body"][1]["w:sectPr"][4]["w:headerReference"]._attr["w:type"]).to.equal("first");
|
||||||
expect(tree["w:body"][1]["w:sectPr"][5]["w:footerReference"][0]._attr["w:type"]).to.equal("first");
|
expect(tree["w:body"][1]["w:sectPr"][5]["w:footerReference"]._attr["w:type"]).to.equal("first");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create with correct headers", () => {
|
it("should create with correct headers", () => {
|
||||||
@ -69,13 +69,13 @@ describe("File", () => {
|
|||||||
|
|
||||||
const tree = new Formatter().format(doc.Document.Body);
|
const tree = new Formatter().format(doc.Document.Body);
|
||||||
|
|
||||||
expect(tree["w:body"][1]["w:sectPr"][4]["w:headerReference"][0]._attr["w:type"]).to.equal("default");
|
expect(tree["w:body"][1]["w:sectPr"][4]["w:headerReference"]._attr["w:type"]).to.equal("default");
|
||||||
expect(tree["w:body"][1]["w:sectPr"][5]["w:headerReference"][0]._attr["w:type"]).to.equal("first");
|
expect(tree["w:body"][1]["w:sectPr"][5]["w:headerReference"]._attr["w:type"]).to.equal("first");
|
||||||
expect(tree["w:body"][1]["w:sectPr"][6]["w:headerReference"][0]._attr["w:type"]).to.equal("even");
|
expect(tree["w:body"][1]["w:sectPr"][6]["w:headerReference"]._attr["w:type"]).to.equal("even");
|
||||||
|
|
||||||
expect(tree["w:body"][1]["w:sectPr"][7]["w:footerReference"][0]._attr["w:type"]).to.equal("default");
|
expect(tree["w:body"][1]["w:sectPr"][7]["w:footerReference"]._attr["w:type"]).to.equal("default");
|
||||||
expect(tree["w:body"][1]["w:sectPr"][8]["w:footerReference"][0]._attr["w:type"]).to.equal("first");
|
expect(tree["w:body"][1]["w:sectPr"][8]["w:footerReference"]._attr["w:type"]).to.equal("first");
|
||||||
expect(tree["w:body"][1]["w:sectPr"][9]["w:footerReference"][0]._attr["w:type"]).to.equal("even");
|
expect(tree["w:body"][1]["w:sectPr"][9]["w:footerReference"]._attr["w:type"]).to.equal("even");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -11,8 +11,7 @@ describe("Footnote", () => {
|
|||||||
const tree = new Formatter().format(footnote);
|
const tree = new Formatter().format(footnote);
|
||||||
|
|
||||||
expect(Object.keys(tree)).to.deep.equal(["w:footnote"]);
|
expect(Object.keys(tree)).to.deep.equal(["w:footnote"]);
|
||||||
expect(tree["w:footnote"]).to.be.an.instanceof(Array);
|
expect(tree["w:footnote"]).to.deep.equal({ _attr: { "w:type": "separator", "w:id": 1 } });
|
||||||
expect(tree["w:footnote"][0]).to.deep.equal({ _attr: { "w:type": "separator", "w:id": 1 } });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create a footnote without a footnote type", () => {
|
it("should create a footnote without a footnote type", () => {
|
||||||
@ -20,8 +19,7 @@ describe("Footnote", () => {
|
|||||||
const tree = new Formatter().format(footnote);
|
const tree = new Formatter().format(footnote);
|
||||||
|
|
||||||
expect(Object.keys(tree)).to.deep.equal(["w:footnote"]);
|
expect(Object.keys(tree)).to.deep.equal(["w:footnote"]);
|
||||||
expect(tree["w:footnote"]).to.be.an.instanceof(Array);
|
expect(tree["w:footnote"]).to.deep.equal({ _attr: { "w:id": 1 } });
|
||||||
expect(tree["w:footnote"][0]).to.deep.equal({ _attr: { "w:id": 1 } });
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -9,3 +9,5 @@ export * from "./document";
|
|||||||
export * from "./styles";
|
export * from "./styles";
|
||||||
export * from "./table-of-contents";
|
export * from "./table-of-contents";
|
||||||
export * from "./xml-components";
|
export * from "./xml-components";
|
||||||
|
export * from "./header-wrapper";
|
||||||
|
export * from "./footer-wrapper";
|
||||||
|
@ -27,10 +27,10 @@ describe("Media", () => {
|
|||||||
const file = new File();
|
const file = new File();
|
||||||
const image1 = Media.addImage(file, "test");
|
const image1 = Media.addImage(file, "test");
|
||||||
const tree = new Formatter().format(image1.Paragraph);
|
const tree = new Formatter().format(image1.Paragraph);
|
||||||
const inlineElements = tree["w:p"][1]["w:r"][1]["w:drawing"][0]["wp:inline"];
|
const inlineElements = tree["w:p"][0]["w:r"][0]["w:drawing"][0]["wp:inline"];
|
||||||
const graphicData = inlineElements.find((x) => x["a:graphic"]);
|
const graphicData = inlineElements.find((x) => x["a:graphic"]);
|
||||||
|
|
||||||
expect(graphicData["a:graphic"][1]["a:graphicData"][1]["pic:pic"][2]["pic:blipFill"][0]["a:blip"][0]).to.deep.equal({
|
expect(graphicData["a:graphic"][1]["a:graphicData"][1]["pic:pic"][2]["pic:blipFill"][0]["a:blip"]).to.deep.equal({
|
||||||
_attr: {
|
_attr: {
|
||||||
"r:embed": `rId{testId.png}`,
|
"r:embed": `rId{testId.png}`,
|
||||||
cstate: "none",
|
cstate: "none",
|
||||||
@ -39,10 +39,10 @@ describe("Media", () => {
|
|||||||
|
|
||||||
const image2 = Media.addImage(file, "test");
|
const image2 = Media.addImage(file, "test");
|
||||||
const tree2 = new Formatter().format(image2.Paragraph);
|
const tree2 = new Formatter().format(image2.Paragraph);
|
||||||
const inlineElements2 = tree2["w:p"][1]["w:r"][1]["w:drawing"][0]["wp:inline"];
|
const inlineElements2 = tree2["w:p"][0]["w:r"][0]["w:drawing"][0]["wp:inline"];
|
||||||
const graphicData2 = inlineElements2.find((x) => x["a:graphic"]);
|
const graphicData2 = inlineElements2.find((x) => x["a:graphic"]);
|
||||||
|
|
||||||
expect(graphicData2["a:graphic"][1]["a:graphicData"][1]["pic:pic"][2]["pic:blipFill"][0]["a:blip"][0]).to.deep.equal({
|
expect(graphicData2["a:graphic"][1]["a:graphicData"][1]["pic:pic"][2]["pic:blipFill"][0]["a:blip"]).to.deep.equal({
|
||||||
_attr: {
|
_attr: {
|
||||||
"r:embed": `rId{testId.png}`,
|
"r:embed": `rId{testId.png}`,
|
||||||
cstate: "none",
|
cstate: "none",
|
||||||
|
@ -7,6 +7,8 @@ import { LevelForOverride } from "./level";
|
|||||||
import { Num } from "./num";
|
import { Num } from "./num";
|
||||||
import { Numbering } from "./numbering";
|
import { Numbering } from "./numbering";
|
||||||
|
|
||||||
|
import { EMPTY_OBJECT } from "file/xml-components";
|
||||||
|
|
||||||
describe("Numbering", () => {
|
describe("Numbering", () => {
|
||||||
let numbering: Numbering;
|
let numbering: Numbering;
|
||||||
|
|
||||||
@ -22,7 +24,7 @@ describe("Numbering", () => {
|
|||||||
expect(abstractNums).to.have.lengthOf(1);
|
expect(abstractNums).to.have.lengthOf(1);
|
||||||
expect(abstractNums[0]["w:abstractNum"]).to.deep.include.members([
|
expect(abstractNums[0]["w:abstractNum"]).to.deep.include.members([
|
||||||
{ _attr: { "w:abstractNumId": 0, "w15:restartNumberingAfterBreak": 0 } },
|
{ _attr: { "w:abstractNumId": 0, "w15:restartNumberingAfterBreak": 0 } },
|
||||||
{ "w:multiLevelType": [{ _attr: { "w:val": "hybridMultilevel" } }] },
|
{ "w:multiLevelType": { _attr: { "w:val": "hybridMultilevel" } } },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
abstractNums
|
abstractNums
|
||||||
@ -37,9 +39,9 @@ describe("Numbering", () => {
|
|||||||
{ "w:numFmt": [{ _attr: { "w:val": "bullet" } }] },
|
{ "w:numFmt": [{ _attr: { "w:val": "bullet" } }] },
|
||||||
]);
|
]);
|
||||||
// Once chai 4.0.0 lands and #644 is resolved, we can add the following to the test:
|
// Once chai 4.0.0 lands and #644 is resolved, we can add the following to the test:
|
||||||
// {"w:lvlText": [{"_attr": {"w:val": "•"}}]},
|
// {"w:lvlText": {"_attr": {"w:val": "•"}}},
|
||||||
// {"w:rPr": [{"w:rFonts": [{"_attr": {"w:ascii": "Symbol", "w:cs": "Symbol", "w:eastAsia": "Symbol", "w:hAnsi": "Symbol", "w:hint": "default"}}]}]},
|
// {"w:rPr": [{"w:rFonts": {"_attr": {"w:ascii": "Symbol", "w:cs": "Symbol", "w:eastAsia": "Symbol", "w:hAnsi": "Symbol", "w:hint": "default"}}}]},
|
||||||
// {"w:pPr": [{"_attr": {}},
|
// {"w:pPr": [
|
||||||
// {"w:ind": [{"_attr": {"w:left": 720, "w:hanging": 360}}]}]},
|
// {"w:ind": [{"_attr": {"w:left": 720, "w:hanging": 360}}]}]},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -65,7 +67,7 @@ describe("Numbering", () => {
|
|||||||
expect(n).to.be.instanceof(Num);
|
expect(n).to.be.instanceof(Num);
|
||||||
const tree = new Formatter().format(numbering);
|
const tree = new Formatter().format(numbering);
|
||||||
const serializedN = tree["w:numbering"].find((obj) => obj["w:num"] && obj["w:num"][0]._attr["w:numId"] === n.id);
|
const serializedN = tree["w:numbering"].find((obj) => obj["w:num"] && obj["w:num"][0]._attr["w:numId"] === n.id);
|
||||||
expect(serializedN["w:num"][1]["w:abstractNumId"][0]._attr["w:val"]).to.equal(a2.id);
|
expect(serializedN["w:num"][1]["w:abstractNumId"]._attr["w:val"]).to.equal(a2.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("assigns a unique ID to each concrete numbering it creates", () => {
|
it("assigns a unique ID to each concrete numbering it creates", () => {
|
||||||
@ -89,10 +91,10 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(3, "lowerLetter", "%1)", "end");
|
const level = abstractNumbering.createLevel(3, "lowerLetter", "%1)", "end");
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({ _attr: { "w:ilvl": 3, "w15:tentative": 1 } });
|
expect(tree["w:lvl"]).to.include({ _attr: { "w:ilvl": 3, "w15:tentative": 1 } });
|
||||||
expect(tree["w:lvl"]).to.include({ "w:start": [{ _attr: { "w:val": 1 } }] });
|
expect(tree["w:lvl"]).to.include({ "w:start": { _attr: { "w:val": 1 } } });
|
||||||
expect(tree["w:lvl"]).to.include({ "w:lvlJc": [{ _attr: { "w:val": "end" } }] });
|
expect(tree["w:lvl"]).to.include({ "w:lvlJc": { _attr: { "w:val": "end" } } });
|
||||||
expect(tree["w:lvl"]).to.include({ "w:numFmt": [{ _attr: { "w:val": "lowerLetter" } }] });
|
expect(tree["w:lvl"]).to.include({ "w:numFmt": { _attr: { "w:val": "lowerLetter" } } });
|
||||||
expect(tree["w:lvl"]).to.include({ "w:lvlText": [{ _attr: { "w:val": "%1)" } }] });
|
expect(tree["w:lvl"]).to.include({ "w:lvlText": { _attr: { "w:val": "%1)" } } });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses 'start' as the default alignment", () => {
|
it("uses 'start' as the default alignment", () => {
|
||||||
@ -100,10 +102,10 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(3, "lowerLetter", "%1)");
|
const level = abstractNumbering.createLevel(3, "lowerLetter", "%1)");
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({ _attr: { "w:ilvl": 3, "w15:tentative": 1 } });
|
expect(tree["w:lvl"]).to.include({ _attr: { "w:ilvl": 3, "w15:tentative": 1 } });
|
||||||
expect(tree["w:lvl"]).to.include({ "w:start": [{ _attr: { "w:val": 1 } }] });
|
expect(tree["w:lvl"]).to.include({ "w:start": { _attr: { "w:val": 1 } } });
|
||||||
expect(tree["w:lvl"]).to.include({ "w:lvlJc": [{ _attr: { "w:val": "start" } }] });
|
expect(tree["w:lvl"]).to.include({ "w:lvlJc": { _attr: { "w:val": "start" } } });
|
||||||
expect(tree["w:lvl"]).to.include({ "w:numFmt": [{ _attr: { "w:val": "lowerLetter" } }] });
|
expect(tree["w:lvl"]).to.include({ "w:numFmt": { _attr: { "w:val": "lowerLetter" } } });
|
||||||
expect(tree["w:lvl"]).to.include({ "w:lvlText": [{ _attr: { "w:val": "%1)" } }] });
|
expect(tree["w:lvl"]).to.include({ "w:lvlText": { _attr: { "w:val": "%1)" } } });
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("formatting methods: paragraph properties", () => {
|
describe("formatting methods: paragraph properties", () => {
|
||||||
@ -112,7 +114,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerLetter", "%0.").indent({ left: 720 });
|
const level = abstractNumbering.createLevel(0, "lowerLetter", "%0.").indent({ left: 720 });
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:pPr": [{ "w:ind": [{ _attr: { "w:left": 720 } }] }],
|
"w:pPr": [{ "w:ind": { _attr: { "w:left": 720 } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -121,7 +123,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerLetter", "%0.").spacing({ before: 50, after: 150 });
|
const level = abstractNumbering.createLevel(0, "lowerLetter", "%0.").spacing({ before: 50, after: 150 });
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:pPr": [{ "w:spacing": [{ _attr: { "w:before": 50, "w:after": 150 } }] }],
|
"w:pPr": [{ "w:spacing": { _attr: { "w:before": 50, "w:after": 150 } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -130,7 +132,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerLetter", "%0.").center();
|
const level = abstractNumbering.createLevel(0, "lowerLetter", "%0.").center();
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "center" } }] }],
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "center" } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -139,7 +141,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.", "left").left();
|
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.", "left").left();
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "left" } }] }],
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "left" } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -148,7 +150,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").right();
|
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").right();
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "right" } }] }],
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "right" } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -157,7 +159,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").justified();
|
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").justified();
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "both" } }] }],
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "both" } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -170,16 +172,14 @@ describe("AbstractNumbering", () => {
|
|||||||
{
|
{
|
||||||
"w:pBdr": [
|
"w:pBdr": [
|
||||||
{
|
{
|
||||||
"w:bottom": [
|
"w:bottom": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:color": "auto",
|
||||||
"w:color": "auto",
|
"w:space": "1",
|
||||||
"w:space": "1",
|
"w:val": "single",
|
||||||
"w:val": "single",
|
"w:sz": "6",
|
||||||
"w:sz": "6",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -194,7 +194,7 @@ describe("AbstractNumbering", () => {
|
|||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:pPr": [
|
"w:pPr": [
|
||||||
{
|
{
|
||||||
"w:tabs": [{ "w:tab": [{ _attr: { "w:val": "left", "w:pos": 1200 } }] }],
|
"w:tabs": [{ "w:tab": { _attr: { "w:val": "left", "w:pos": 1200 } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -207,7 +207,7 @@ describe("AbstractNumbering", () => {
|
|||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:pPr": [
|
"w:pPr": [
|
||||||
{
|
{
|
||||||
"w:tabs": [{ "w:tab": [{ _attr: { "w:val": "right", "w:pos": 9026 } }] }],
|
"w:tabs": [{ "w:tab": { _attr: { "w:val": "right", "w:pos": 9026 } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -218,7 +218,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").keepLines();
|
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").keepLines();
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:pPr": [{ "w:keepLines": [] }],
|
"w:pPr": [{ "w:keepLines": EMPTY_OBJECT }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -227,7 +227,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").keepNext();
|
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").keepNext();
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:pPr": [{ "w:keepNext": [] }],
|
"w:pPr": [{ "w:keepNext": EMPTY_OBJECT }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -238,7 +238,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").size(24);
|
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").size(24);
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:rPr": [{ "w:sz": [{ _attr: { "w:val": 24 } }] }],
|
"w:rPr": [{ "w:sz": { _attr: { "w:val": 24 } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -247,7 +247,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").smallCaps();
|
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").smallCaps();
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:rPr": [{ "w:smallCaps": [{ _attr: { "w:val": true } }] }],
|
"w:rPr": [{ "w:smallCaps": { _attr: { "w:val": true } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -256,7 +256,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").allCaps();
|
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").allCaps();
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:rPr": [{ "w:caps": [{ _attr: { "w:val": true } }] }],
|
"w:rPr": [{ "w:caps": { _attr: { "w:val": true } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -265,7 +265,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").strike();
|
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").strike();
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:rPr": [{ "w:strike": [{ _attr: { "w:val": true } }] }],
|
"w:rPr": [{ "w:strike": { _attr: { "w:val": true } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -274,7 +274,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").doubleStrike();
|
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").doubleStrike();
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:rPr": [{ "w:dstrike": [{ _attr: { "w:val": true } }] }],
|
"w:rPr": [{ "w:dstrike": { _attr: { "w:val": true } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -283,7 +283,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").subScript();
|
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").subScript();
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:rPr": [{ "w:vertAlign": [{ _attr: { "w:val": "subscript" } }] }],
|
"w:rPr": [{ "w:vertAlign": { _attr: { "w:val": "subscript" } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -292,7 +292,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").superScript();
|
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").superScript();
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:rPr": [{ "w:vertAlign": [{ _attr: { "w:val": "superscript" } }] }],
|
"w:rPr": [{ "w:vertAlign": { _attr: { "w:val": "superscript" } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -302,7 +302,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:rPr": [
|
"w:rPr": [
|
||||||
{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }] },
|
{ "w:rFonts": { _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } } },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -312,7 +312,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").bold();
|
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").bold();
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:rPr": [{ "w:b": [{ _attr: { "w:val": true } }] }],
|
"w:rPr": [{ "w:b": { _attr: { "w:val": true } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -321,7 +321,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").italics();
|
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").italics();
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:rPr": [{ "w:i": [{ _attr: { "w:val": true } }] }],
|
"w:rPr": [{ "w:i": { _attr: { "w:val": true } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -331,7 +331,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").underline();
|
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").underline();
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:rPr": [{ "w:u": [{ _attr: { "w:val": "single" } }] }],
|
"w:rPr": [{ "w:u": { _attr: { "w:val": "single" } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -340,7 +340,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").underline("double");
|
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").underline("double");
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:rPr": [{ "w:u": [{ _attr: { "w:val": "double" } }] }],
|
"w:rPr": [{ "w:u": { _attr: { "w:val": "double" } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -349,7 +349,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").underline("double", "005599");
|
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").underline("double", "005599");
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:rPr": [{ "w:u": [{ _attr: { "w:val": "double", "w:color": "005599" } }] }],
|
"w:rPr": [{ "w:u": { _attr: { "w:val": "double", "w:color": "005599" } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -359,7 +359,7 @@ describe("AbstractNumbering", () => {
|
|||||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").color("123456");
|
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").color("123456");
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:rPr": [{ "w:color": [{ _attr: { "w:val": "123456" } }] }],
|
"w:rPr": [{ "w:color": { _attr: { "w:val": "123456" } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -388,20 +388,12 @@ describe("concrete numbering", () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:lvl": [
|
"w:lvl": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:ilvl": 3,
|
||||||
"w:ilvl": 3,
|
"w15:tentative": 1,
|
||||||
"w15:tentative": 1,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
},
|
||||||
"w:pPr": [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"w:rPr": [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -418,29 +410,19 @@ describe("concrete numbering", () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:startOverride": [
|
"w:startOverride": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": 9,
|
||||||
"w:val": 9,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:lvl": [
|
"w:lvl": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:ilvl": 1,
|
||||||
"w:ilvl": 1,
|
"w15:tentative": 1,
|
||||||
"w15:tentative": 1,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
},
|
||||||
"w:pPr": [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"w:rPr": [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -454,7 +436,7 @@ describe("concrete numbering", () => {
|
|||||||
"w:lvlOverride": [
|
"w:lvlOverride": [
|
||||||
{ _attr: { "w:ilvl": 1 } },
|
{ _attr: { "w:ilvl": 1 } },
|
||||||
{
|
{
|
||||||
"w:lvl": [{ _attr: { "w15:tentative": 1, "w:ilvl": 1 } }, { "w:pPr": [] }, { "w:rPr": [] }],
|
"w:lvl": { _attr: { "w15:tentative": 1, "w:ilvl": 1 } },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { assert } from "chai";
|
import { assert, expect } from "chai";
|
||||||
|
|
||||||
import { Utility } from "tests/utility";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { ThematicBreak } from "./border";
|
import { ThematicBreak } from "./border";
|
||||||
|
|
||||||
@ -28,14 +28,21 @@ describe("ThematicBreak", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should create a Thematic Break with correct border properties", () => {
|
it("should create a Thematic Break with correct border properties", () => {
|
||||||
const newJson = Utility.jsonify(thematicBreak);
|
const tree = new Formatter().format(thematicBreak);
|
||||||
const attributes = {
|
expect(tree).to.deep.equal({
|
||||||
color: "auto",
|
"w:pBdr": [
|
||||||
space: "1",
|
{
|
||||||
val: "single",
|
"w:bottom": {
|
||||||
sz: "6",
|
_attr: {
|
||||||
};
|
"w:color": "auto",
|
||||||
assert.equal(JSON.stringify(newJson.root[0].root[0].root), JSON.stringify(attributes));
|
"w:space": "1",
|
||||||
|
"w:sz": "6",
|
||||||
|
"w:val": "single",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { assert } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Utility } from "tests/utility";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { PageBreak, PageBreakBefore } from "./page-break";
|
import { PageBreak, PageBreakBefore } from "./page-break";
|
||||||
|
|
||||||
@ -13,21 +13,18 @@ describe("PageBreak", () => {
|
|||||||
|
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a Page Break with correct attributes", () => {
|
it("should create a Page Break with correct attributes", () => {
|
||||||
const newJson = Utility.jsonify(pageBreak);
|
const tree = new Formatter().format(pageBreak);
|
||||||
const attributes = {
|
expect(tree).to.deep.equal({
|
||||||
type: "page",
|
"w:r": [
|
||||||
};
|
{
|
||||||
assert.equal(JSON.stringify(newJson.root[1].root[0].root), JSON.stringify(attributes));
|
"w:br": {
|
||||||
});
|
_attr: {
|
||||||
|
"w:type": "page",
|
||||||
it("should create a Page Break with w:r", () => {
|
},
|
||||||
const newJson = Utility.jsonify(pageBreak);
|
},
|
||||||
assert.equal(newJson.rootKey, "w:r");
|
},
|
||||||
});
|
],
|
||||||
|
});
|
||||||
it("should create a Page Break with a Break inside", () => {
|
|
||||||
const newJson = Utility.jsonify(pageBreak);
|
|
||||||
assert.equal(newJson.root[1].rootKey, "w:br");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -35,7 +32,9 @@ describe("PageBreak", () => {
|
|||||||
describe("PageBreakBefore", () => {
|
describe("PageBreakBefore", () => {
|
||||||
it("should create page break before", () => {
|
it("should create page break before", () => {
|
||||||
const pageBreakBefore = new PageBreakBefore();
|
const pageBreakBefore = new PageBreakBefore();
|
||||||
const newJson = Utility.jsonify(pageBreakBefore);
|
const tree = new Formatter().format(pageBreakBefore);
|
||||||
assert.equal(newJson.rootKey, "w:pageBreakBefore");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:pageBreakBefore": {},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -10,7 +10,7 @@ describe("Spacing", () => {
|
|||||||
const spacing = new Spacing({ before: 100, after: 120, line: 150 });
|
const spacing = new Spacing({ before: 100, after: 120, line: 150 });
|
||||||
const tree = new Formatter().format(spacing);
|
const tree = new Formatter().format(spacing);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:spacing": [{ _attr: { "w:after": 120, "w:before": 100, "w:line": 150 } }],
|
"w:spacing": { _attr: { "w:after": 120, "w:before": 100, "w:line": 150 } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ describe("Spacing", () => {
|
|||||||
const spacing = new Spacing({ before: 100 });
|
const spacing = new Spacing({ before: 100 });
|
||||||
const tree = new Formatter().format(spacing);
|
const tree = new Formatter().format(spacing);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:spacing": [{ _attr: { "w:before": 100 } }],
|
"w:spacing": { _attr: { "w:before": 100 } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -30,7 +30,7 @@ describe("ContextualSpacing", () => {
|
|||||||
const spacing = new ContextualSpacing(true);
|
const spacing = new ContextualSpacing(true);
|
||||||
const tree = new Formatter().format(spacing);
|
const tree = new Formatter().format(spacing);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:contextualSpacing": [{ _attr: { "w:val": 1 } }],
|
"w:contextualSpacing": { _attr: { "w:val": 1 } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ describe("ContextualSpacing", () => {
|
|||||||
const spacing = new ContextualSpacing(false);
|
const spacing = new ContextualSpacing(false);
|
||||||
const tree = new Formatter().format(spacing);
|
const tree = new Formatter().format(spacing);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:contextualSpacing": [{ _attr: { "w:val": 0 } }],
|
"w:contextualSpacing": { _attr: { "w:val": 0 } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { assert } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Utility } from "tests/utility";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { Style } from "./style";
|
import { Style } from "./style";
|
||||||
|
|
||||||
@ -10,14 +10,26 @@ describe("ParagraphStyle", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a style with given value", () => {
|
it("should create a style with given value", () => {
|
||||||
style = new Style("test");
|
style = new Style("test");
|
||||||
const newJson = Utility.jsonify(style);
|
const tree = new Formatter().format(style);
|
||||||
assert.equal(newJson.root[0].root.val, "test");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:pStyle": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create a style with blank val", () => {
|
it("should create a style with blank val", () => {
|
||||||
style = new Style("");
|
style = new Style("");
|
||||||
const newJson = Utility.jsonify(style);
|
const tree = new Formatter().format(style);
|
||||||
assert.equal(newJson.root[0].root.val, "");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:pStyle": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { assert } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Utility } from "tests/utility";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { NumberProperties } from "./unordered-list";
|
import { NumberProperties } from "./unordered-list";
|
||||||
|
|
||||||
@ -13,20 +13,25 @@ describe("NumberProperties", () => {
|
|||||||
|
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a Number Properties with correct root key", () => {
|
it("should create a Number Properties with correct root key", () => {
|
||||||
const newJson = Utility.jsonify(numberProperties);
|
const tree = new Formatter().format(numberProperties);
|
||||||
assert.equal(newJson.rootKey, "w:numPr");
|
expect(tree).to.deep.equal({
|
||||||
});
|
"w:numPr": [
|
||||||
|
{
|
||||||
it("should create a Page Break with a Indent Level inside", () => {
|
"w:ilvl": {
|
||||||
const newJson = Utility.jsonify(numberProperties);
|
_attr: {
|
||||||
assert.equal(newJson.root[0].rootKey, "w:ilvl");
|
"w:val": 10,
|
||||||
assert.equal(newJson.root[0].root[0].root.val, 10);
|
},
|
||||||
});
|
},
|
||||||
|
},
|
||||||
it("should create a Page Break with a Number Id inside", () => {
|
{
|
||||||
const newJson = Utility.jsonify(numberProperties);
|
"w:numId": {
|
||||||
assert.equal(newJson.root[1].rootKey, "w:numId");
|
_attr: {
|
||||||
assert.equal(newJson.root[1].root[0].root.val, 5);
|
"w:val": 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -5,6 +5,8 @@ import { Formatter } from "export/formatter";
|
|||||||
|
|
||||||
import { ImageParagraph } from "./image";
|
import { ImageParagraph } from "./image";
|
||||||
|
|
||||||
|
import { EMPTY_OBJECT } from "file/xml-components";
|
||||||
|
|
||||||
describe("Image", () => {
|
describe("Image", () => {
|
||||||
let image: ImageParagraph;
|
let image: ImageParagraph;
|
||||||
|
|
||||||
@ -45,14 +47,8 @@ describe("Image", () => {
|
|||||||
const tree = new Formatter().format(image);
|
const tree = new Formatter().format(image);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
|
||||||
"w:pPr": [],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"w:r": [
|
"w:r": [
|
||||||
{
|
|
||||||
"w:rPr": [],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"w:drawing": [
|
"w:drawing": [
|
||||||
{
|
{
|
||||||
@ -66,49 +62,41 @@ describe("Image", () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"wp:extent": [
|
"wp:extent": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
cx: 20,
|
||||||
cx: 20,
|
cy: 20,
|
||||||
cy: 20,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"wp:effectExtent": [
|
"wp:effectExtent": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
b: 0,
|
||||||
b: 0,
|
l: 0,
|
||||||
l: 0,
|
r: 0,
|
||||||
r: 0,
|
t: 0,
|
||||||
t: 0,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"wp:docPr": [
|
"wp:docPr": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
descr: "",
|
||||||
descr: "",
|
id: 0,
|
||||||
id: 0,
|
name: "",
|
||||||
name: "",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"wp:cNvGraphicFramePr": [
|
"wp:cNvGraphicFramePr": [
|
||||||
{
|
{
|
||||||
"a:graphicFrameLocks": [
|
"a:graphicFrameLocks": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
noChangeAspect: 1,
|
||||||
noChangeAspect: 1,
|
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||||
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -137,27 +125,23 @@ describe("Image", () => {
|
|||||||
{
|
{
|
||||||
"pic:nvPicPr": [
|
"pic:nvPicPr": [
|
||||||
{
|
{
|
||||||
"pic:cNvPr": [
|
"pic:cNvPr": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
desc: "",
|
||||||
desc: "",
|
id: 0,
|
||||||
id: 0,
|
name: "",
|
||||||
name: "",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"pic:cNvPicPr": [
|
"pic:cNvPicPr": [
|
||||||
{
|
{
|
||||||
"a:picLocks": [
|
"a:picLocks": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
noChangeArrowheads: 1,
|
||||||
noChangeArrowheads: 1,
|
noChangeAspect: 1,
|
||||||
noChangeAspect: 1,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -166,22 +150,20 @@ describe("Image", () => {
|
|||||||
{
|
{
|
||||||
"pic:blipFill": [
|
"pic:blipFill": [
|
||||||
{
|
{
|
||||||
"a:blip": [
|
"a:blip": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
cstate: "none",
|
||||||
cstate: "none",
|
"r:embed": "rId{test.png}",
|
||||||
"r:embed": "rId{test.png}",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"a:srcRect": [],
|
"a:srcRect": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"a:stretch": [
|
"a:stretch": [
|
||||||
{
|
{
|
||||||
"a:fillRect": [],
|
"a:fillRect": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -197,24 +179,20 @@ describe("Image", () => {
|
|||||||
{
|
{
|
||||||
"a:xfrm": [
|
"a:xfrm": [
|
||||||
{
|
{
|
||||||
"a:ext": [
|
"a:ext": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
cx: 10,
|
||||||
cx: 10,
|
cy: 10,
|
||||||
cy: 10,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"a:off": [
|
"a:off": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
x: 0,
|
||||||
x: 0,
|
y: 0,
|
||||||
y: 0,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -226,7 +204,7 @@ describe("Image", () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"a:avLst": [],
|
"a:avLst": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { assert, expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
import { Utility } from "tests/utility";
|
|
||||||
|
|
||||||
import { Hyperlink } from "./";
|
import { Hyperlink } from "./";
|
||||||
|
|
||||||
@ -14,28 +13,23 @@ describe("Hyperlink", () => {
|
|||||||
|
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a hyperlink with correct root key", () => {
|
it("should create a hyperlink with correct root key", () => {
|
||||||
const newJson = Utility.jsonify(hyperlink);
|
|
||||||
assert.equal(newJson.rootKey, "w:hyperlink");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should create a hyperlink with right attributes", () => {
|
|
||||||
const newJson = Utility.jsonify(hyperlink);
|
|
||||||
const attributes = {
|
|
||||||
history: 1,
|
|
||||||
id: "rId1",
|
|
||||||
};
|
|
||||||
assert.equal(JSON.stringify(newJson.root[0].root), JSON.stringify(attributes));
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should create a hyperlink with a run component", () => {
|
|
||||||
const tree = new Formatter().format(hyperlink);
|
const tree = new Formatter().format(hyperlink);
|
||||||
const runJson = {
|
expect(tree).to.deep.equal({
|
||||||
"w:r": [
|
"w:hyperlink": [
|
||||||
{ "w:rPr": [{ "w:rStyle": [{ _attr: { "w:val": "Hyperlink" } }] }] },
|
{
|
||||||
{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "https://example.com"] },
|
_attr: {
|
||||||
|
"w:history": 1,
|
||||||
|
"r:id": "rId1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:r": [
|
||||||
|
{ "w:rPr": [{ "w:rStyle": { _attr: { "w:val": "Hyperlink" } } }] },
|
||||||
|
{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "https://example.com"] },
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
});
|
||||||
expect(tree["w:hyperlink"][1]).to.deep.equal(runJson);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("with optional anchor parameter", () => {
|
describe("with optional anchor parameter", () => {
|
||||||
@ -44,12 +38,23 @@ describe("Hyperlink", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should create an internal link with anchor tag", () => {
|
it("should create an internal link with anchor tag", () => {
|
||||||
const newJson = Utility.jsonify(hyperlink);
|
const tree = new Formatter().format(hyperlink);
|
||||||
const attributes = {
|
expect(tree).to.deep.equal({
|
||||||
history: 1,
|
"w:hyperlink": [
|
||||||
anchor: "anchor",
|
{
|
||||||
};
|
_attr: {
|
||||||
assert.equal(JSON.stringify(newJson.root[0].root), JSON.stringify(attributes));
|
"w:history": 1,
|
||||||
|
"w:anchor": "anchor",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:r": [
|
||||||
|
{ "w:rPr": [{ "w:rStyle": { _attr: { "w:val": "Hyperlink" } } }] },
|
||||||
|
{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "Anchor Text"] },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { assert } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Utility } from "tests/utility";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { OutlineLevel } from "./outline-level";
|
import { OutlineLevel } from "./outline-level";
|
||||||
|
|
||||||
@ -10,14 +10,14 @@ describe("ParagraphOutlineLevel", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create an outlineLevel with given value", () => {
|
it("should create an outlineLevel with given value", () => {
|
||||||
outlineLevel = new OutlineLevel("0");
|
outlineLevel = new OutlineLevel("0");
|
||||||
const newJson = Utility.jsonify(outlineLevel);
|
const tree = new Formatter().format(outlineLevel);
|
||||||
assert.equal(newJson.root[0].root.val, "0");
|
expect(tree).to.deep.equal({
|
||||||
});
|
"w:outlineLvl": {
|
||||||
|
_attr: {
|
||||||
it("should create an outlineLevel with blank val", () => {
|
"w:val": "0",
|
||||||
outlineLevel = new OutlineLevel("");
|
},
|
||||||
const newJson = Utility.jsonify(outlineLevel);
|
},
|
||||||
assert.equal(newJson.root[0].root.val, "");
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -6,6 +6,8 @@ import * as file from "file";
|
|||||||
import { Numbering } from "../numbering";
|
import { Numbering } from "../numbering";
|
||||||
import { LeaderType } from "./formatting";
|
import { LeaderType } from "./formatting";
|
||||||
|
|
||||||
|
import { EMPTY_OBJECT } from "file/xml-components";
|
||||||
|
|
||||||
describe("Paragraph", () => {
|
describe("Paragraph", () => {
|
||||||
let paragraph: file.Paragraph;
|
let paragraph: file.Paragraph;
|
||||||
|
|
||||||
@ -40,7 +42,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree)
|
expect(tree)
|
||||||
.to.be.an("array")
|
.to.be.an("array")
|
||||||
.which.includes({
|
.which.includes({
|
||||||
"w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "this is a test run"] }],
|
"w:r": [{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "this is a test run"] }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -52,7 +54,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading1" } }] }],
|
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Heading1" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -66,7 +68,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading2" } }] }],
|
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Heading2" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -80,7 +82,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading3" } }] }],
|
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Heading3" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -94,7 +96,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading4" } }] }],
|
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Heading4" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -108,7 +110,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading5" } }] }],
|
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Heading5" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -122,7 +124,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading6" } }] }],
|
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Heading6" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -136,7 +138,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Title" } }] }],
|
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Title" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -150,7 +152,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "center" } }] }],
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "center" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -164,7 +166,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "left" } }] }],
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "left" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -178,7 +180,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "right" } }] }],
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "right" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -192,7 +194,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "start" } }] }],
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "start" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -206,7 +208,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "end" } }] }],
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "end" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -220,7 +222,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "distribute" } }] }],
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "distribute" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -234,7 +236,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "both" } }] }],
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "both" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -252,14 +254,12 @@ describe("Paragraph", () => {
|
|||||||
{
|
{
|
||||||
"w:tabs": [
|
"w:tabs": [
|
||||||
{
|
{
|
||||||
"w:tab": [
|
"w:tab": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:pos": 9026,
|
||||||
"w:pos": 9026,
|
"w:val": "right",
|
||||||
"w:val": "right",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -281,15 +281,13 @@ describe("Paragraph", () => {
|
|||||||
{
|
{
|
||||||
"w:tabs": [
|
"w:tabs": [
|
||||||
{
|
{
|
||||||
"w:tab": [
|
"w:tab": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:pos": 100,
|
||||||
"w:pos": 100,
|
"w:val": "left",
|
||||||
"w:val": "left",
|
"w:leader": "hyphen",
|
||||||
"w:leader": "hyphen",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -311,15 +309,13 @@ describe("Paragraph", () => {
|
|||||||
{
|
{
|
||||||
"w:tabs": [
|
"w:tabs": [
|
||||||
{
|
{
|
||||||
"w:tab": [
|
"w:tab": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:pos": 100,
|
||||||
"w:pos": 100,
|
"w:val": "right",
|
||||||
"w:val": "right",
|
"w:leader": "dot",
|
||||||
"w:leader": "dot",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -341,15 +337,13 @@ describe("Paragraph", () => {
|
|||||||
{
|
{
|
||||||
"w:tabs": [
|
"w:tabs": [
|
||||||
{
|
{
|
||||||
"w:tab": [
|
"w:tab": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:pos": 100,
|
||||||
"w:pos": 100,
|
"w:val": "center",
|
||||||
"w:val": "center",
|
"w:leader": "middleDot",
|
||||||
"w:leader": "middleDot",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -367,7 +361,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:contextualSpacing": [{ _attr: { "w:val": 1 } }] }],
|
"w:pPr": [{ "w:contextualSpacing": { _attr: { "w:val": 1 } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -379,7 +373,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:contextualSpacing": [{ _attr: { "w:val": 0 } }] }],
|
"w:pPr": [{ "w:contextualSpacing": { _attr: { "w:val": 0 } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -397,16 +391,14 @@ describe("Paragraph", () => {
|
|||||||
{
|
{
|
||||||
"w:pBdr": [
|
"w:pBdr": [
|
||||||
{
|
{
|
||||||
"w:bottom": [
|
"w:bottom": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "single",
|
||||||
"w:val": "single",
|
"w:color": "auto",
|
||||||
"w:color": "auto",
|
"w:space": "1",
|
||||||
"w:space": "1",
|
"w:sz": "6",
|
||||||
"w:sz": "6",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -430,28 +422,24 @@ describe("Paragraph", () => {
|
|||||||
{
|
{
|
||||||
"w:pBdr": [
|
"w:pBdr": [
|
||||||
{
|
{
|
||||||
"w:left": [
|
"w:left": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:color": "auto",
|
||||||
"w:color": "auto",
|
"w:space": "1",
|
||||||
"w:space": "1",
|
"w:sz": "6",
|
||||||
"w:sz": "6",
|
"w:val": "single",
|
||||||
"w:val": "single",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:right": [
|
"w:right": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:color": "auto",
|
||||||
"w:color": "auto",
|
"w:space": "1",
|
||||||
"w:space": "1",
|
"w:sz": "6",
|
||||||
"w:sz": "6",
|
"w:val": "single",
|
||||||
"w:val": "single",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -469,10 +457,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [],
|
"w:r": [{ "w:br": { _attr: { "w:type": "page" } } }],
|
||||||
},
|
|
||||||
{
|
|
||||||
"w:r": [{ "w:rPr": [] }, { "w:br": [{ _attr: { "w:type": "page" } }] }],
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -488,7 +473,7 @@ describe("Paragraph", () => {
|
|||||||
{
|
{
|
||||||
"w:pPr": [
|
"w:pPr": [
|
||||||
{
|
{
|
||||||
"w:pageBreakBefore": [],
|
"w:pageBreakBefore": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -510,7 +495,7 @@ describe("Paragraph", () => {
|
|||||||
.which.is.an("array")
|
.which.is.an("array")
|
||||||
.which.has.length.at.least(1);
|
.which.has.length.at.least(1);
|
||||||
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({
|
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({
|
||||||
"w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }],
|
"w:pStyle": { _attr: { "w:val": "ListParagraph" } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -526,7 +511,7 @@ describe("Paragraph", () => {
|
|||||||
.which.is.an("array")
|
.which.is.an("array")
|
||||||
.which.has.length.at.least(1);
|
.which.has.length.at.least(1);
|
||||||
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({
|
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({
|
||||||
"w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }],
|
"w:pStyle": { _attr: { "w:val": "ListParagraph" } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -542,7 +527,7 @@ describe("Paragraph", () => {
|
|||||||
.which.is.an("array")
|
.which.is.an("array")
|
||||||
.which.has.length.at.least(2);
|
.which.has.length.at.least(2);
|
||||||
expect(tree["w:p"][0]["w:pPr"][1]).to.deep.equal({
|
expect(tree["w:p"][0]["w:pPr"][1]).to.deep.equal({
|
||||||
"w:numPr": [{ "w:ilvl": [{ _attr: { "w:val": 1 } }] }, { "w:numId": [{ _attr: { "w:val": 1 } }] }],
|
"w:numPr": [{ "w:ilvl": { _attr: { "w:val": 1 } } }, { "w:numId": { _attr: { "w:val": 1 } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -565,7 +550,7 @@ describe("Paragraph", () => {
|
|||||||
.which.is.an("array")
|
.which.is.an("array")
|
||||||
.which.has.length.at.least(1);
|
.which.has.length.at.least(1);
|
||||||
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({
|
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({
|
||||||
"w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }],
|
"w:pStyle": { _attr: { "w:val": "ListParagraph" } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -581,11 +566,11 @@ describe("Paragraph", () => {
|
|||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [
|
"w:pPr": [
|
||||||
{ "w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }] },
|
{ "w:pStyle": { _attr: { "w:val": "ListParagraph" } } },
|
||||||
{
|
{
|
||||||
"w:numPr": [
|
"w:numPr": [
|
||||||
{ "w:ilvl": [{ _attr: { "w:val": 0 } }] },
|
{ "w:ilvl": { _attr: { "w:val": 0 } } },
|
||||||
{ "w:numId": [{ _attr: { "w:val": letterNumbering.id } }] },
|
{ "w:numId": { _attr: { "w:val": letterNumbering.id } } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -602,7 +587,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "myFancyStyle" } }] }],
|
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "myFancyStyle" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -616,7 +601,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:ind": [{ _attr: { "w:left": 720 } }] }],
|
"w:pPr": [{ "w:ind": { _attr: { "w:left": 720 } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -630,7 +615,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:spacing": [{ _attr: { "w:before": 90, "w:line": 50 } }] }],
|
"w:pPr": [{ "w:spacing": { _attr: { "w:before": 90, "w:line": 50 } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -642,7 +627,7 @@ describe("Paragraph", () => {
|
|||||||
paragraph.keepLines();
|
paragraph.keepLines();
|
||||||
const tree = new Formatter().format(paragraph);
|
const tree = new Formatter().format(paragraph);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [{ "w:pPr": [{ "w:keepLines": [] }] }],
|
"w:p": [{ "w:pPr": [{ "w:keepLines": EMPTY_OBJECT }] }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -652,7 +637,7 @@ describe("Paragraph", () => {
|
|||||||
paragraph.keepNext();
|
paragraph.keepNext();
|
||||||
const tree = new Formatter().format(paragraph);
|
const tree = new Formatter().format(paragraph);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [{ "w:pPr": [{ "w:keepNext": [] }] }],
|
"w:p": [{ "w:pPr": [{ "w:keepNext": EMPTY_OBJECT }] }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -662,7 +647,7 @@ describe("Paragraph", () => {
|
|||||||
paragraph.bidirectional();
|
paragraph.bidirectional();
|
||||||
const tree = new Formatter().format(paragraph);
|
const tree = new Formatter().format(paragraph);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [{ "w:pPr": [{ "w:bidi": [] }] }],
|
"w:p": [{ "w:pPr": [{ "w:bidi": EMPTY_OBJECT }] }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -674,7 +659,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:outlineLvl": [{ _attr: { "w:val": "0" } }] }],
|
"w:pPr": [{ "w:outlineLvl": { _attr: { "w:val": "0" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
// http://officeopenxml.com/WPparagraphProperties.php
|
// http://officeopenxml.com/WPparagraphProperties.php
|
||||||
import { XmlComponent } from "file/xml-components";
|
import { IgnoreIfEmptyXmlComponent, XmlComponent } from "file/xml-components";
|
||||||
import { Border } from "./formatting/border";
|
import { Border } from "./formatting/border";
|
||||||
|
|
||||||
export class ParagraphProperties extends XmlComponent {
|
export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
||||||
public readonly paragraphBorder: Border;
|
public readonly paragraphBorder: Border;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { assert } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Utility } from "tests/utility";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { Break } from "./break";
|
import { Break } from "./break";
|
||||||
|
|
||||||
@ -13,8 +13,10 @@ describe("Break", () => {
|
|||||||
|
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a Break with correct root key", () => {
|
it("should create a Break with correct root key", () => {
|
||||||
const newJson = Utility.jsonify(currentBreak);
|
const tree = new Formatter().format(currentBreak);
|
||||||
assert.equal(newJson.rootKey, "w:br");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:br": {},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { XmlComponent } from "file/xml-components";
|
import { IgnoreIfEmptyXmlComponent, XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
export class RunProperties extends XmlComponent {
|
export class RunProperties extends IgnoreIfEmptyXmlComponent {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("w:rPr");
|
super("w:rPr");
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ describe("Text", () => {
|
|||||||
it("creates an empty text run if no text is given", () => {
|
it("creates an empty text run if no text is given", () => {
|
||||||
const t = new Text("");
|
const t = new Text("");
|
||||||
const f = new Formatter().format(t);
|
const f = new Formatter().format(t);
|
||||||
expect(f).to.deep.equal({ "w:t": [{ _attr: { "xml:space": "preserve" } }] });
|
expect(f).to.deep.equal({ "w:t": { _attr: { "xml:space": "preserve" } } });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("adds the passed in text to the component", () => {
|
it("adds the passed in text to the component", () => {
|
||||||
|
@ -9,16 +9,16 @@ describe("RunFonts", () => {
|
|||||||
it("uses the font name for both ascii and hAnsi", () => {
|
it("uses the font name for both ascii and hAnsi", () => {
|
||||||
const tree = new Formatter().format(new RunFonts("Times"));
|
const tree = new Formatter().format(new RunFonts("Times"));
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }],
|
"w:rFonts": { _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses hint if given", () => {
|
it("uses hint if given", () => {
|
||||||
const tree = new Formatter().format(new RunFonts("Times", "default"));
|
const tree = new Formatter().format(new RunFonts("Times", "default"));
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:rFonts": [
|
"w:rFonts": {
|
||||||
{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times", "w:hint": "default" } },
|
_attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times", "w:hint": "default" },
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { assert, expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
import { Utility } from "tests/utility";
|
|
||||||
|
|
||||||
import { Run } from "./";
|
import { Run } from "./";
|
||||||
|
|
||||||
@ -15,33 +14,55 @@ describe("Run", () => {
|
|||||||
describe("#bold()", () => {
|
describe("#bold()", () => {
|
||||||
it("it should add bold to the properties", () => {
|
it("it should add bold to the properties", () => {
|
||||||
run.bold();
|
run.bold();
|
||||||
const newJson = Utility.jsonify(run);
|
const tree = new Formatter().format(run);
|
||||||
assert.equal(newJson.root[0].root[0].rootKey, "w:b");
|
expect(tree).to.deep.equal({
|
||||||
assert.equal(newJson.root[0].root[1].rootKey, "w:bCs");
|
"w:r": [
|
||||||
|
{
|
||||||
|
"w:rPr": [
|
||||||
|
{ "w:b": { _attr: { "w:val": true } } },
|
||||||
|
{
|
||||||
|
"w:bCs": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#italics()", () => {
|
describe("#italics()", () => {
|
||||||
it("it should add italics to the properties", () => {
|
it("it should add italics to the properties", () => {
|
||||||
run.italics();
|
run.italics();
|
||||||
const newJson = Utility.jsonify(run);
|
const tree = new Formatter().format(run);
|
||||||
assert.equal(newJson.root[0].root[0].rootKey, "w:i");
|
expect(tree).to.deep.equal({
|
||||||
assert.equal(newJson.root[0].root[1].rootKey, "w:iCs");
|
"w:r": [
|
||||||
|
{
|
||||||
|
"w:rPr": [
|
||||||
|
{ "w:i": { _attr: { "w:val": true } } },
|
||||||
|
{
|
||||||
|
"w:iCs": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#underline()", () => {
|
describe("#underline()", () => {
|
||||||
it("it should add underline to the properties", () => {
|
|
||||||
run.underline();
|
|
||||||
const newJson = Utility.jsonify(run);
|
|
||||||
assert.equal(newJson.root[0].root[0].rootKey, "w:u");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should default to 'single' and no color", () => {
|
it("should default to 'single' and no color", () => {
|
||||||
run.underline();
|
run.underline();
|
||||||
const tree = new Formatter().format(run);
|
const tree = new Formatter().format(run);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:r": [{ "w:rPr": [{ "w:u": [{ _attr: { "w:val": "single" } }] }] }],
|
"w:r": [{ "w:rPr": [{ "w:u": { _attr: { "w:val": "single" } } }] }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -49,7 +70,7 @@ describe("Run", () => {
|
|||||||
run.underline("double", "990011");
|
run.underline("double", "990011");
|
||||||
const tree = new Formatter().format(run);
|
const tree = new Formatter().format(run);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:r": [{ "w:rPr": [{ "w:u": [{ _attr: { "w:val": "double", "w:color": "990011" } }] }] }],
|
"w:r": [{ "w:rPr": [{ "w:u": { _attr: { "w:val": "double", "w:color": "990011" } } }] }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -57,48 +78,60 @@ describe("Run", () => {
|
|||||||
describe("#smallCaps()", () => {
|
describe("#smallCaps()", () => {
|
||||||
it("it should add smallCaps to the properties", () => {
|
it("it should add smallCaps to the properties", () => {
|
||||||
run.smallCaps();
|
run.smallCaps();
|
||||||
const newJson = Utility.jsonify(run);
|
const tree = new Formatter().format(run);
|
||||||
assert.equal(newJson.root[0].root[0].rootKey, "w:smallCaps");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [{ "w:rPr": [{ "w:smallCaps": {} }] }],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#caps()", () => {
|
describe("#caps()", () => {
|
||||||
it("it should add caps to the properties", () => {
|
it("it should add caps to the properties", () => {
|
||||||
run.allCaps();
|
run.allCaps();
|
||||||
const newJson = Utility.jsonify(run);
|
const tree = new Formatter().format(run);
|
||||||
assert.equal(newJson.root[0].root[0].rootKey, "w:caps");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [{ "w:rPr": [{ "w:caps": {} }] }],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#strike()", () => {
|
describe("#strike()", () => {
|
||||||
it("it should add strike to the properties", () => {
|
it("it should add strike to the properties", () => {
|
||||||
run.strike();
|
run.strike();
|
||||||
const newJson = Utility.jsonify(run);
|
const tree = new Formatter().format(run);
|
||||||
assert.equal(newJson.root[0].root[0].rootKey, "w:strike");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [{ "w:rPr": [{ "w:strike": { _attr: { "w:val": true } } }] }],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#doubleStrike()", () => {
|
describe("#doubleStrike()", () => {
|
||||||
it("it should add caps to the properties", () => {
|
it("it should add caps to the properties", () => {
|
||||||
run.doubleStrike();
|
run.doubleStrike();
|
||||||
const newJson = Utility.jsonify(run);
|
const tree = new Formatter().format(run);
|
||||||
assert.equal(newJson.root[0].root[0].rootKey, "w:dstrike");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [{ "w:rPr": [{ "w:dstrike": { _attr: { "w:val": true } } }] }],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#break()", () => {
|
describe("#break()", () => {
|
||||||
it("it should add break to the run", () => {
|
it("it should add break to the run", () => {
|
||||||
run.break();
|
run.break();
|
||||||
const newJson = Utility.jsonify(run);
|
const tree = new Formatter().format(run);
|
||||||
assert.equal(newJson.root[1].rootKey, "w:br");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [{ "w:br": {} }],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#tab()", () => {
|
describe("#tab()", () => {
|
||||||
it("it should add break to the run", () => {
|
it("it should add break to the run", () => {
|
||||||
run.tab();
|
run.tab();
|
||||||
const newJson = Utility.jsonify(run);
|
const tree = new Formatter().format(run);
|
||||||
assert.equal(newJson.root[1].rootKey, "w:tab");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [{ "w:tab": {} }],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -114,7 +147,7 @@ describe("Run", () => {
|
|||||||
"w:r": [
|
"w:r": [
|
||||||
{
|
{
|
||||||
"w:rPr": [
|
"w:rPr": [
|
||||||
{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }] },
|
{ "w:rFonts": { _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -127,7 +160,7 @@ describe("Run", () => {
|
|||||||
run.color("001122");
|
run.color("001122");
|
||||||
const tree = new Formatter().format(run);
|
const tree = new Formatter().format(run);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:r": [{ "w:rPr": [{ "w:color": [{ _attr: { "w:val": "001122" } }] }] }],
|
"w:r": [{ "w:rPr": [{ "w:color": { _attr: { "w:val": "001122" } } }] }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -139,7 +172,7 @@ describe("Run", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:r": [
|
"w:r": [
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:sz": [{ _attr: { "w:val": 24 } }] }, { "w:szCs": [{ _attr: { "w:val": 24 } }] }],
|
"w:rPr": [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -151,7 +184,7 @@ describe("Run", () => {
|
|||||||
run.rightToLeft();
|
run.rightToLeft();
|
||||||
const tree = new Formatter().format(run);
|
const tree = new Formatter().format(run);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:r": [{ "w:rPr": [{ "w:rtl": [{ _attr: { "w:val": true } }] }] }],
|
"w:r": [{ "w:rPr": [{ "w:rtl": { _attr: { "w:val": true } } }] }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -162,11 +195,10 @@ describe("Run", () => {
|
|||||||
const tree = new Formatter().format(run);
|
const tree = new Formatter().format(run);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:r": [
|
"w:r": [
|
||||||
{ "w:rPr": [] },
|
{ "w:fldChar": { _attr: { "w:fldCharType": "begin" } } },
|
||||||
{ "w:fldChar": [{ _attr: { "w:fldCharType": "begin" } }] },
|
|
||||||
{ "w:instrText": [{ _attr: { "xml:space": "preserve" } }, "NUMPAGES"] },
|
{ "w:instrText": [{ _attr: { "xml:space": "preserve" } }, "NUMPAGES"] },
|
||||||
{ "w:fldChar": [{ _attr: { "w:fldCharType": "separate" } }] },
|
{ "w:fldChar": { _attr: { "w:fldCharType": "separate" } } },
|
||||||
{ "w:fldChar": [{ _attr: { "w:fldCharType": "end" } }] },
|
{ "w:fldChar": { _attr: { "w:fldCharType": "end" } } },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -178,11 +210,10 @@ describe("Run", () => {
|
|||||||
const tree = new Formatter().format(run);
|
const tree = new Formatter().format(run);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:r": [
|
"w:r": [
|
||||||
{ "w:rPr": [] },
|
{ "w:fldChar": { _attr: { "w:fldCharType": "begin" } } },
|
||||||
{ "w:fldChar": [{ _attr: { "w:fldCharType": "begin" } }] },
|
|
||||||
{ "w:instrText": [{ _attr: { "xml:space": "preserve" } }, "PAGE"] },
|
{ "w:instrText": [{ _attr: { "xml:space": "preserve" } }, "PAGE"] },
|
||||||
{ "w:fldChar": [{ _attr: { "w:fldCharType": "separate" } }] },
|
{ "w:fldChar": { _attr: { "w:fldCharType": "separate" } } },
|
||||||
{ "w:fldChar": [{ _attr: { "w:fldCharType": "end" } }] },
|
{ "w:fldChar": { _attr: { "w:fldCharType": "end" } } },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -193,7 +224,7 @@ describe("Run", () => {
|
|||||||
run.style("myRunStyle");
|
run.style("myRunStyle");
|
||||||
const tree = new Formatter().format(run);
|
const tree = new Formatter().format(run);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:r": [{ "w:rPr": [{ "w:rStyle": [{ _attr: { "w:val": "myRunStyle" } }] }] }],
|
"w:r": [{ "w:rPr": [{ "w:rStyle": { _attr: { "w:val": "myRunStyle" } } }] }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -17,17 +17,12 @@ describe("Sequential Identifier", () => {
|
|||||||
const DEFAULT_SEQ = {
|
const DEFAULT_SEQ = {
|
||||||
"w:r": [
|
"w:r": [
|
||||||
{
|
{
|
||||||
"w:rPr": [],
|
"w:fldChar": {
|
||||||
},
|
_attr: {
|
||||||
{
|
"w:fldCharType": "begin",
|
||||||
"w:fldChar": [
|
"w:dirty": true,
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:fldCharType": "begin",
|
|
||||||
"w:dirty": true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:instrText": [
|
"w:instrText": [
|
||||||
@ -40,22 +35,18 @@ const DEFAULT_SEQ = {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:fldChar": [
|
"w:fldChar": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:fldCharType": "separate",
|
||||||
"w:fldCharType": "separate",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:fldChar": [
|
"w:fldChar": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:fldCharType": "end",
|
||||||
"w:fldCharType": "end",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { assert } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Utility } from "tests/utility";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { DoubleStrike, Strike } from "./formatting";
|
import { DoubleStrike, Strike } from "./formatting";
|
||||||
|
|
||||||
@ -13,8 +13,14 @@ describe("Strike", () => {
|
|||||||
|
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a Strike with correct root key", () => {
|
it("should create a Strike with correct root key", () => {
|
||||||
const newJson = Utility.jsonify(strike);
|
const tree = new Formatter().format(strike);
|
||||||
assert.equal(newJson.rootKey, "w:strike");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:strike": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -28,8 +34,14 @@ describe("DoubleStrike", () => {
|
|||||||
|
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a Double Strike with correct root key", () => {
|
it("should create a Double Strike with correct root key", () => {
|
||||||
const newJson = Utility.jsonify(strike);
|
const tree = new Formatter().format(strike);
|
||||||
assert.equal(newJson.rootKey, "w:dstrike");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:dstrike": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { assert } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Utility } from "tests/utility";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { Tab } from "./tab";
|
import { Tab } from "./tab";
|
||||||
|
|
||||||
@ -13,8 +13,10 @@ describe("Tab", () => {
|
|||||||
|
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a Tab with correct root key", () => {
|
it("should create a Tab with correct root key", () => {
|
||||||
const newJson = Utility.jsonify(tab);
|
const tree = new Formatter().format(tab);
|
||||||
assert.equal(newJson.rootKey, "w:tab");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:tab": {},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -12,7 +12,7 @@ describe("TextRun", () => {
|
|||||||
run = new TextRun("test");
|
run = new TextRun("test");
|
||||||
const f = new Formatter().format(run);
|
const f = new Formatter().format(run);
|
||||||
expect(f).to.deep.equal({
|
expect(f).to.deep.equal({
|
||||||
"w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "test"] }],
|
"w:r": [{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "test"] }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { assert, expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
import { Utility } from "tests/utility";
|
|
||||||
|
|
||||||
import * as u from "./underline";
|
import * as u from "./underline";
|
||||||
|
|
||||||
@ -9,15 +8,21 @@ describe("Underline", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a new Underline object with u:u as the rootKey", () => {
|
it("should create a new Underline object with u:u as the rootKey", () => {
|
||||||
const underline = new u.Underline();
|
const underline = new u.Underline();
|
||||||
const newJson = Utility.jsonify(underline);
|
const tree = new Formatter().format(underline);
|
||||||
assert.equal(newJson.rootKey, "w:u");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:u": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "single",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should default to 'single' and no color", () => {
|
it("should default to 'single' and no color", () => {
|
||||||
const underline = new u.Underline();
|
const underline = new u.Underline();
|
||||||
const tree = new Formatter().format(underline);
|
const tree = new Formatter().format(underline);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:u": [{ _attr: { "w:val": "single" } }],
|
"w:u": { _attr: { "w:val": "single" } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -25,7 +30,7 @@ describe("Underline", () => {
|
|||||||
const underline = new u.Underline("double", "FF00CC");
|
const underline = new u.Underline("double", "FF00CC");
|
||||||
const tree = new Formatter().format(underline);
|
const tree = new Formatter().format(underline);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:u": [{ _attr: { "w:val": "double", "w:color": "FF00CC" } }],
|
"w:u": { _attr: { "w:val": "double", "w:color": "FF00CC" } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -33,16 +38,16 @@ describe("Underline", () => {
|
|||||||
|
|
||||||
describe("DashDotDotHeavyUnderline", () => {
|
describe("DashDotDotHeavyUnderline", () => {
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should have u:u as the rootKey", () => {
|
|
||||||
const underline = new u.DashDotDotHeavyUnderline();
|
|
||||||
const newJson = Utility.jsonify(underline);
|
|
||||||
assert.equal(newJson.rootKey, "w:u");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should put value in attribute", () => {
|
it("should put value in attribute", () => {
|
||||||
const underline = new u.DashDotDotHeavyUnderline();
|
const underline = new u.DashDotDotHeavyUnderline();
|
||||||
const newJson = Utility.jsonify(underline);
|
const tree = new Formatter().format(underline);
|
||||||
assert.equal(newJson.root[0].root.val, "dashDotDotHeavy");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:u": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "dashDotDotHeavy",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -51,8 +56,14 @@ describe("DashDotDotHeavyUnderline", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should put value in attribute", () => {
|
it("should put value in attribute", () => {
|
||||||
const underline = new u.DashDotHeavyUnderline();
|
const underline = new u.DashDotHeavyUnderline();
|
||||||
const newJson = Utility.jsonify(underline);
|
const tree = new Formatter().format(underline);
|
||||||
assert.equal(newJson.root[0].root.val, "dashDotHeavy");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:u": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "dashDotHeavy",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -61,8 +72,14 @@ describe("DashDotDotHeavyUnderline", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should put value in attribute", () => {
|
it("should put value in attribute", () => {
|
||||||
const underline = new u.DashLongHeavyUnderline();
|
const underline = new u.DashLongHeavyUnderline();
|
||||||
const newJson = Utility.jsonify(underline);
|
const tree = new Formatter().format(underline);
|
||||||
assert.equal(newJson.root[0].root.val, "dashLongHeavy");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:u": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "dashLongHeavy",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -71,8 +88,14 @@ describe("DashDotDotHeavyUnderline", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should put value in attribute", () => {
|
it("should put value in attribute", () => {
|
||||||
const underline = new u.DashLongUnderline();
|
const underline = new u.DashLongUnderline();
|
||||||
const newJson = Utility.jsonify(underline);
|
const tree = new Formatter().format(underline);
|
||||||
assert.equal(newJson.root[0].root.val, "dashLong");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:u": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "dashLong",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -81,8 +104,14 @@ describe("DashDotDotHeavyUnderline", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should put value in attribute", () => {
|
it("should put value in attribute", () => {
|
||||||
const underline = new u.DashUnderline();
|
const underline = new u.DashUnderline();
|
||||||
const newJson = Utility.jsonify(underline);
|
const tree = new Formatter().format(underline);
|
||||||
assert.equal(newJson.root[0].root.val, "dash");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:u": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "dash",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -91,8 +120,14 @@ describe("DashDotDotHeavyUnderline", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should put value in attribute", () => {
|
it("should put value in attribute", () => {
|
||||||
const underline = new u.DotDashUnderline();
|
const underline = new u.DotDashUnderline();
|
||||||
const newJson = Utility.jsonify(underline);
|
const tree = new Formatter().format(underline);
|
||||||
assert.equal(newJson.root[0].root.val, "dotDash");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:u": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "dotDash",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -101,8 +136,14 @@ describe("DashDotDotHeavyUnderline", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should put value in attribute", () => {
|
it("should put value in attribute", () => {
|
||||||
const underline = new u.DotDotDashUnderline();
|
const underline = new u.DotDotDashUnderline();
|
||||||
const newJson = Utility.jsonify(underline);
|
const tree = new Formatter().format(underline);
|
||||||
assert.equal(newJson.root[0].root.val, "dotDotDash");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:u": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "dotDotDash",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -111,8 +152,14 @@ describe("DashDotDotHeavyUnderline", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should put value in attribute", () => {
|
it("should put value in attribute", () => {
|
||||||
const underline = new u.DottedHeavyUnderline();
|
const underline = new u.DottedHeavyUnderline();
|
||||||
const newJson = Utility.jsonify(underline);
|
const tree = new Formatter().format(underline);
|
||||||
assert.equal(newJson.root[0].root.val, "dottedHeavy");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:u": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "dottedHeavy",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -121,8 +168,14 @@ describe("DashDotDotHeavyUnderline", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should put value in attribute", () => {
|
it("should put value in attribute", () => {
|
||||||
const underline = new u.DottedUnderline();
|
const underline = new u.DottedUnderline();
|
||||||
const newJson = Utility.jsonify(underline);
|
const tree = new Formatter().format(underline);
|
||||||
assert.equal(newJson.root[0].root.val, "dotted");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:u": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "dotted",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -131,8 +184,14 @@ describe("DashDotDotHeavyUnderline", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should put value in attribute", () => {
|
it("should put value in attribute", () => {
|
||||||
const underline = new u.DoubleUnderline();
|
const underline = new u.DoubleUnderline();
|
||||||
const newJson = Utility.jsonify(underline);
|
const tree = new Formatter().format(underline);
|
||||||
assert.equal(newJson.root[0].root.val, "double");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:u": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "double",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -141,8 +200,14 @@ describe("DashDotDotHeavyUnderline", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should put value in attribute", () => {
|
it("should put value in attribute", () => {
|
||||||
const underline = new u.SingleUnderline();
|
const underline = new u.SingleUnderline();
|
||||||
const newJson = Utility.jsonify(underline);
|
const tree = new Formatter().format(underline);
|
||||||
assert.equal(newJson.root[0].root.val, "single");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:u": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "single",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -151,8 +216,14 @@ describe("DashDotDotHeavyUnderline", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should put value in attribute", () => {
|
it("should put value in attribute", () => {
|
||||||
const underline = new u.ThickUnderline();
|
const underline = new u.ThickUnderline();
|
||||||
const newJson = Utility.jsonify(underline);
|
const tree = new Formatter().format(underline);
|
||||||
assert.equal(newJson.root[0].root.val, "thick");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:u": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "thick",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -161,8 +232,14 @@ describe("DashDotDotHeavyUnderline", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should put value in attribute", () => {
|
it("should put value in attribute", () => {
|
||||||
const underline = new u.WaveUnderline();
|
const underline = new u.WaveUnderline();
|
||||||
const newJson = Utility.jsonify(underline);
|
const tree = new Formatter().format(underline);
|
||||||
assert.equal(newJson.root[0].root.val, "wave");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:u": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "wave",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -171,8 +248,14 @@ describe("DashDotDotHeavyUnderline", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should put value in attribute", () => {
|
it("should put value in attribute", () => {
|
||||||
const underline = new u.WavyDoubleUnderline();
|
const underline = new u.WavyDoubleUnderline();
|
||||||
const newJson = Utility.jsonify(underline);
|
const tree = new Formatter().format(underline);
|
||||||
assert.equal(newJson.root[0].root.val, "wavyDouble");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:u": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "wavyDouble",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -181,8 +264,14 @@ describe("DashDotDotHeavyUnderline", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should put value in attribute", () => {
|
it("should put value in attribute", () => {
|
||||||
const underline = new u.WavyHeavyUnderline();
|
const underline = new u.WavyHeavyUnderline();
|
||||||
const newJson = Utility.jsonify(underline);
|
const tree = new Formatter().format(underline);
|
||||||
assert.equal(newJson.root[0].root.val, "wavyHeavy");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:u": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "wavyHeavy",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -191,8 +280,14 @@ describe("DashDotDotHeavyUnderline", () => {
|
|||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should put value in attribute", () => {
|
it("should put value in attribute", () => {
|
||||||
const underline = new u.WordsUnderline();
|
const underline = new u.WordsUnderline();
|
||||||
const newJson = Utility.jsonify(underline);
|
const tree = new Formatter().format(underline);
|
||||||
assert.equal(newJson.root[0].root.val, "words");
|
expect(tree).to.deep.equal({
|
||||||
|
"w:u": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "words",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -11,8 +11,7 @@ describe("Relationships", () => {
|
|||||||
const properties = new Relationships();
|
const properties = new Relationships();
|
||||||
const tree = new Formatter().format(properties);
|
const tree = new Formatter().format(properties);
|
||||||
expect(Object.keys(tree)).to.deep.equal(["Relationships"]);
|
expect(Object.keys(tree)).to.deep.equal(["Relationships"]);
|
||||||
expect(tree["Relationships"]).to.be.an.instanceof(Array);
|
expect(tree["Relationships"]).to.deep.equal({
|
||||||
expect(tree["Relationships"][0]).to.deep.equal({
|
|
||||||
_attr: { xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" },
|
_attr: { xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -2,13 +2,15 @@ import { expect } from "chai";
|
|||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
import { Compatibility } from "file/settings/compatibility";
|
import { Compatibility } from "file/settings/compatibility";
|
||||||
|
|
||||||
|
import { EMPTY_OBJECT } from "file/xml-components";
|
||||||
|
|
||||||
describe("Compatibility", () => {
|
describe("Compatibility", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
it("creates an initially empty property object", () => {
|
it("creates an initially empty property object", () => {
|
||||||
const compatibility = new Compatibility();
|
const compatibility = new Compatibility();
|
||||||
|
|
||||||
const tree = new Formatter().format(compatibility);
|
const tree = new Formatter().format(compatibility);
|
||||||
expect(tree).to.deep.equal({ "w:compat": [] });
|
expect(tree).to.deep.equal({ "w:compat": EMPTY_OBJECT });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -18,7 +20,7 @@ describe("Compatibility", () => {
|
|||||||
compatibility.doNotExpandShiftReturn();
|
compatibility.doNotExpandShiftReturn();
|
||||||
|
|
||||||
const tree = new Formatter().format(compatibility);
|
const tree = new Formatter().format(compatibility);
|
||||||
expect(tree).to.deep.equal({ "w:compat": [{ "w:doNotExpandShiftReturn": [] }] });
|
expect(tree).to.deep.equal({ "w:compat": [{ "w:doNotExpandShiftReturn": EMPTY_OBJECT }] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -13,9 +13,7 @@ describe("Settings", () => {
|
|||||||
expect(keys).is.an.instanceof(Array);
|
expect(keys).is.an.instanceof(Array);
|
||||||
expect(keys).has.length(1);
|
expect(keys).has.length(1);
|
||||||
expect(keys[0]).to.be.equal("w:settings");
|
expect(keys[0]).to.be.equal("w:settings");
|
||||||
expect(tree["w:settings"]).is.an.instanceof(Array);
|
keys = Object.keys(tree["w:settings"]);
|
||||||
expect(tree["w:settings"]).has.length(1);
|
|
||||||
keys = Object.keys(tree["w:settings"][0]);
|
|
||||||
expect(keys).is.an.instanceof(Array);
|
expect(keys).is.an.instanceof(Array);
|
||||||
expect(keys).has.length(1);
|
expect(keys).has.length(1);
|
||||||
expect(keys[0]).to.be.equal("_attr");
|
expect(keys[0]).to.be.equal("_attr");
|
||||||
@ -39,12 +37,12 @@ describe("Settings", () => {
|
|||||||
expect(keys).is.an.instanceof(Array);
|
expect(keys).is.an.instanceof(Array);
|
||||||
expect(keys).has.length(1);
|
expect(keys).has.length(1);
|
||||||
expect(keys[0]).to.be.equal("w:updateFields");
|
expect(keys[0]).to.be.equal("w:updateFields");
|
||||||
const updateFieldsArray = rootArray[1]["w:updateFields"];
|
const updateFields = rootArray[1]["w:updateFields"];
|
||||||
keys = Object.keys(updateFieldsArray[0]);
|
keys = Object.keys(updateFields);
|
||||||
expect(keys).is.an.instanceof(Array);
|
expect(keys).is.an.instanceof(Array);
|
||||||
expect(keys).has.length(1);
|
expect(keys).has.length(1);
|
||||||
expect(keys[0]).to.be.equal("_attr");
|
expect(keys[0]).to.be.equal("_attr");
|
||||||
const updateFieldsAttr = updateFieldsArray[0]._attr;
|
const updateFieldsAttr = updateFields._attr;
|
||||||
expect(updateFieldsAttr["w:val"]).to.be.equal(true);
|
expect(updateFieldsAttr["w:val"]).to.be.equal(true);
|
||||||
};
|
};
|
||||||
it("should add a UpdateFields with value true", () => {
|
it("should add a UpdateFields with value true", () => {
|
||||||
|
@ -5,22 +5,18 @@ import { Formatter } from "export/formatter";
|
|||||||
import { UpdateFields } from "./update-fields";
|
import { UpdateFields } from "./update-fields";
|
||||||
|
|
||||||
const UF_TRUE = {
|
const UF_TRUE = {
|
||||||
"w:updateFields": [
|
"w:updateFields": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": true,
|
||||||
"w:val": true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
};
|
};
|
||||||
const UF_FALSE = {
|
const UF_FALSE = {
|
||||||
"w:updateFields": [
|
"w:updateFields": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": false,
|
||||||
"w:val": false,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
};
|
};
|
||||||
describe("Update Fields", () => {
|
describe("Update Fields", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
|
@ -71,24 +71,34 @@ describe("External styles factory", () => {
|
|||||||
deleted: false,
|
deleted: false,
|
||||||
root: [
|
root: [
|
||||||
{
|
{
|
||||||
_attr: {
|
|
||||||
"w:ascii": "Arial",
|
|
||||||
"w:cstheme": "minorHAnsi",
|
|
||||||
"w:eastAsiaTheme": "minorHAnsi",
|
|
||||||
"w:hAnsi": "Arial",
|
|
||||||
},
|
|
||||||
deleted: false,
|
deleted: false,
|
||||||
root: [],
|
root: [
|
||||||
|
{
|
||||||
|
deleted: false,
|
||||||
|
root: {
|
||||||
|
"w:ascii": "Arial",
|
||||||
|
"w:cstheme": "minorHAnsi",
|
||||||
|
"w:eastAsiaTheme": "minorHAnsi",
|
||||||
|
"w:hAnsi": "Arial",
|
||||||
|
},
|
||||||
|
rootKey: "_attr",
|
||||||
|
},
|
||||||
|
],
|
||||||
rootKey: "w:rFonts",
|
rootKey: "w:rFonts",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_attr: {
|
|
||||||
"w:bidi": "ar-SA",
|
|
||||||
"w:eastAsia": "en-US",
|
|
||||||
"w:val": "en-US",
|
|
||||||
},
|
|
||||||
deleted: false,
|
deleted: false,
|
||||||
root: [],
|
root: [
|
||||||
|
{
|
||||||
|
deleted: false,
|
||||||
|
root: {
|
||||||
|
"w:bidi": "ar-SA",
|
||||||
|
"w:eastAsia": "en-US",
|
||||||
|
"w:val": "en-US",
|
||||||
|
},
|
||||||
|
rootKey: "_attr",
|
||||||
|
},
|
||||||
|
],
|
||||||
rootKey: "w:lang",
|
rootKey: "w:lang",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -104,13 +114,18 @@ describe("External styles factory", () => {
|
|||||||
deleted: false,
|
deleted: false,
|
||||||
root: [
|
root: [
|
||||||
{
|
{
|
||||||
_attr: {
|
|
||||||
"w:after": "160",
|
|
||||||
"w:line": "259",
|
|
||||||
"w:lineRule": "auto",
|
|
||||||
},
|
|
||||||
deleted: false,
|
deleted: false,
|
||||||
root: [],
|
root: [
|
||||||
|
{
|
||||||
|
deleted: false,
|
||||||
|
root: {
|
||||||
|
"w:after": "160",
|
||||||
|
"w:line": "259",
|
||||||
|
"w:lineRule": "auto",
|
||||||
|
},
|
||||||
|
rootKey: "_attr",
|
||||||
|
},
|
||||||
|
],
|
||||||
rootKey: "w:spacing",
|
rootKey: "w:spacing",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -123,12 +138,17 @@ describe("External styles factory", () => {
|
|||||||
rootKey: "w:docDefaults",
|
rootKey: "w:docDefaults",
|
||||||
});
|
});
|
||||||
expect(importedStyle.root[2]).to.deep.equal({
|
expect(importedStyle.root[2]).to.deep.equal({
|
||||||
_attr: {
|
|
||||||
"w:defLockedState": "1",
|
|
||||||
"w:defUIPriority": "99",
|
|
||||||
},
|
|
||||||
deleted: false,
|
deleted: false,
|
||||||
root: [],
|
root: [
|
||||||
|
{
|
||||||
|
deleted: false,
|
||||||
|
root: {
|
||||||
|
"w:defLockedState": "1",
|
||||||
|
"w:defUIPriority": "99",
|
||||||
|
},
|
||||||
|
rootKey: "_attr",
|
||||||
|
},
|
||||||
|
],
|
||||||
rootKey: "w:latentStyles",
|
rootKey: "w:latentStyles",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -139,19 +159,28 @@ describe("External styles factory", () => {
|
|||||||
|
|
||||||
expect(importedStyle.root.length).to.equal(5);
|
expect(importedStyle.root.length).to.equal(5);
|
||||||
expect(importedStyle.root[3]).to.deep.equal({
|
expect(importedStyle.root[3]).to.deep.equal({
|
||||||
_attr: {
|
|
||||||
"w:default": "1",
|
|
||||||
"w:styleId": "Normal",
|
|
||||||
"w:type": "paragraph",
|
|
||||||
},
|
|
||||||
deleted: false,
|
deleted: false,
|
||||||
root: [
|
root: [
|
||||||
{
|
{
|
||||||
_attr: {
|
|
||||||
"w:val": "Normal",
|
|
||||||
},
|
|
||||||
deleted: false,
|
deleted: false,
|
||||||
root: [],
|
root: {
|
||||||
|
"w:default": "1",
|
||||||
|
"w:styleId": "Normal",
|
||||||
|
"w:type": "paragraph",
|
||||||
|
},
|
||||||
|
rootKey: "_attr",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
deleted: false,
|
||||||
|
root: [
|
||||||
|
{
|
||||||
|
deleted: false,
|
||||||
|
root: {
|
||||||
|
"w:val": "Normal",
|
||||||
|
},
|
||||||
|
rootKey: "_attr",
|
||||||
|
},
|
||||||
|
],
|
||||||
rootKey: "w:name",
|
rootKey: "w:name",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -164,26 +193,40 @@ describe("External styles factory", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(importedStyle.root[4]).to.deep.equal({
|
expect(importedStyle.root[4]).to.deep.equal({
|
||||||
_attr: {
|
|
||||||
"w:styleId": "Heading1",
|
|
||||||
"w:type": "paragraph",
|
|
||||||
},
|
|
||||||
deleted: false,
|
deleted: false,
|
||||||
root: [
|
root: [
|
||||||
{
|
{
|
||||||
_attr: {
|
|
||||||
"w:val": "heading 1",
|
|
||||||
},
|
|
||||||
deleted: false,
|
deleted: false,
|
||||||
root: [],
|
root: {
|
||||||
|
"w:styleId": "Heading1",
|
||||||
|
"w:type": "paragraph",
|
||||||
|
},
|
||||||
|
rootKey: "_attr",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
deleted: false,
|
||||||
|
root: [
|
||||||
|
{
|
||||||
|
deleted: false,
|
||||||
|
root: {
|
||||||
|
"w:val": "heading 1",
|
||||||
|
},
|
||||||
|
rootKey: "_attr",
|
||||||
|
},
|
||||||
|
],
|
||||||
rootKey: "w:name",
|
rootKey: "w:name",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_attr: {
|
|
||||||
"w:val": "Normal",
|
|
||||||
},
|
|
||||||
deleted: false,
|
deleted: false,
|
||||||
root: [],
|
root: [
|
||||||
|
{
|
||||||
|
deleted: false,
|
||||||
|
root: {
|
||||||
|
"w:val": "Normal",
|
||||||
|
},
|
||||||
|
rootKey: "_attr",
|
||||||
|
},
|
||||||
|
],
|
||||||
rootKey: "w:basedOn",
|
rootKey: "w:basedOn",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -203,14 +246,19 @@ describe("External styles factory", () => {
|
|||||||
deleted: false,
|
deleted: false,
|
||||||
root: [
|
root: [
|
||||||
{
|
{
|
||||||
_attr: {
|
|
||||||
"w:color": "auto",
|
|
||||||
"w:space": "1",
|
|
||||||
"w:sz": "4",
|
|
||||||
"w:val": "single",
|
|
||||||
},
|
|
||||||
deleted: false,
|
deleted: false,
|
||||||
root: [],
|
root: [
|
||||||
|
{
|
||||||
|
deleted: false,
|
||||||
|
root: {
|
||||||
|
"w:color": "auto",
|
||||||
|
"w:space": "1",
|
||||||
|
"w:sz": "4",
|
||||||
|
"w:val": "single",
|
||||||
|
},
|
||||||
|
rootKey: "_attr",
|
||||||
|
},
|
||||||
|
],
|
||||||
rootKey: "w:bottom",
|
rootKey: "w:bottom",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1 +1,3 @@
|
|||||||
export * from "./styles";
|
export * from "./styles";
|
||||||
|
export * from "./style/character-style";
|
||||||
|
export * from "./style/paragraph-style";
|
||||||
|
@ -4,6 +4,8 @@ import { Formatter } from "export/formatter";
|
|||||||
|
|
||||||
import { CharacterStyle } from "./character-style";
|
import { CharacterStyle } from "./character-style";
|
||||||
|
|
||||||
|
import { EMPTY_OBJECT } from "file/xml-components";
|
||||||
|
|
||||||
describe("CharacterStyle", () => {
|
describe("CharacterStyle", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
it("should set the style type to character and use the given style id", () => {
|
it("should set the style type to character and use the given style id", () => {
|
||||||
@ -12,18 +14,15 @@ describe("CharacterStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||||
{ "w:rPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:uiPriority": [
|
"w:uiPriority": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "99",
|
||||||
"w:val": "99",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:unhideWhenUsed": [],
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -35,19 +34,16 @@ describe("CharacterStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||||
{ "w:name": [{ _attr: { "w:val": "Style Name" } }] },
|
{ "w:name": { _attr: { "w:val": "Style Name" } } },
|
||||||
{ "w:rPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:uiPriority": [
|
"w:uiPriority": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "99",
|
||||||
"w:val": "99",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:unhideWhenUsed": [],
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -61,20 +57,17 @@ describe("CharacterStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||||
{ "w:rPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:uiPriority": [
|
"w:uiPriority": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "99",
|
||||||
"w:val": "99",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:unhideWhenUsed": [],
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
{ "w:basedOn": [{ _attr: { "w:val": "otherId" } }] },
|
{ "w:basedOn": { _attr: { "w:val": "otherId" } } },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -88,19 +81,17 @@ describe("CharacterStyle", () => {
|
|||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:sz": [{ _attr: { "w:val": 24 } }] }, { "w:szCs": [{ _attr: { "w:val": 24 } }] }],
|
"w:rPr": [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:uiPriority": [
|
"w:uiPriority": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "99",
|
||||||
"w:val": "99",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:unhideWhenUsed": [],
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -114,19 +105,17 @@ describe("CharacterStyle", () => {
|
|||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:u": [{ _attr: { "w:val": "single" } }] }],
|
"w:rPr": [{ "w:u": { _attr: { "w:val": "single" } } }],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:uiPriority": [
|
"w:uiPriority": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "99",
|
||||||
"w:val": "99",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:unhideWhenUsed": [],
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -139,19 +128,17 @@ describe("CharacterStyle", () => {
|
|||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:u": [{ _attr: { "w:val": "double" } }] }],
|
"w:rPr": [{ "w:u": { _attr: { "w:val": "double" } } }],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:uiPriority": [
|
"w:uiPriority": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "99",
|
||||||
"w:val": "99",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:unhideWhenUsed": [],
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -164,19 +151,17 @@ describe("CharacterStyle", () => {
|
|||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:u": [{ _attr: { "w:val": "double", "w:color": "005599" } }] }],
|
"w:rPr": [{ "w:u": { _attr: { "w:val": "double", "w:color": "005599" } } }],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:uiPriority": [
|
"w:uiPriority": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "99",
|
||||||
"w:val": "99",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:unhideWhenUsed": [],
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -192,27 +177,23 @@ describe("CharacterStyle", () => {
|
|||||||
{
|
{
|
||||||
"w:rPr": [
|
"w:rPr": [
|
||||||
{
|
{
|
||||||
"w:vertAlign": [
|
"w:vertAlign": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "superscript",
|
||||||
"w:val": "superscript",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"w:uiPriority": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:val": "99",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:unhideWhenUsed": [],
|
"w:uiPriority": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "99",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -225,19 +206,17 @@ describe("CharacterStyle", () => {
|
|||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:color": [{ _attr: { "w:val": "123456" } }] }],
|
"w:rPr": [{ "w:color": { _attr: { "w:val": "123456" } } }],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:uiPriority": [
|
"w:uiPriority": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "99",
|
||||||
"w:val": "99",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:unhideWhenUsed": [],
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -250,19 +229,17 @@ describe("CharacterStyle", () => {
|
|||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:b": [{ _attr: { "w:val": true } }] }],
|
"w:rPr": [{ "w:b": { _attr: { "w:val": true } } }],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:uiPriority": [
|
"w:uiPriority": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "99",
|
||||||
"w:val": "99",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:unhideWhenUsed": [],
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -275,19 +252,17 @@ describe("CharacterStyle", () => {
|
|||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:i": [{ _attr: { "w:val": true } }] }],
|
"w:rPr": [{ "w:i": { _attr: { "w:val": true } } }],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:uiPriority": [
|
"w:uiPriority": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "99",
|
||||||
"w:val": "99",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:unhideWhenUsed": [],
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -300,21 +275,16 @@ describe("CharacterStyle", () => {
|
|||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||||
{
|
{
|
||||||
"w:rPr": [],
|
"w:uiPriority": {
|
||||||
},
|
_attr: {
|
||||||
{
|
"w:val": "99",
|
||||||
"w:uiPriority": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:val": "99",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:unhideWhenUsed": [],
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
{ "w:link": [{ _attr: { "w:val": "MyLink" } }] },
|
{ "w:link": { _attr: { "w:val": "MyLink" } } },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -326,19 +296,14 @@ describe("CharacterStyle", () => {
|
|||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||||
{
|
{
|
||||||
"w:rPr": [],
|
"w:uiPriority": {
|
||||||
},
|
_attr: {
|
||||||
{
|
"w:val": "99",
|
||||||
"w:uiPriority": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:val": "99",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{ "w:unhideWhenUsed": [] },
|
{ "w:unhideWhenUsed": EMPTY_OBJECT },
|
||||||
{ "w:semiHidden": [] },
|
{ "w:semiHidden": EMPTY_OBJECT },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -2,52 +2,54 @@ import { expect } from "chai";
|
|||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
import * as components from "./components";
|
import * as components from "./components";
|
||||||
|
|
||||||
|
import { EMPTY_OBJECT } from "file/xml-components";
|
||||||
|
|
||||||
describe("Style components", () => {
|
describe("Style components", () => {
|
||||||
it("Name#constructor", () => {
|
it("Name#constructor", () => {
|
||||||
const style = new components.Name("Style Name");
|
const style = new components.Name("Style Name");
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({ "w:name": [{ _attr: { "w:val": "Style Name" } }] });
|
expect(tree).to.deep.equal({ "w:name": { _attr: { "w:val": "Style Name" } } });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("BasedOn#constructor", () => {
|
it("BasedOn#constructor", () => {
|
||||||
const style = new components.BasedOn("otherId");
|
const style = new components.BasedOn("otherId");
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({ "w:basedOn": [{ _attr: { "w:val": "otherId" } }] });
|
expect(tree).to.deep.equal({ "w:basedOn": { _attr: { "w:val": "otherId" } } });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Next#constructor", () => {
|
it("Next#constructor", () => {
|
||||||
const style = new components.Next("otherId");
|
const style = new components.Next("otherId");
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({ "w:next": [{ _attr: { "w:val": "otherId" } }] });
|
expect(tree).to.deep.equal({ "w:next": { _attr: { "w:val": "otherId" } } });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Link#constructor", () => {
|
it("Link#constructor", () => {
|
||||||
const style = new components.Link("otherId");
|
const style = new components.Link("otherId");
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({ "w:link": [{ _attr: { "w:val": "otherId" } }] });
|
expect(tree).to.deep.equal({ "w:link": { _attr: { "w:val": "otherId" } } });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("UiPriority#constructor", () => {
|
it("UiPriority#constructor", () => {
|
||||||
const style = new components.UiPriority("123");
|
const style = new components.UiPriority("123");
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({ "w:uiPriority": [{ _attr: { "w:val": "123" } }] });
|
expect(tree).to.deep.equal({ "w:uiPriority": { _attr: { "w:val": "123" } } });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("UnhideWhenUsed#constructor", () => {
|
it("UnhideWhenUsed#constructor", () => {
|
||||||
const style = new components.UnhideWhenUsed();
|
const style = new components.UnhideWhenUsed();
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({ "w:unhideWhenUsed": [] });
|
expect(tree).to.deep.equal({ "w:unhideWhenUsed": EMPTY_OBJECT });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("QuickFormat#constructor", () => {
|
it("QuickFormat#constructor", () => {
|
||||||
const style = new components.QuickFormat();
|
const style = new components.QuickFormat();
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({ "w:qFormat": [] });
|
expect(tree).to.deep.equal({ "w:qFormat": EMPTY_OBJECT });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("SemiHidden#constructor", () => {
|
it("SemiHidden#constructor", () => {
|
||||||
const style = new components.SemiHidden();
|
const style = new components.SemiHidden();
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({ "w:semiHidden": [] });
|
expect(tree).to.deep.equal({ "w:semiHidden": EMPTY_OBJECT });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -2,6 +2,8 @@ import { expect } from "chai";
|
|||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
import * as defaultStyels from "./default-styles";
|
import * as defaultStyels from "./default-styles";
|
||||||
|
|
||||||
|
import { EMPTY_OBJECT } from "file/xml-components";
|
||||||
|
|
||||||
describe("Default Styles", () => {
|
describe("Default Styles", () => {
|
||||||
it("HeadingStyle#constructor", () => {
|
it("HeadingStyle#constructor", () => {
|
||||||
const style = new defaultStyels.HeadingStyle("Heading1", "Heading 1");
|
const style = new defaultStyels.HeadingStyle("Heading1", "Heading 1");
|
||||||
@ -9,12 +11,10 @@ describe("Default Styles", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "Heading1" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "Heading1" } },
|
||||||
{ "w:name": [{ _attr: { "w:val": "Heading 1" } }] },
|
{ "w:name": { _attr: { "w:val": "Heading 1" } } },
|
||||||
{ "w:pPr": [] },
|
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||||
{ "w:rPr": [] },
|
{ "w:next": { _attr: { "w:val": "Normal" } } },
|
||||||
{ "w:basedOn": [{ _attr: { "w:val": "Normal" } }] },
|
{ "w:qFormat": EMPTY_OBJECT },
|
||||||
{ "w:next": [{ _attr: { "w:val": "Normal" } }] },
|
|
||||||
{ "w:qFormat": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -25,12 +25,10 @@ describe("Default Styles", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "Title" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "Title" } },
|
||||||
{ "w:name": [{ _attr: { "w:val": "Title" } }] },
|
{ "w:name": { _attr: { "w:val": "Title" } } },
|
||||||
{ "w:pPr": [] },
|
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||||
{ "w:rPr": [] },
|
{ "w:next": { _attr: { "w:val": "Normal" } } },
|
||||||
{ "w:basedOn": [{ _attr: { "w:val": "Normal" } }] },
|
{ "w:qFormat": EMPTY_OBJECT },
|
||||||
{ "w:next": [{ _attr: { "w:val": "Normal" } }] },
|
|
||||||
{ "w:qFormat": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -41,12 +39,10 @@ describe("Default Styles", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "Heading1" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "Heading1" } },
|
||||||
{ "w:name": [{ _attr: { "w:val": "Heading 1" } }] },
|
{ "w:name": { _attr: { "w:val": "Heading 1" } } },
|
||||||
{ "w:pPr": [] },
|
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||||
{ "w:rPr": [] },
|
{ "w:next": { _attr: { "w:val": "Normal" } } },
|
||||||
{ "w:basedOn": [{ _attr: { "w:val": "Normal" } }] },
|
{ "w:qFormat": EMPTY_OBJECT },
|
||||||
{ "w:next": [{ _attr: { "w:val": "Normal" } }] },
|
|
||||||
{ "w:qFormat": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -57,12 +53,10 @@ describe("Default Styles", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "Heading2" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "Heading2" } },
|
||||||
{ "w:name": [{ _attr: { "w:val": "Heading 2" } }] },
|
{ "w:name": { _attr: { "w:val": "Heading 2" } } },
|
||||||
{ "w:pPr": [] },
|
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||||
{ "w:rPr": [] },
|
{ "w:next": { _attr: { "w:val": "Normal" } } },
|
||||||
{ "w:basedOn": [{ _attr: { "w:val": "Normal" } }] },
|
{ "w:qFormat": EMPTY_OBJECT },
|
||||||
{ "w:next": [{ _attr: { "w:val": "Normal" } }] },
|
|
||||||
{ "w:qFormat": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -73,12 +67,10 @@ describe("Default Styles", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "Heading3" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "Heading3" } },
|
||||||
{ "w:name": [{ _attr: { "w:val": "Heading 3" } }] },
|
{ "w:name": { _attr: { "w:val": "Heading 3" } } },
|
||||||
{ "w:pPr": [] },
|
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||||
{ "w:rPr": [] },
|
{ "w:next": { _attr: { "w:val": "Normal" } } },
|
||||||
{ "w:basedOn": [{ _attr: { "w:val": "Normal" } }] },
|
{ "w:qFormat": EMPTY_OBJECT },
|
||||||
{ "w:next": [{ _attr: { "w:val": "Normal" } }] },
|
|
||||||
{ "w:qFormat": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -89,12 +81,10 @@ describe("Default Styles", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "Heading4" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "Heading4" } },
|
||||||
{ "w:name": [{ _attr: { "w:val": "Heading 4" } }] },
|
{ "w:name": { _attr: { "w:val": "Heading 4" } } },
|
||||||
{ "w:pPr": [] },
|
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||||
{ "w:rPr": [] },
|
{ "w:next": { _attr: { "w:val": "Normal" } } },
|
||||||
{ "w:basedOn": [{ _attr: { "w:val": "Normal" } }] },
|
{ "w:qFormat": EMPTY_OBJECT },
|
||||||
{ "w:next": [{ _attr: { "w:val": "Normal" } }] },
|
|
||||||
{ "w:qFormat": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -105,12 +95,10 @@ describe("Default Styles", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "Heading5" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "Heading5" } },
|
||||||
{ "w:name": [{ _attr: { "w:val": "Heading 5" } }] },
|
{ "w:name": { _attr: { "w:val": "Heading 5" } } },
|
||||||
{ "w:pPr": [] },
|
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||||
{ "w:rPr": [] },
|
{ "w:next": { _attr: { "w:val": "Normal" } } },
|
||||||
{ "w:basedOn": [{ _attr: { "w:val": "Normal" } }] },
|
{ "w:qFormat": EMPTY_OBJECT },
|
||||||
{ "w:next": [{ _attr: { "w:val": "Normal" } }] },
|
|
||||||
{ "w:qFormat": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -121,12 +109,10 @@ describe("Default Styles", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "Heading6" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "Heading6" } },
|
||||||
{ "w:name": [{ _attr: { "w:val": "Heading 6" } }] },
|
{ "w:name": { _attr: { "w:val": "Heading 6" } } },
|
||||||
{ "w:pPr": [] },
|
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||||
{ "w:rPr": [] },
|
{ "w:next": { _attr: { "w:val": "Normal" } } },
|
||||||
{ "w:basedOn": [{ _attr: { "w:val": "Normal" } }] },
|
{ "w:qFormat": EMPTY_OBJECT },
|
||||||
{ "w:next": [{ _attr: { "w:val": "Normal" } }] },
|
|
||||||
{ "w:qFormat": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -137,11 +123,9 @@ describe("Default Styles", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "ListParagraph" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "ListParagraph" } },
|
||||||
{ "w:name": [{ _attr: { "w:val": "List Paragraph" } }] },
|
{ "w:name": { _attr: { "w:val": "List Paragraph" } } },
|
||||||
{ "w:pPr": [] },
|
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||||
{ "w:rPr": [] },
|
{ "w:qFormat": EMPTY_OBJECT },
|
||||||
{ "w:basedOn": [{ _attr: { "w:val": "Normal" } }] },
|
|
||||||
{ "w:qFormat": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -152,60 +136,52 @@ describe("Default Styles", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "FootnoteText" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "FootnoteText" } },
|
||||||
{ "w:name": [{ _attr: { "w:val": "footnote text" } }] },
|
{ "w:name": { _attr: { "w:val": "footnote text" } } },
|
||||||
{
|
{
|
||||||
"w:pPr": [
|
"w:pPr": [
|
||||||
{
|
{
|
||||||
"w:spacing": [
|
"w:spacing": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:after": 0,
|
||||||
"w:after": 0,
|
"w:line": 240,
|
||||||
"w:line": 240,
|
"w:lineRule": "auto",
|
||||||
"w:lineRule": "auto",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:rPr": [
|
"w:rPr": [
|
||||||
{
|
{
|
||||||
"w:sz": [
|
"w:sz": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": 20,
|
||||||
"w:val": 20,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:szCs": [
|
"w:szCs": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": 20,
|
||||||
"w:val": 20,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{ "w:basedOn": [{ _attr: { "w:val": "Normal" } }] },
|
|
||||||
{ "w:link": [{ _attr: { "w:val": "FootnoteTextChar" } }] },
|
|
||||||
{
|
|
||||||
"w:uiPriority": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:val": "99",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||||
|
{ "w:link": { _attr: { "w:val": "FootnoteTextChar" } } },
|
||||||
{
|
{
|
||||||
"w:semiHidden": [],
|
"w:uiPriority": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "99",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:unhideWhenUsed": [],
|
"w:semiHidden": EMPTY_OBJECT,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -217,36 +193,32 @@ describe("Default Styles", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "character", "w:styleId": "FootnoteReference" } },
|
{ _attr: { "w:type": "character", "w:styleId": "FootnoteReference" } },
|
||||||
{ "w:name": [{ _attr: { "w:val": "footnote reference" } }] },
|
{ "w:name": { _attr: { "w:val": "footnote reference" } } },
|
||||||
{
|
{
|
||||||
"w:rPr": [
|
"w:rPr": [
|
||||||
{
|
{
|
||||||
"w:vertAlign": [
|
"w:vertAlign": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "superscript",
|
||||||
"w:val": "superscript",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"w:uiPriority": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:val": "99",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:unhideWhenUsed": [],
|
"w:uiPriority": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "99",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{ "w:basedOn": [{ _attr: { "w:val": "DefaultParagraphFont" } }] },
|
{
|
||||||
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
|
},
|
||||||
|
{ "w:basedOn": { _attr: { "w:val": "DefaultParagraphFont" } } },
|
||||||
|
|
||||||
{
|
{
|
||||||
"w:semiHidden": [],
|
"w:semiHidden": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -258,45 +230,39 @@ describe("Default Styles", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "character", "w:styleId": "FootnoteTextChar" } },
|
{ _attr: { "w:type": "character", "w:styleId": "FootnoteTextChar" } },
|
||||||
{ "w:name": [{ _attr: { "w:val": "Footnote Text Char" } }] },
|
{ "w:name": { _attr: { "w:val": "Footnote Text Char" } } },
|
||||||
{
|
{
|
||||||
"w:rPr": [
|
"w:rPr": [
|
||||||
{
|
{
|
||||||
"w:sz": [
|
"w:sz": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": 20,
|
||||||
"w:val": 20,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:szCs": [
|
"w:szCs": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": 20,
|
||||||
"w:val": 20,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"w:uiPriority": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:val": "99",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:unhideWhenUsed": [],
|
"w:uiPriority": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "99",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{ "w:basedOn": [{ _attr: { "w:val": "DefaultParagraphFont" } }] },
|
|
||||||
{ "w:link": [{ _attr: { "w:val": "FootnoteText" } }] },
|
|
||||||
{
|
{
|
||||||
"w:semiHidden": [],
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
|
},
|
||||||
|
{ "w:basedOn": { _attr: { "w:val": "DefaultParagraphFont" } } },
|
||||||
|
{ "w:link": { _attr: { "w:val": "FootnoteText" } } },
|
||||||
|
{
|
||||||
|
"w:semiHidden": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -308,23 +274,21 @@ describe("Default Styles", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "character", "w:styleId": "Hyperlink" } },
|
{ _attr: { "w:type": "character", "w:styleId": "Hyperlink" } },
|
||||||
{ "w:name": [{ _attr: { "w:val": "Hyperlink" } }] },
|
{ "w:name": { _attr: { "w:val": "Hyperlink" } } },
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:color": [{ _attr: { "w:val": "0563C1" } }] }, { "w:u": [{ _attr: { "w:val": "single" } }] }],
|
"w:rPr": [{ "w:color": { _attr: { "w:val": "0563C1" } } }, { "w:u": { _attr: { "w:val": "single" } } }],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:uiPriority": [
|
"w:uiPriority": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "99",
|
||||||
"w:val": "99",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:unhideWhenUsed": [],
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
{ "w:basedOn": [{ _attr: { "w:val": "DefaultParagraphFont" } }] },
|
{ "w:basedOn": { _attr: { "w:val": "DefaultParagraphFont" } } },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -4,13 +4,15 @@ import { Formatter } from "export/formatter";
|
|||||||
|
|
||||||
import { ParagraphStyle } from "./paragraph-style";
|
import { ParagraphStyle } from "./paragraph-style";
|
||||||
|
|
||||||
|
import { EMPTY_OBJECT } from "file/xml-components";
|
||||||
|
|
||||||
describe("ParagraphStyle", () => {
|
describe("ParagraphStyle", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
it("should set the style type to paragraph and use the given style id", () => {
|
it("should set the style type to paragraph and use the given style id", () => {
|
||||||
const style = new ParagraphStyle("myStyleId");
|
const style = new ParagraphStyle("myStyleId");
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [] }, { "w:rPr": [] }],
|
"w:style": { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -20,9 +22,7 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:name": [{ _attr: { "w:val": "Style Name" } }] },
|
{ "w:name": { _attr: { "w:val": "Style Name" } } },
|
||||||
{ "w:pPr": [] },
|
|
||||||
{ "w:rPr": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -35,9 +35,7 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [] },
|
{ "w:basedOn": { _attr: { "w:val": "otherId" } } },
|
||||||
{ "w:rPr": [] },
|
|
||||||
{ "w:basedOn": [{ _attr: { "w:val": "otherId" } }] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -46,12 +44,7 @@ describe("ParagraphStyle", () => {
|
|||||||
const style = new ParagraphStyle("myStyleId").quickFormat();
|
const style = new ParagraphStyle("myStyleId").quickFormat();
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:qFormat": EMPTY_OBJECT }],
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
|
||||||
{ "w:pPr": [] },
|
|
||||||
{ "w:rPr": [] },
|
|
||||||
{ "w:qFormat": [] },
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -61,9 +54,7 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [] },
|
{ "w:next": { _attr: { "w:val": "otherId" } } },
|
||||||
{ "w:rPr": [] },
|
|
||||||
{ "w:next": [{ _attr: { "w:val": "otherId" } }] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -77,9 +68,8 @@ describe("ParagraphStyle", () => {
|
|||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:ind": [{ _attr: { "w:left": 720 } }] }],
|
"w:pPr": [{ "w:ind": { _attr: { "w:left": 720 } } }],
|
||||||
},
|
},
|
||||||
{ "w:rPr": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -91,9 +81,8 @@ describe("ParagraphStyle", () => {
|
|||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:spacing": [{ _attr: { "w:before": 50, "w:after": 150 } }] }],
|
"w:pPr": [{ "w:spacing": { _attr: { "w:before": 50, "w:after": 150 } } }],
|
||||||
},
|
},
|
||||||
{ "w:rPr": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -105,9 +94,8 @@ describe("ParagraphStyle", () => {
|
|||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "center" } }] }],
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "center" } } }],
|
||||||
},
|
},
|
||||||
{ "w:rPr": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -118,9 +106,8 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:spacing": [{ _attr: { "w:val": 24 } }] }],
|
"w:rPr": [{ "w:spacing": { _attr: { "w:val": 24 } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -133,9 +120,8 @@ describe("ParagraphStyle", () => {
|
|||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "left" } }] }],
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "left" } } }],
|
||||||
},
|
},
|
||||||
{ "w:rPr": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -147,9 +133,8 @@ describe("ParagraphStyle", () => {
|
|||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "right" } }] }],
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "right" } } }],
|
||||||
},
|
},
|
||||||
{ "w:rPr": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -161,9 +146,8 @@ describe("ParagraphStyle", () => {
|
|||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{
|
{
|
||||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "both" } }] }],
|
"w:pPr": [{ "w:jc": { _attr: { "w:val": "both" } } }],
|
||||||
},
|
},
|
||||||
{ "w:rPr": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -179,22 +163,19 @@ describe("ParagraphStyle", () => {
|
|||||||
{
|
{
|
||||||
"w:pBdr": [
|
"w:pBdr": [
|
||||||
{
|
{
|
||||||
"w:bottom": [
|
"w:bottom": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:color": "auto",
|
||||||
"w:color": "auto",
|
"w:space": "1",
|
||||||
"w:space": "1",
|
"w:val": "single",
|
||||||
"w:val": "single",
|
"w:sz": "6",
|
||||||
"w:sz": "6",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{ "w:rPr": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -208,11 +189,10 @@ describe("ParagraphStyle", () => {
|
|||||||
{
|
{
|
||||||
"w:pPr": [
|
"w:pPr": [
|
||||||
{
|
{
|
||||||
"w:tabs": [{ "w:tab": [{ _attr: { "w:val": "left", "w:pos": 1200 } }] }],
|
"w:tabs": [{ "w:tab": { _attr: { "w:val": "left", "w:pos": 1200 } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{ "w:rPr": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -226,11 +206,10 @@ describe("ParagraphStyle", () => {
|
|||||||
{
|
{
|
||||||
"w:pPr": [
|
"w:pPr": [
|
||||||
{
|
{
|
||||||
"w:tabs": [{ "w:tab": [{ _attr: { "w:val": "right", "w:pos": 9026 } }] }],
|
"w:tabs": [{ "w:tab": { _attr: { "w:val": "right", "w:pos": 9026 } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{ "w:rPr": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -239,11 +218,7 @@ describe("ParagraphStyle", () => {
|
|||||||
const style = new ParagraphStyle("myStyleId").keepLines();
|
const style = new ParagraphStyle("myStyleId").keepLines();
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [{ "w:keepLines": EMPTY_OBJECT }] }],
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
|
||||||
{ "w:pPr": [{ "w:keepLines": [] }] },
|
|
||||||
{ "w:rPr": [] },
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -251,11 +226,7 @@ describe("ParagraphStyle", () => {
|
|||||||
const style = new ParagraphStyle("myStyleId").keepNext();
|
const style = new ParagraphStyle("myStyleId").keepNext();
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [{ "w:keepNext": EMPTY_OBJECT }] }],
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
|
||||||
{ "w:pPr": [{ "w:keepNext": [] }] },
|
|
||||||
{ "w:rPr": [] },
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -265,8 +236,7 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [{ "w:outlineLvl": [{ _attr: { "w:val": "1" } }] }] },
|
{ "w:pPr": [{ "w:outlineLvl": { _attr: { "w:val": "1" } } }] },
|
||||||
{ "w:rPr": [] },
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -279,9 +249,8 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:sz": [{ _attr: { "w:val": 24 } }] }, { "w:szCs": [{ _attr: { "w:val": 24 } }] }],
|
"w:rPr": [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -293,9 +262,8 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:smallCaps": [{ _attr: { "w:val": true } }] }],
|
"w:rPr": [{ "w:smallCaps": { _attr: { "w:val": true } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -307,9 +275,8 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:caps": [{ _attr: { "w:val": true } }] }],
|
"w:rPr": [{ "w:caps": { _attr: { "w:val": true } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -321,9 +288,8 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:strike": [{ _attr: { "w:val": true } }] }],
|
"w:rPr": [{ "w:strike": { _attr: { "w:val": true } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -335,9 +301,8 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:dstrike": [{ _attr: { "w:val": true } }] }],
|
"w:rPr": [{ "w:dstrike": { _attr: { "w:val": true } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -349,9 +314,8 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:vertAlign": [{ _attr: { "w:val": "subscript" } }] }],
|
"w:rPr": [{ "w:vertAlign": { _attr: { "w:val": "subscript" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -363,9 +327,8 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:vertAlign": [{ _attr: { "w:val": "superscript" } }] }],
|
"w:rPr": [{ "w:vertAlign": { _attr: { "w:val": "superscript" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -377,10 +340,9 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:rPr": [
|
"w:rPr": [
|
||||||
{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }] },
|
{ "w:rFonts": { _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -393,9 +355,8 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:b": [{ _attr: { "w:val": true } }] }],
|
"w:rPr": [{ "w:b": { _attr: { "w:val": true } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -407,9 +368,8 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:i": [{ _attr: { "w:val": true } }] }],
|
"w:rPr": [{ "w:i": { _attr: { "w:val": true } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -422,9 +382,8 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:u": [{ _attr: { "w:val": "single" } }] }],
|
"w:rPr": [{ "w:u": { _attr: { "w:val": "single" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -436,9 +395,8 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:u": [{ _attr: { "w:val": "double" } }] }],
|
"w:rPr": [{ "w:u": { _attr: { "w:val": "double" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -450,9 +408,8 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:u": [{ _attr: { "w:val": "double", "w:color": "005599" } }] }],
|
"w:rPr": [{ "w:u": { _attr: { "w:val": "double", "w:color": "005599" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -465,9 +422,8 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:rPr": [{ "w:color": [{ _attr: { "w:val": "123456" } }] }],
|
"w:rPr": [{ "w:color": { _attr: { "w:val": "123456" } } }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -477,12 +433,7 @@ describe("ParagraphStyle", () => {
|
|||||||
const style = new ParagraphStyle("myStyleId").link("MyLink");
|
const style = new ParagraphStyle("myStyleId").link("MyLink");
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:link": { _attr: { "w:val": "MyLink" } } }],
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
|
||||||
{ "w:pPr": [] },
|
|
||||||
{ "w:rPr": [] },
|
|
||||||
{ "w:link": [{ _attr: { "w:val": "MyLink" } }] },
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -490,12 +441,7 @@ describe("ParagraphStyle", () => {
|
|||||||
const style = new ParagraphStyle("myStyleId").semiHidden();
|
const style = new ParagraphStyle("myStyleId").semiHidden();
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:semiHidden": EMPTY_OBJECT }],
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
|
||||||
{ "w:pPr": [] },
|
|
||||||
{ "w:rPr": [] },
|
|
||||||
{ "w:semiHidden": [] },
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -505,16 +451,12 @@ describe("ParagraphStyle", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:pPr": [] },
|
|
||||||
{ "w:rPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:uiPriority": [
|
"w:uiPriority": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "99",
|
||||||
"w:val": "99",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -524,12 +466,7 @@ describe("ParagraphStyle", () => {
|
|||||||
const style = new ParagraphStyle("myStyleId").unhideWhenUsed();
|
const style = new ParagraphStyle("myStyleId").unhideWhenUsed();
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:unhideWhenUsed": EMPTY_OBJECT }],
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
|
||||||
{ "w:pPr": [] },
|
|
||||||
{ "w:rPr": [] },
|
|
||||||
{ "w:unhideWhenUsed": [] },
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -12,7 +12,7 @@ describe("Style", () => {
|
|||||||
});
|
});
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId", "w:default": true } }],
|
"w:style": { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId", "w:default": true } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ describe("Style", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||||
{ "w:name": [{ _attr: { "w:val": "Style Name" } }] },
|
{ "w:name": { _attr: { "w:val": "Style Name" } } },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -6,6 +6,8 @@ import { CharacterStyle, ParagraphStyle } from "./style";
|
|||||||
|
|
||||||
import { Styles } from "./styles";
|
import { Styles } from "./styles";
|
||||||
|
|
||||||
|
import { EMPTY_OBJECT } from "file/xml-components";
|
||||||
|
|
||||||
describe("Styles", () => {
|
describe("Styles", () => {
|
||||||
let styles: Styles;
|
let styles: Styles;
|
||||||
|
|
||||||
@ -27,7 +29,7 @@ describe("Styles", () => {
|
|||||||
const tree = new Formatter().format(styles)["w:styles"].filter((x) => !x._attr);
|
const tree = new Formatter().format(styles)["w:styles"].filter((x) => !x._attr);
|
||||||
expect(tree).to.deep.equal([
|
expect(tree).to.deep.equal([
|
||||||
{
|
{
|
||||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "pStyleId" } }, { "w:pPr": [] }, { "w:rPr": [] }],
|
"w:style": { _attr: { "w:type": "paragraph", "w:styleId": "pStyleId" } },
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
@ -40,9 +42,7 @@ describe("Styles", () => {
|
|||||||
{
|
{
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "paragraph", "w:styleId": "pStyleId" } },
|
{ _attr: { "w:type": "paragraph", "w:styleId": "pStyleId" } },
|
||||||
{ "w:name": [{ _attr: { "w:val": "Paragraph Style" } }] },
|
{ "w:name": { _attr: { "w:val": "Paragraph Style" } } },
|
||||||
{ "w:pPr": [] },
|
|
||||||
{ "w:rPr": [] },
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@ -58,18 +58,15 @@ describe("Styles", () => {
|
|||||||
{
|
{
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "character", "w:styleId": "pStyleId" } },
|
{ _attr: { "w:type": "character", "w:styleId": "pStyleId" } },
|
||||||
{ "w:rPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:uiPriority": [
|
"w:uiPriority": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "99",
|
||||||
"w:val": "99",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:unhideWhenUsed": [],
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -84,19 +81,16 @@ describe("Styles", () => {
|
|||||||
{
|
{
|
||||||
"w:style": [
|
"w:style": [
|
||||||
{ _attr: { "w:type": "character", "w:styleId": "pStyleId" } },
|
{ _attr: { "w:type": "character", "w:styleId": "pStyleId" } },
|
||||||
{ "w:name": [{ _attr: { "w:val": "Character Style" } }] },
|
{ "w:name": { _attr: { "w:val": "Character Style" } } },
|
||||||
{ "w:rPr": [] },
|
|
||||||
{
|
{
|
||||||
"w:uiPriority": [
|
"w:uiPriority": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "99",
|
||||||
"w:val": "99",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:unhideWhenUsed": [],
|
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -49,13 +49,11 @@ const DEFAULT_TOC = {
|
|||||||
{
|
{
|
||||||
"w:sdtPr": [
|
"w:sdtPr": [
|
||||||
{
|
{
|
||||||
"w:alias": [
|
"w:alias": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "Table of Contents",
|
||||||
"w:val": "Table of Contents",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -63,23 +61,15 @@ const DEFAULT_TOC = {
|
|||||||
"w:sdtContent": [
|
"w:sdtContent": [
|
||||||
{
|
{
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
|
||||||
"w:pPr": [],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"w:r": [
|
"w:r": [
|
||||||
{
|
{
|
||||||
"w:rPr": [],
|
"w:fldChar": {
|
||||||
},
|
_attr: {
|
||||||
{
|
"w:fldCharType": "begin",
|
||||||
"w:fldChar": [
|
"w:dirty": true,
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:fldCharType": "begin",
|
|
||||||
"w:dirty": true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:instrText": [
|
"w:instrText": [
|
||||||
@ -92,13 +82,11 @@ const DEFAULT_TOC = {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:fldChar": [
|
"w:fldChar": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:fldCharType": "separate",
|
||||||
"w:fldCharType": "separate",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -106,22 +94,14 @@ const DEFAULT_TOC = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
|
||||||
"w:pPr": [],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"w:r": [
|
"w:r": [
|
||||||
{
|
{
|
||||||
"w:rPr": [],
|
"w:fldChar": {
|
||||||
},
|
_attr: {
|
||||||
{
|
"w:fldCharType": "end",
|
||||||
"w:fldChar": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:fldCharType": "end",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -137,13 +117,11 @@ const COMPLETE_TOC = {
|
|||||||
{
|
{
|
||||||
"w:sdtPr": [
|
"w:sdtPr": [
|
||||||
{
|
{
|
||||||
"w:alias": [
|
"w:alias": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:val": "Summary",
|
||||||
"w:val": "Summary",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -151,23 +129,15 @@ const COMPLETE_TOC = {
|
|||||||
"w:sdtContent": [
|
"w:sdtContent": [
|
||||||
{
|
{
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
|
||||||
"w:pPr": [],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"w:r": [
|
"w:r": [
|
||||||
{
|
{
|
||||||
"w:rPr": [],
|
"w:fldChar": {
|
||||||
},
|
_attr: {
|
||||||
{
|
"w:fldCharType": "begin",
|
||||||
"w:fldChar": [
|
"w:dirty": true,
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:fldCharType": "begin",
|
|
||||||
"w:dirty": true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:instrText": [
|
"w:instrText": [
|
||||||
@ -180,13 +150,11 @@ const COMPLETE_TOC = {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:fldChar": [
|
"w:fldChar": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:fldCharType": "separate",
|
||||||
"w:fldCharType": "separate",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -194,22 +162,14 @@ const COMPLETE_TOC = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:p": [
|
"w:p": [
|
||||||
{
|
|
||||||
"w:pPr": [],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"w:r": [
|
"w:r": [
|
||||||
{
|
{
|
||||||
"w:rPr": [],
|
"w:fldChar": {
|
||||||
},
|
_attr: {
|
||||||
{
|
"w:fldCharType": "end",
|
||||||
"w:fldChar": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:fldCharType": "end",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -4,20 +4,22 @@ import { Formatter } from "export/formatter";
|
|||||||
|
|
||||||
import { GridCol, TableGrid } from "./grid";
|
import { GridCol, TableGrid } from "./grid";
|
||||||
|
|
||||||
|
import { EMPTY_OBJECT } from "file/xml-components";
|
||||||
|
|
||||||
describe("GridCol", () => {
|
describe("GridCol", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
it("sets the width attribute to the value given", () => {
|
it("sets the width attribute to the value given", () => {
|
||||||
const grid = new GridCol(1234);
|
const grid = new GridCol(1234);
|
||||||
const tree = new Formatter().format(grid);
|
const tree = new Formatter().format(grid);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:gridCol": [{ _attr: { "w:w": 1234 } }],
|
"w:gridCol": { _attr: { "w:w": 1234 } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not set a width attribute if not given", () => {
|
it("does not set a width attribute if not given", () => {
|
||||||
const grid = new GridCol();
|
const grid = new GridCol();
|
||||||
const tree = new Formatter().format(grid);
|
const tree = new Formatter().format(grid);
|
||||||
expect(tree).to.deep.equal({ "w:gridCol": [] });
|
expect(tree).to.deep.equal({ "w:gridCol": EMPTY_OBJECT });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -29,9 +31,9 @@ describe("TableGrid", () => {
|
|||||||
const tree = new Formatter().format(grid);
|
const tree = new Formatter().format(grid);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tblGrid": [
|
"w:tblGrid": [
|
||||||
{ "w:gridCol": [{ _attr: { "w:w": 1234 } }] },
|
{ "w:gridCol": { _attr: { "w:w": 1234 } } },
|
||||||
{ "w:gridCol": [{ _attr: { "w:w": 321 } }] },
|
{ "w:gridCol": { _attr: { "w:w": 321 } } },
|
||||||
{ "w:gridCol": [{ _attr: { "w:w": 123 } }] },
|
{ "w:gridCol": { _attr: { "w:w": 123 } } },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -2,3 +2,4 @@ export * from "./table";
|
|||||||
export * from "./table-cell";
|
export * from "./table-cell";
|
||||||
export * from "./table-properties";
|
export * from "./table-properties";
|
||||||
export * from "./shading";
|
export * from "./shading";
|
||||||
|
export * from "./table-row";
|
||||||
|
@ -7,30 +7,26 @@ import { ShadingType, TableShading } from "./shading";
|
|||||||
describe("TableShading", () => {
|
describe("TableShading", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
it("should create", () => {
|
it("should create", () => {
|
||||||
const cellMargain = new TableShading({});
|
const shading = new TableShading({});
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(shading);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:shd": [
|
"w:shd": {
|
||||||
{
|
_attr: {},
|
||||||
_attr: {},
|
},
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create with params", () => {
|
it("should create with params", () => {
|
||||||
const cellMargain = new TableShading({ val: ShadingType.PERCENT_40, color: "FF0000", fill: "555555" });
|
const shading = new TableShading({ val: ShadingType.PERCENT_40, color: "FF0000", fill: "555555" });
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(shading);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:shd": [
|
"w:shd": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:color": "FF0000",
|
||||||
"w:color": "FF0000",
|
"w:fill": "555555",
|
||||||
"w:fill": "555555",
|
"w:val": "pct40",
|
||||||
"w:val": "pct40",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,81 +0,0 @@
|
|||||||
import { expect } from "chai";
|
|
||||||
|
|
||||||
import { Formatter } from "export/formatter";
|
|
||||||
|
|
||||||
import { BottomCellMargain, LeftCellMargain, RightCellMargain, TopCellMargain } from "./cell-margain";
|
|
||||||
|
|
||||||
describe("TopCellMargain", () => {
|
|
||||||
describe("#constructor", () => {
|
|
||||||
it("should create", () => {
|
|
||||||
const cellMargain = new TopCellMargain(1);
|
|
||||||
const tree = new Formatter().format(cellMargain);
|
|
||||||
expect(tree).to.deep.equal({
|
|
||||||
"w:top": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:type": "dxa",
|
|
||||||
"w:w": 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("BottomCellMargain", () => {
|
|
||||||
describe("#constructor", () => {
|
|
||||||
it("should create", () => {
|
|
||||||
const cellMargain = new BottomCellMargain(1);
|
|
||||||
const tree = new Formatter().format(cellMargain);
|
|
||||||
expect(tree).to.deep.equal({
|
|
||||||
"w:bottom": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:type": "dxa",
|
|
||||||
"w:w": 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("LeftCellMargain", () => {
|
|
||||||
describe("#constructor", () => {
|
|
||||||
it("should create", () => {
|
|
||||||
const cellMargain = new LeftCellMargain(1);
|
|
||||||
const tree = new Formatter().format(cellMargain);
|
|
||||||
expect(tree).to.deep.equal({
|
|
||||||
"w:start": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:type": "dxa",
|
|
||||||
"w:w": 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("RightCellMargain", () => {
|
|
||||||
describe("#constructor", () => {
|
|
||||||
it("should create", () => {
|
|
||||||
const cellMargain = new RightCellMargain(1);
|
|
||||||
const tree = new Formatter().format(cellMargain);
|
|
||||||
expect(tree).to.deep.equal({
|
|
||||||
"w:end": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:type": "dxa",
|
|
||||||
"w:w": 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,112 +0,0 @@
|
|||||||
import { expect } from "chai";
|
|
||||||
|
|
||||||
import { Formatter } from "export/formatter";
|
|
||||||
|
|
||||||
import { TableCellMargain } from "./table-cell-margains";
|
|
||||||
|
|
||||||
describe("TableCellMargain", () => {
|
|
||||||
describe("#constructor", () => {
|
|
||||||
it("should create with default values", () => {
|
|
||||||
const cellMargain = new TableCellMargain({});
|
|
||||||
const tree = new Formatter().format(cellMargain);
|
|
||||||
expect(tree).to.deep.equal({
|
|
||||||
"w:tcMar": [
|
|
||||||
{
|
|
||||||
"w:top": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:type": "dxa",
|
|
||||||
"w:w": 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"w:bottom": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:type": "dxa",
|
|
||||||
"w:w": 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"w:end": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:type": "dxa",
|
|
||||||
"w:w": 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"w:start": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:type": "dxa",
|
|
||||||
"w:w": 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should create with values", () => {
|
|
||||||
const cellMargain = new TableCellMargain({
|
|
||||||
top: 5,
|
|
||||||
bottom: 5,
|
|
||||||
left: 5,
|
|
||||||
right: 5,
|
|
||||||
});
|
|
||||||
const tree = new Formatter().format(cellMargain);
|
|
||||||
expect(tree).to.deep.equal({
|
|
||||||
"w:tcMar": [
|
|
||||||
{
|
|
||||||
"w:top": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:type": "dxa",
|
|
||||||
"w:w": 5,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"w:bottom": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:type": "dxa",
|
|
||||||
"w:w": 5,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"w:end": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:type": "dxa",
|
|
||||||
"w:w": 5,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"w:start": [
|
|
||||||
{
|
|
||||||
_attr: {
|
|
||||||
"w:type": "dxa",
|
|
||||||
"w:w": 5,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,21 +0,0 @@
|
|||||||
// http://officeopenxml.com/WPtableCellProperties-Margins.php
|
|
||||||
import { XmlComponent } from "file/xml-components";
|
|
||||||
|
|
||||||
import { BottomCellMargain, LeftCellMargain, RightCellMargain, TopCellMargain } from "./cell-margain";
|
|
||||||
|
|
||||||
export interface ITableCellMargainOptions {
|
|
||||||
readonly top?: number;
|
|
||||||
readonly left?: number;
|
|
||||||
readonly bottom?: number;
|
|
||||||
readonly right?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TableCellMargain extends XmlComponent {
|
|
||||||
constructor({ top = 0, left = 0, right = 0, bottom = 0 }: ITableCellMargainOptions) {
|
|
||||||
super("w:tcMar");
|
|
||||||
this.root.push(new TopCellMargain(top));
|
|
||||||
this.root.push(new BottomCellMargain(bottom));
|
|
||||||
this.root.push(new RightCellMargain(right));
|
|
||||||
this.root.push(new LeftCellMargain(left));
|
|
||||||
}
|
|
||||||
}
|
|
73
src/file/table/table-cell/cell-margin/cell-margin.spec.ts
Normal file
73
src/file/table/table-cell/cell-margin/cell-margin.spec.ts
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
|
import { BottomCellMargin, LeftCellMargin, RightCellMargin, TopCellMargin } from "./cell-margin";
|
||||||
|
|
||||||
|
describe("TopCellMargin", () => {
|
||||||
|
describe("#constructor", () => {
|
||||||
|
it("should create", () => {
|
||||||
|
const cellMargin = new TopCellMargin(1);
|
||||||
|
const tree = new Formatter().format(cellMargin);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:top": {
|
||||||
|
_attr: {
|
||||||
|
"w:type": "dxa",
|
||||||
|
"w:w": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("BottomCellMargin", () => {
|
||||||
|
describe("#constructor", () => {
|
||||||
|
it("should create", () => {
|
||||||
|
const cellMargin = new BottomCellMargin(1);
|
||||||
|
const tree = new Formatter().format(cellMargin);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:bottom": {
|
||||||
|
_attr: {
|
||||||
|
"w:type": "dxa",
|
||||||
|
"w:w": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("LeftCellMargin", () => {
|
||||||
|
describe("#constructor", () => {
|
||||||
|
it("should create", () => {
|
||||||
|
const cellMargin = new LeftCellMargin(1);
|
||||||
|
const tree = new Formatter().format(cellMargin);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:start": {
|
||||||
|
_attr: {
|
||||||
|
"w:type": "dxa",
|
||||||
|
"w:w": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("RightCellMargin", () => {
|
||||||
|
describe("#constructor", () => {
|
||||||
|
it("should create", () => {
|
||||||
|
const cellMargin = new RightCellMargin(1);
|
||||||
|
const tree = new Formatter().format(cellMargin);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:end": {
|
||||||
|
_attr: {
|
||||||
|
"w:type": "dxa",
|
||||||
|
"w:w": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -1,21 +1,21 @@
|
|||||||
// http://officeopenxml.com/WPtableCellProperties-Margins.php
|
// http://officeopenxml.com/WPtableCellProperties-Margins.php
|
||||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
export interface ICellMargainProperties {
|
export interface ICellMarginProperties {
|
||||||
readonly type: string;
|
readonly type: string;
|
||||||
readonly width: number;
|
readonly width: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
class CellMargainAttributes extends XmlAttributeComponent<ICellMargainProperties> {
|
class CellMarginAttributes extends XmlAttributeComponent<ICellMarginProperties> {
|
||||||
protected readonly xmlKeys = { width: "w:w", type: "w:type" };
|
protected readonly xmlKeys = { width: "w:w", type: "w:type" };
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TopCellMargain extends XmlComponent {
|
export class TopCellMargin extends XmlComponent {
|
||||||
constructor(value: number) {
|
constructor(value: number) {
|
||||||
super("w:top");
|
super("w:top");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new CellMargainAttributes({
|
new CellMarginAttributes({
|
||||||
width: value,
|
width: value,
|
||||||
type: "dxa",
|
type: "dxa",
|
||||||
}),
|
}),
|
||||||
@ -23,12 +23,12 @@ export class TopCellMargain extends XmlComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BottomCellMargain extends XmlComponent {
|
export class BottomCellMargin extends XmlComponent {
|
||||||
constructor(value: number) {
|
constructor(value: number) {
|
||||||
super("w:bottom");
|
super("w:bottom");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new CellMargainAttributes({
|
new CellMarginAttributes({
|
||||||
width: value,
|
width: value,
|
||||||
type: "dxa",
|
type: "dxa",
|
||||||
}),
|
}),
|
||||||
@ -36,12 +36,12 @@ export class BottomCellMargain extends XmlComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class LeftCellMargain extends XmlComponent {
|
export class LeftCellMargin extends XmlComponent {
|
||||||
constructor(value: number) {
|
constructor(value: number) {
|
||||||
super("w:start");
|
super("w:start");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new CellMargainAttributes({
|
new CellMarginAttributes({
|
||||||
width: value,
|
width: value,
|
||||||
type: "dxa",
|
type: "dxa",
|
||||||
}),
|
}),
|
||||||
@ -49,12 +49,12 @@ export class LeftCellMargain extends XmlComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class RightCellMargain extends XmlComponent {
|
export class RightCellMargin extends XmlComponent {
|
||||||
constructor(value: number) {
|
constructor(value: number) {
|
||||||
super("w:end");
|
super("w:end");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new CellMargainAttributes({
|
new CellMarginAttributes({
|
||||||
width: value,
|
width: value,
|
||||||
type: "dxa",
|
type: "dxa",
|
||||||
}),
|
}),
|
@ -0,0 +1,96 @@
|
|||||||
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
|
import { TableCellMargin } from "./table-cell-margins";
|
||||||
|
|
||||||
|
describe("TableCellMargin", () => {
|
||||||
|
describe("#constructor", () => {
|
||||||
|
it("should create with default values", () => {
|
||||||
|
const cellMargin = new TableCellMargin({});
|
||||||
|
const tree = new Formatter().format(cellMargin);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:tcMar": [
|
||||||
|
{
|
||||||
|
"w:top": {
|
||||||
|
_attr: {
|
||||||
|
"w:type": "dxa",
|
||||||
|
"w:w": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:bottom": {
|
||||||
|
_attr: {
|
||||||
|
"w:type": "dxa",
|
||||||
|
"w:w": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:end": {
|
||||||
|
_attr: {
|
||||||
|
"w:type": "dxa",
|
||||||
|
"w:w": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:start": {
|
||||||
|
_attr: {
|
||||||
|
"w:type": "dxa",
|
||||||
|
"w:w": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should create with values", () => {
|
||||||
|
const cellMargin = new TableCellMargin({
|
||||||
|
top: 5,
|
||||||
|
bottom: 5,
|
||||||
|
left: 5,
|
||||||
|
right: 5,
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(cellMargin);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:tcMar": [
|
||||||
|
{
|
||||||
|
"w:top": {
|
||||||
|
_attr: {
|
||||||
|
"w:type": "dxa",
|
||||||
|
"w:w": 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:bottom": {
|
||||||
|
_attr: {
|
||||||
|
"w:type": "dxa",
|
||||||
|
"w:w": 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:end": {
|
||||||
|
_attr: {
|
||||||
|
"w:type": "dxa",
|
||||||
|
"w:w": 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:start": {
|
||||||
|
_attr: {
|
||||||
|
"w:type": "dxa",
|
||||||
|
"w:w": 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
21
src/file/table/table-cell/cell-margin/table-cell-margins.ts
Normal file
21
src/file/table/table-cell/cell-margin/table-cell-margins.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// http://officeopenxml.com/WPtableCellProperties-Margins.php
|
||||||
|
import { XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
|
import { BottomCellMargin, LeftCellMargin, RightCellMargin, TopCellMargin } from "./cell-margin";
|
||||||
|
|
||||||
|
export interface ITableCellMarginOptions {
|
||||||
|
readonly top?: number;
|
||||||
|
readonly left?: number;
|
||||||
|
readonly bottom?: number;
|
||||||
|
readonly right?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TableCellMargin extends XmlComponent {
|
||||||
|
constructor({ top = 0, left = 0, right = 0, bottom = 0 }: ITableCellMarginOptions) {
|
||||||
|
super("w:tcMar");
|
||||||
|
this.root.push(new TopCellMargin(top));
|
||||||
|
this.root.push(new BottomCellMargin(bottom));
|
||||||
|
this.root.push(new RightCellMargin(right));
|
||||||
|
this.root.push(new LeftCellMargin(left));
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
import { BorderStyle } from "file/styles";
|
import { BorderStyle } from "file/styles";
|
||||||
import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
interface ICellBorder {
|
interface ICellBorder {
|
||||||
readonly style: BorderStyle;
|
readonly style: BorderStyle;
|
||||||
@ -24,17 +24,11 @@ class BaseTableCellBorder extends XmlComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TableCellBorders extends XmlComponent {
|
export class TableCellBorders extends IgnoreIfEmptyXmlComponent {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("w:tcBorders");
|
super("w:tcBorders");
|
||||||
}
|
}
|
||||||
|
|
||||||
public prepForXml(): IXmlableObject | undefined {
|
|
||||||
if (this.root.length > 0) {
|
|
||||||
return super.prepForXml();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public addTopBorder(style: BorderStyle, size: number, color: string): TableCellBorders {
|
public addTopBorder(style: BorderStyle, size: number, color: string): TableCellBorders {
|
||||||
const top = new BaseTableCellBorder("w:top");
|
const top = new BaseTableCellBorder("w:top");
|
||||||
top.setProperties(style, size, color);
|
top.setProperties(style, size, color);
|
||||||
|
@ -9,77 +9,80 @@ import { TableCellProperties } from "./table-cell-properties";
|
|||||||
describe("TableCellProperties", () => {
|
describe("TableCellProperties", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
it("creates an initially empty property object", () => {
|
it("creates an initially empty property object", () => {
|
||||||
const cellMargain = new TableCellProperties();
|
const properties = new TableCellProperties();
|
||||||
const tree = new Formatter().format(cellMargain);
|
// The TableCellProperties is ignorable if there are no attributes,
|
||||||
expect(tree).to.deep.equal({ "w:tcPr": [] });
|
// which results in prepForXml returning undefined, which causes
|
||||||
|
// the formatter to throw an error if that is the only object it
|
||||||
|
// has been asked to format.
|
||||||
|
expect(() => new Formatter().format(properties)).to.throw("XMLComponent did not format correctly");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#addGridSpan", () => {
|
describe("#addGridSpan", () => {
|
||||||
it("adds grid span", () => {
|
it("adds grid span", () => {
|
||||||
const cellMargain = new TableCellProperties();
|
const properties = new TableCellProperties();
|
||||||
cellMargain.addGridSpan(1);
|
properties.addGridSpan(1);
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(properties);
|
||||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:gridSpan": [{ _attr: { "w:val": 1 } }] }] });
|
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:gridSpan": { _attr: { "w:val": 1 } } }] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#addVerticalMerge", () => {
|
describe("#addVerticalMerge", () => {
|
||||||
it("adds vertical merge", () => {
|
it("adds vertical merge", () => {
|
||||||
const cellMargain = new TableCellProperties();
|
const properties = new TableCellProperties();
|
||||||
cellMargain.addVerticalMerge(VMergeType.CONTINUE);
|
properties.addVerticalMerge(VMergeType.CONTINUE);
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(properties);
|
||||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:vMerge": [{ _attr: { "w:val": "continue" } }] }] });
|
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "continue" } } }] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#setVerticalAlign", () => {
|
describe("#setVerticalAlign", () => {
|
||||||
it("sets vertical align", () => {
|
it("sets vertical align", () => {
|
||||||
const cellMargain = new TableCellProperties();
|
const properties = new TableCellProperties();
|
||||||
cellMargain.setVerticalAlign(VerticalAlign.BOTTOM);
|
properties.setVerticalAlign(VerticalAlign.BOTTOM);
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(properties);
|
||||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:vAlign": [{ _attr: { "w:val": "bottom" } }] }] });
|
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:vAlign": { _attr: { "w:val": "bottom" } } }] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#setWidth", () => {
|
describe("#setWidth", () => {
|
||||||
it("should set width", () => {
|
it("should set width", () => {
|
||||||
const cellMargain = new TableCellProperties();
|
const properties = new TableCellProperties();
|
||||||
cellMargain.setWidth(1, WidthType.DXA);
|
properties.setWidth(1, WidthType.DXA);
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(properties);
|
||||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:tcW": [{ _attr: { "w:type": "dxa", "w:w": 1 } }] }] });
|
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:tcW": { _attr: { "w:type": "dxa", "w:w": 1 } } }] });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should set width using default of AUTO", () => {
|
it("should set width using default of AUTO", () => {
|
||||||
const cellMargain = new TableCellProperties();
|
const properties = new TableCellProperties();
|
||||||
cellMargain.setWidth(1);
|
properties.setWidth(1);
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(properties);
|
||||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:tcW": [{ _attr: { "w:type": "auto", "w:w": 1 } }] }] });
|
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:tcW": { _attr: { "w:type": "auto", "w:w": 1 } } }] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#setShading", () => {
|
describe("#setShading", () => {
|
||||||
it("sets shading", () => {
|
it("sets shading", () => {
|
||||||
const cellMargain = new TableCellProperties();
|
const properties = new TableCellProperties();
|
||||||
cellMargain.setShading({
|
properties.setShading({
|
||||||
fill: "test",
|
fill: "test",
|
||||||
color: "000",
|
color: "000",
|
||||||
});
|
});
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(properties);
|
||||||
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:shd": [{ _attr: { "w:fill": "test", "w:color": "000" } }] }] });
|
expect(tree).to.deep.equal({ "w:tcPr": [{ "w:shd": { _attr: { "w:fill": "test", "w:color": "000" } } }] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#Borders", () => {
|
describe("#Borders", () => {
|
||||||
it("should return the TableCellBorders if Border has borders", () => {
|
it("should return the TableCellBorders if Border has borders", () => {
|
||||||
const cellMargain = new TableCellProperties();
|
const properties = new TableCellProperties();
|
||||||
cellMargain.Borders.addTopBorder(BorderStyle.DASH_DOT_STROKED, 3, "red");
|
properties.Borders.addTopBorder(BorderStyle.DASH_DOT_STROKED, 3, "red");
|
||||||
const borders = cellMargain.Borders;
|
const borders = properties.Borders;
|
||||||
|
|
||||||
const tree = new Formatter().format(borders);
|
const tree = new Formatter().format(borders);
|
||||||
|
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tcBorders": [{ "w:top": [{ _attr: { "w:val": "dashDotStroked", "w:sz": 3, "w:color": "red" } }] }],
|
"w:tcBorders": [{ "w:top": { _attr: { "w:val": "dashDotStroked", "w:sz": 3, "w:color": "red" } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { XmlComponent } from "file/xml-components";
|
import { IgnoreIfEmptyXmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
import { ITableShadingAttributesProperties, TableShading } from "../shading";
|
import { ITableShadingAttributesProperties, TableShading } from "../shading";
|
||||||
import { ITableCellMargainOptions, TableCellMargain } from "./cell-margain/table-cell-margains";
|
import { ITableCellMarginOptions, TableCellMargin } from "./cell-margin/table-cell-margins";
|
||||||
import { GridSpan, TableCellBorders, TableCellWidth, VAlign, VerticalAlign, VMerge, VMergeType, WidthType } from "./table-cell-components";
|
import { GridSpan, TableCellBorders, TableCellWidth, VAlign, VerticalAlign, VMerge, VMergeType, WidthType } from "./table-cell-components";
|
||||||
|
|
||||||
export class TableCellProperties extends XmlComponent {
|
export class TableCellProperties extends IgnoreIfEmptyXmlComponent {
|
||||||
private readonly cellBorder: TableCellBorders;
|
private readonly cellBorder: TableCellBorders;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -47,8 +47,8 @@ export class TableCellProperties extends XmlComponent {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public addMargains(options: ITableCellMargainOptions): TableCellProperties {
|
public addMargins(options: ITableCellMarginOptions): TableCellProperties {
|
||||||
this.root.push(new TableCellMargain(options));
|
this.root.push(new TableCellMargin(options));
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -22,15 +22,13 @@ describe("TableCellBorders", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tcBorders": [
|
"w:tcBorders": [
|
||||||
{
|
{
|
||||||
"w:top": [
|
"w:top": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:color": "FF00FF",
|
||||||
"w:color": "FF00FF",
|
"w:sz": 1,
|
||||||
"w:sz": 1,
|
"w:val": "dotted",
|
||||||
"w:val": "dotted",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -44,15 +42,13 @@ describe("TableCellBorders", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tcBorders": [
|
"w:tcBorders": [
|
||||||
{
|
{
|
||||||
"w:start": [
|
"w:start": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:color": "FF00FF",
|
||||||
"w:color": "FF00FF",
|
"w:sz": 2,
|
||||||
"w:sz": 2,
|
"w:val": "single",
|
||||||
"w:val": "single",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -66,15 +62,13 @@ describe("TableCellBorders", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tcBorders": [
|
"w:tcBorders": [
|
||||||
{
|
{
|
||||||
"w:bottom": [
|
"w:bottom": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:color": "FF00FF",
|
||||||
"w:color": "FF00FF",
|
"w:sz": 1,
|
||||||
"w:sz": 1,
|
"w:val": "double",
|
||||||
"w:val": "double",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -88,15 +82,13 @@ describe("TableCellBorders", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tcBorders": [
|
"w:tcBorders": [
|
||||||
{
|
{
|
||||||
"w:end": [
|
"w:end": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:color": "FF00FF",
|
||||||
"w:color": "FF00FF",
|
"w:sz": 3,
|
||||||
"w:sz": 3,
|
"w:val": "thick",
|
||||||
"w:val": "thick",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -110,15 +102,13 @@ describe("TableCellBorders", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tcBorders": [
|
"w:tcBorders": [
|
||||||
{
|
{
|
||||||
"w:left": [
|
"w:left": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:color": "FF00FF",
|
||||||
"w:color": "FF00FF",
|
"w:sz": 3,
|
||||||
"w:sz": 3,
|
"w:val": "thick",
|
||||||
"w:val": "thick",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -132,15 +122,13 @@ describe("TableCellBorders", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tcBorders": [
|
"w:tcBorders": [
|
||||||
{
|
{
|
||||||
"w:right": [
|
"w:right": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:color": "FF00FF",
|
||||||
"w:color": "FF00FF",
|
"w:sz": 3,
|
||||||
"w:sz": 3,
|
"w:val": "thick",
|
||||||
"w:val": "thick",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -159,70 +147,58 @@ describe("TableCellBorders", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tcBorders": [
|
"w:tcBorders": [
|
||||||
{
|
{
|
||||||
"w:top": [
|
"w:top": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:color": "FF00FF",
|
||||||
"w:color": "FF00FF",
|
"w:sz": 1,
|
||||||
"w:sz": 1,
|
"w:val": "dotted",
|
||||||
"w:val": "dotted",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:end": [
|
"w:end": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:color": "FF00FF",
|
||||||
"w:color": "FF00FF",
|
"w:sz": 3,
|
||||||
"w:sz": 3,
|
"w:val": "thick",
|
||||||
"w:val": "thick",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:bottom": [
|
"w:bottom": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:color": "FF00FF",
|
||||||
"w:color": "FF00FF",
|
"w:sz": 1,
|
||||||
"w:sz": 1,
|
"w:val": "double",
|
||||||
"w:val": "double",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:start": [
|
"w:start": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:color": "FF00FF",
|
||||||
"w:color": "FF00FF",
|
"w:sz": 2,
|
||||||
"w:sz": 2,
|
"w:val": "single",
|
||||||
"w:val": "single",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:left": [
|
"w:left": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:color": "FF00FF",
|
||||||
"w:color": "FF00FF",
|
"w:sz": 2,
|
||||||
"w:sz": 2,
|
"w:val": "single",
|
||||||
"w:val": "single",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"w:right": [
|
"w:right": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:color": "FF00FF",
|
||||||
"w:color": "FF00FF",
|
"w:sz": 2,
|
||||||
"w:sz": 2,
|
"w:val": "single",
|
||||||
"w:val": "single",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -236,14 +212,12 @@ describe("TableCellWidth", () => {
|
|||||||
const tcWidth = new TableCellWidth(100, WidthType.DXA);
|
const tcWidth = new TableCellWidth(100, WidthType.DXA);
|
||||||
const tree = new Formatter().format(tcWidth);
|
const tree = new Formatter().format(tcWidth);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tcW": [
|
"w:tcW": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:type": "dxa",
|
||||||
"w:type": "dxa",
|
"w:w": 100,
|
||||||
"w:w": 100,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -4,7 +4,7 @@ import { IXmlableObject, XmlComponent } from "file/xml-components";
|
|||||||
|
|
||||||
import { ITableShadingAttributesProperties } from "../shading";
|
import { ITableShadingAttributesProperties } from "../shading";
|
||||||
import { Table } from "../table";
|
import { Table } from "../table";
|
||||||
import { ITableCellMargainOptions } from "./cell-margain/table-cell-margains";
|
import { ITableCellMarginOptions } from "./cell-margin/table-cell-margins";
|
||||||
import { TableCellBorders, VerticalAlign, VMergeType } from "./table-cell-components";
|
import { TableCellBorders, VerticalAlign, VMergeType } from "./table-cell-components";
|
||||||
import { TableCellProperties } from "./table-cell-properties";
|
import { TableCellProperties } from "./table-cell-properties";
|
||||||
|
|
||||||
@ -30,16 +30,10 @@ export class TableCell extends XmlComponent {
|
|||||||
|
|
||||||
public prepForXml(): IXmlableObject | undefined {
|
public prepForXml(): IXmlableObject | undefined {
|
||||||
// Cells must end with a paragraph
|
// Cells must end with a paragraph
|
||||||
const retval = super.prepForXml();
|
if (!(this.root[this.root.length - 1] instanceof Paragraph)) {
|
||||||
if (!retval) {
|
this.createParagraph();
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
return super.prepForXml();
|
||||||
const content = retval["w:tc"];
|
|
||||||
if (!content[content.length - 1]["w:p"]) {
|
|
||||||
content.push(new Paragraph().prepForXml());
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public createParagraph(text?: string): Paragraph {
|
public createParagraph(text?: string): Paragraph {
|
||||||
@ -67,8 +61,8 @@ export class TableCell extends XmlComponent {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public setMargains(margains: ITableCellMargainOptions): TableCell {
|
public setMargins(margins: ITableCellMarginOptions): TableCell {
|
||||||
this.properties.addMargains(margains);
|
this.properties.addMargins(margins);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ import { Formatter } from "export/formatter";
|
|||||||
import { TableCell } from "./table-cell";
|
import { TableCell } from "./table-cell";
|
||||||
import { TableColumn } from "./table-column";
|
import { TableColumn } from "./table-column";
|
||||||
|
|
||||||
|
import { EMPTY_OBJECT } from "file/xml-components";
|
||||||
|
|
||||||
describe("TableColumn", () => {
|
describe("TableColumn", () => {
|
||||||
let cells: TableCell[];
|
let cells: TableCell[];
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@ -37,15 +39,17 @@ describe("TableColumn", () => {
|
|||||||
|
|
||||||
const tree = new Formatter().format(cells[0]);
|
const tree = new Formatter().format(cells[0]);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tc": [{ "w:tcPr": [{ "w:vMerge": [{ _attr: { "w:val": "restart" } }] }] }, { "w:p": [{ "w:pPr": [] }] }],
|
"w:tc": [{ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "restart" } } }] }, { "w:p": EMPTY_OBJECT }],
|
||||||
});
|
});
|
||||||
|
|
||||||
const tree2 = new Formatter().format(cells[1]);
|
const tree2 = new Formatter().format(cells[1]);
|
||||||
expect(tree2).to.deep.equal({ "w:tc": [{ "w:tcPr": [] }, { "w:p": [{ "w:pPr": [] }] }] });
|
expect(tree2).to.deep.equal({
|
||||||
|
"w:tc": [{ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "continue" } } }] }, { "w:p": EMPTY_OBJECT }],
|
||||||
|
});
|
||||||
|
|
||||||
const tree3 = new Formatter().format(cells[2]);
|
const tree3 = new Formatter().format(cells[2]);
|
||||||
expect(tree3).to.deep.equal({
|
expect(tree3).to.deep.equal({
|
||||||
"w:tc": [{ "w:tcPr": [{ "w:vMerge": [{ _attr: { "w:val": "continue" } }] }] }, { "w:p": [{ "w:pPr": [] }] }],
|
"w:tc": [{ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "continue" } } }] }, { "w:p": EMPTY_OBJECT }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -15,7 +15,10 @@ export class TableColumn {
|
|||||||
|
|
||||||
public mergeCells(startIndex: number, endIndex: number): TableCell {
|
public mergeCells(startIndex: number, endIndex: number): TableCell {
|
||||||
this.cells[startIndex].addVerticalMerge(VMergeType.RESTART);
|
this.cells[startIndex].addVerticalMerge(VMergeType.RESTART);
|
||||||
this.cells[endIndex].addVerticalMerge(VMergeType.CONTINUE);
|
|
||||||
|
for (let i = startIndex + 1; i <= endIndex; i++) {
|
||||||
|
this.cells[i].addVerticalMerge(VMergeType.CONTINUE);
|
||||||
|
}
|
||||||
|
|
||||||
return this.cells[startIndex];
|
return this.cells[startIndex];
|
||||||
}
|
}
|
||||||
|
@ -8,44 +8,44 @@ import { TableCellMargin } from "./table-cell-margin";
|
|||||||
describe("TableCellMargin", () => {
|
describe("TableCellMargin", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
it("should throw an error if theres no child elements", () => {
|
it("should throw an error if theres no child elements", () => {
|
||||||
const cellMargain = new TableCellMargin();
|
const cellMargin = new TableCellMargin();
|
||||||
expect(() => new Formatter().format(cellMargain)).to.throw();
|
expect(() => new Formatter().format(cellMargin)).to.throw();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#addTopMargin", () => {
|
describe("#addTopMargin", () => {
|
||||||
it("adds a table cell top margin", () => {
|
it("adds a table cell top margin", () => {
|
||||||
const cellMargain = new TableCellMargin();
|
const cellMargin = new TableCellMargin();
|
||||||
cellMargain.addTopMargin(1234, WidthType.DXA);
|
cellMargin.addTopMargin(1234, WidthType.DXA);
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(cellMargin);
|
||||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:top": [{ _attr: { "w:sz": "dxa", "w:w": 1234 } }] }] });
|
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:top": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#addLeftMargin", () => {
|
describe("#addLeftMargin", () => {
|
||||||
it("adds a table cell left margin", () => {
|
it("adds a table cell left margin", () => {
|
||||||
const cellMargain = new TableCellMargin();
|
const cellMargin = new TableCellMargin();
|
||||||
cellMargain.addLeftMargin(1234, WidthType.DXA);
|
cellMargin.addLeftMargin(1234, WidthType.DXA);
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(cellMargin);
|
||||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:left": [{ _attr: { "w:sz": "dxa", "w:w": 1234 } }] }] });
|
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:left": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#addBottomMargin", () => {
|
describe("#addBottomMargin", () => {
|
||||||
it("adds a table cell bottom margin", () => {
|
it("adds a table cell bottom margin", () => {
|
||||||
const cellMargain = new TableCellMargin();
|
const cellMargin = new TableCellMargin();
|
||||||
cellMargain.addBottomMargin(1234, WidthType.DXA);
|
cellMargin.addBottomMargin(1234, WidthType.DXA);
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(cellMargin);
|
||||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:bottom": [{ _attr: { "w:sz": "dxa", "w:w": 1234 } }] }] });
|
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:bottom": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#addRightMargin", () => {
|
describe("#addRightMargin", () => {
|
||||||
it("adds a table cell right margin", () => {
|
it("adds a table cell right margin", () => {
|
||||||
const cellMargain = new TableCellMargin();
|
const cellMargin = new TableCellMargin();
|
||||||
cellMargain.addRightMargin(1234, WidthType.DXA);
|
cellMargin.addRightMargin(1234, WidthType.DXA);
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(cellMargin);
|
||||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:right": [{ _attr: { "w:sz": "dxa", "w:w": 1234 } }] }] });
|
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:right": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
import { WidthType } from "../table-cell";
|
import { WidthType } from "../table-cell";
|
||||||
|
|
||||||
class TableCellMarginAttributes extends XmlAttributeComponent<{ readonly type: WidthType; readonly value: number }> {
|
class TableCellMarginAttributes extends XmlAttributeComponent<{ readonly type: WidthType; readonly value: number }> {
|
||||||
protected readonly xmlKeys = { value: "w:w", type: "w:sz" };
|
protected readonly xmlKeys = { value: "w:w", type: "w:type" };
|
||||||
}
|
}
|
||||||
|
|
||||||
class BaseTableCellMargin extends XmlComponent {
|
class BaseTableCellMargin extends XmlComponent {
|
||||||
@ -17,17 +17,11 @@ class BaseTableCellMargin extends XmlComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TableCellMargin extends XmlComponent {
|
export class TableCellMargin extends IgnoreIfEmptyXmlComponent {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("w:tblCellMar");
|
super("w:tblCellMar");
|
||||||
}
|
}
|
||||||
|
|
||||||
public prepForXml(): IXmlableObject | undefined {
|
|
||||||
if (this.root.length > 0) {
|
|
||||||
return super.prepForXml();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public addTopMargin(value: number, type: WidthType = WidthType.DXA): void {
|
public addTopMargin(value: number, type: WidthType = WidthType.DXA): void {
|
||||||
const top = new BaseTableCellMargin("w:top");
|
const top = new BaseTableCellMargin("w:top");
|
||||||
|
|
||||||
|
@ -26,20 +26,18 @@ describe("Table Float Properties", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const DEFAULT_TFP = {
|
const DEFAULT_TFP = {
|
||||||
"w:tblpPr": [
|
"w:tblpPr": {
|
||||||
{
|
_attr: {
|
||||||
_attr: {
|
"w:horzAnchor": "margin",
|
||||||
"w:horzAnchor": "margin",
|
"w:vertAnchor": "page",
|
||||||
"w:vertAnchor": "page",
|
"w:tblpX": 10,
|
||||||
"w:tblpX": 10,
|
"w:tblpXSpec": "center",
|
||||||
"w:tblpXSpec": "center",
|
"w:tblpY": 20,
|
||||||
"w:tblpY": 20,
|
"w:tblpYSpec": "bottom",
|
||||||
"w:tblpYSpec": "bottom",
|
"w:bottomFromText": 30,
|
||||||
"w:bottomFromText": 30,
|
"w:topFromText": 40,
|
||||||
"w:topFromText": 40,
|
"w:leftFromText": 50,
|
||||||
"w:leftFromText": 50,
|
"w:rightFromText": 60,
|
||||||
"w:rightFromText": 60,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
};
|
};
|
||||||
|
@ -9,8 +9,11 @@ describe("TableProperties", () => {
|
|||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
it("creates an initially empty property object", () => {
|
it("creates an initially empty property object", () => {
|
||||||
const tp = new TableProperties();
|
const tp = new TableProperties();
|
||||||
const tree = new Formatter().format(tp);
|
// The TableProperties is ignorable if there are no attributes,
|
||||||
expect(tree).to.deep.equal({ "w:tblPr": [] });
|
// which results in prepForXml returning undefined, which causes
|
||||||
|
// the formatter to throw an error if that is the only object it
|
||||||
|
// has been asked to format.
|
||||||
|
expect(() => new Formatter().format(tp)).to.throw("XMLComponent did not format correctly");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -19,7 +22,7 @@ describe("TableProperties", () => {
|
|||||||
const tp = new TableProperties().setWidth(1234, WidthType.DXA);
|
const tp = new TableProperties().setWidth(1234, WidthType.DXA);
|
||||||
const tree = new Formatter().format(tp);
|
const tree = new Formatter().format(tp);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tblPr": [{ "w:tblW": [{ _attr: { "w:type": "dxa", "w:w": 1234 } }] }],
|
"w:tblPr": [{ "w:tblW": { _attr: { "w:type": "dxa", "w:w": 1234 } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -27,7 +30,7 @@ describe("TableProperties", () => {
|
|||||||
const tp = new TableProperties().setWidth(1234);
|
const tp = new TableProperties().setWidth(1234);
|
||||||
const tree = new Formatter().format(tp);
|
const tree = new Formatter().format(tp);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tblPr": [{ "w:tblW": [{ _attr: { "w:type": "auto", "w:w": 1234 } }] }],
|
"w:tblPr": [{ "w:tblW": { _attr: { "w:type": "auto", "w:w": 1234 } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -37,7 +40,7 @@ describe("TableProperties", () => {
|
|||||||
const tp = new TableProperties().setFixedWidthLayout();
|
const tp = new TableProperties().setFixedWidthLayout();
|
||||||
const tree = new Formatter().format(tp);
|
const tree = new Formatter().format(tp);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tblPr": [{ "w:tblLayout": [{ _attr: { "w:type": "fixed" } }] }],
|
"w:tblPr": [{ "w:tblLayout": { _attr: { "w:type": "fixed" } } }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -48,7 +51,7 @@ describe("TableProperties", () => {
|
|||||||
tp.CellMargin.addTopMargin(1234, WidthType.DXA);
|
tp.CellMargin.addTopMargin(1234, WidthType.DXA);
|
||||||
const tree = new Formatter().format(tp);
|
const tree = new Formatter().format(tp);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tblPr": [{ "w:tblCellMar": [{ "w:top": [{ _attr: { "w:sz": "dxa", "w:w": 1234 } }] }] }],
|
"w:tblPr": [{ "w:tblCellMar": [{ "w:top": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -57,7 +60,7 @@ describe("TableProperties", () => {
|
|||||||
tp.CellMargin.addLeftMargin(1234, WidthType.DXA);
|
tp.CellMargin.addLeftMargin(1234, WidthType.DXA);
|
||||||
const tree = new Formatter().format(tp);
|
const tree = new Formatter().format(tp);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tblPr": [{ "w:tblCellMar": [{ "w:left": [{ _attr: { "w:sz": "dxa", "w:w": 1234 } }] }] }],
|
"w:tblPr": [{ "w:tblCellMar": [{ "w:left": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { XmlComponent } from "file/xml-components";
|
import { IgnoreIfEmptyXmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
import { ITableShadingAttributesProperties, TableShading } from "../shading";
|
import { ITableShadingAttributesProperties, TableShading } from "../shading";
|
||||||
import { WidthType } from "../table-cell";
|
import { WidthType } from "../table-cell";
|
||||||
@ -8,7 +8,7 @@ import { ITableFloatOptions, TableFloatProperties } from "./table-float-properti
|
|||||||
import { TableLayout, TableLayoutType } from "./table-layout";
|
import { TableLayout, TableLayoutType } from "./table-layout";
|
||||||
import { PreferredTableWidth } from "./table-width";
|
import { PreferredTableWidth } from "./table-width";
|
||||||
|
|
||||||
export class TableProperties extends XmlComponent {
|
export class TableProperties extends IgnoreIfEmptyXmlComponent {
|
||||||
private readonly cellMargin: TableCellMargin;
|
private readonly cellMargin: TableCellMargin;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
export * from "./table-row";
|
export * from "./table-row";
|
||||||
export * from "./table-row-properties";
|
export * from "./table-row-properties";
|
||||||
|
export * from "./table-row-height";
|
||||||
|
32
src/file/table/table-row/table-row-height.ts
Normal file
32
src/file/table/table-row/table-row-height.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
|
export enum HeightRule {
|
||||||
|
/** Height is determined based on the content, so value is ignored. */
|
||||||
|
AUTO = "auto",
|
||||||
|
/** At least the value specified */
|
||||||
|
ATLEAST = "atLeast",
|
||||||
|
/** Exactly the value specified */
|
||||||
|
EXACT = "exact",
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ITableRowHeight {
|
||||||
|
readonly height: number;
|
||||||
|
readonly rule: HeightRule;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TableRowHeightAttributes extends XmlAttributeComponent<ITableRowHeight> {
|
||||||
|
protected readonly xmlKeys = { height: "w:val", rule: "w:hRule" };
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TableRowHeight extends XmlComponent {
|
||||||
|
constructor(value: number, rule: HeightRule) {
|
||||||
|
super("w:trHeight");
|
||||||
|
|
||||||
|
this.root.push(
|
||||||
|
new TableRowHeightAttributes({
|
||||||
|
height: value,
|
||||||
|
rule: rule,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,17 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
|
import { HeightRule } from "file/table/table-row/table-row-height";
|
||||||
import { TableRowProperties } from "./table-row-properties";
|
import { TableRowProperties } from "./table-row-properties";
|
||||||
|
|
||||||
describe("TableRowProperties", () => {
|
describe("TableRowProperties", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
it("creates an initially empty property object", () => {
|
it("creates an initially empty property object", () => {
|
||||||
const rowProperties = new TableRowProperties();
|
const rowProperties = new TableRowProperties();
|
||||||
const tree = new Formatter().format(rowProperties);
|
// The TableRowProperties is ignorable if there are no attributes,
|
||||||
expect(tree).to.deep.equal({ "w:trPr": [] });
|
// which results in prepForXml returning undefined, which causes
|
||||||
|
// the formatter to throw an error if that is the only object it
|
||||||
|
// has been asked to format.
|
||||||
|
expect(() => new Formatter().format(rowProperties)).to.throw("XMLComponent did not format correctly");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -16,7 +20,7 @@ describe("TableRowProperties", () => {
|
|||||||
const rowProperties = new TableRowProperties();
|
const rowProperties = new TableRowProperties();
|
||||||
rowProperties.setCantSplit();
|
rowProperties.setCantSplit();
|
||||||
const tree = new Formatter().format(rowProperties);
|
const tree = new Formatter().format(rowProperties);
|
||||||
expect(tree).to.deep.equal({ "w:trPr": [{ "w:cantSplit": [{ _attr: { "w:val": true } }] }] });
|
expect(tree).to.deep.equal({ "w:trPr": [{ "w:cantSplit": { _attr: { "w:val": true } } }] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -25,7 +29,28 @@ describe("TableRowProperties", () => {
|
|||||||
const rowProperties = new TableRowProperties();
|
const rowProperties = new TableRowProperties();
|
||||||
rowProperties.setTableHeader();
|
rowProperties.setTableHeader();
|
||||||
const tree = new Formatter().format(rowProperties);
|
const tree = new Formatter().format(rowProperties);
|
||||||
expect(tree).to.deep.equal({ "w:trPr": [{ "w:tblHeader": [{ _attr: { "w:val": true } }] }] });
|
expect(tree).to.deep.equal({ "w:trPr": [{ "w:tblHeader": { _attr: { "w:val": true } } }] });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("#setHeight", () => {
|
||||||
|
it("sets row height exact", () => {
|
||||||
|
const rowProperties = new TableRowProperties();
|
||||||
|
rowProperties.setHeight(100, HeightRule.EXACT);
|
||||||
|
const tree = new Formatter().format(rowProperties);
|
||||||
|
expect(tree).to.deep.equal({ "w:trPr": [{ "w:trHeight": { _attr: { "w:val": 100, "w:hRule": "exact" } } }] });
|
||||||
|
});
|
||||||
|
it("sets row height auto", () => {
|
||||||
|
const rowProperties = new TableRowProperties();
|
||||||
|
rowProperties.setHeight(100, HeightRule.AUTO);
|
||||||
|
const tree = new Formatter().format(rowProperties);
|
||||||
|
expect(tree).to.deep.equal({ "w:trPr": [{ "w:trHeight": { _attr: { "w:val": 100, "w:hRule": "auto" } } }] });
|
||||||
|
});
|
||||||
|
it("sets row height at least", () => {
|
||||||
|
const rowProperties = new TableRowProperties();
|
||||||
|
rowProperties.setHeight(100, HeightRule.ATLEAST);
|
||||||
|
const tree = new Formatter().format(rowProperties);
|
||||||
|
expect(tree).to.deep.equal({ "w:trPr": [{ "w:trHeight": { _attr: { "w:val": 100, "w:hRule": "atLeast" } } }] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
import { HeightRule, TableRowHeight } from "file/table/table-row/table-row-height";
|
||||||
|
import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
export class TableRowProperties extends XmlComponent {
|
export class TableRowProperties extends IgnoreIfEmptyXmlComponent {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("w:trPr");
|
super("w:trPr");
|
||||||
}
|
}
|
||||||
@ -16,6 +17,12 @@ export class TableRowProperties extends XmlComponent {
|
|||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setHeight(height: number, rule: HeightRule): TableRowProperties {
|
||||||
|
this.root.push(new TableRowHeight(height, rule));
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CantSplitAttributes extends XmlAttributeComponent<{ readonly val: boolean }> {
|
class CantSplitAttributes extends XmlAttributeComponent<{ readonly val: boolean }> {
|
||||||
|
@ -2,6 +2,8 @@ import { expect } from "chai";
|
|||||||
|
|
||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
|
import { HeightRule } from "file/table/table-row/table-row-height";
|
||||||
|
import { EMPTY_OBJECT } from "file/xml-components";
|
||||||
import { TableCell } from "../table-cell";
|
import { TableCell } from "../table-cell";
|
||||||
import { TableRow } from "./table-row";
|
import { TableRow } from "./table-row";
|
||||||
|
|
||||||
@ -11,11 +13,7 @@ describe("TableRow", () => {
|
|||||||
const tableRow = new TableRow([]);
|
const tableRow = new TableRow([]);
|
||||||
const tree = new Formatter().format(tableRow);
|
const tree = new Formatter().format(tableRow);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tr": [
|
"w:tr": EMPTY_OBJECT,
|
||||||
{
|
|
||||||
"w:trPr": [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -24,20 +22,10 @@ describe("TableRow", () => {
|
|||||||
const tree = new Formatter().format(tableRow);
|
const tree = new Formatter().format(tableRow);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tr": [
|
"w:tr": [
|
||||||
{
|
|
||||||
"w:trPr": [],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"w:tc": [
|
"w:tc": [
|
||||||
{
|
{
|
||||||
"w:tcPr": [],
|
"w:p": EMPTY_OBJECT,
|
||||||
},
|
|
||||||
{
|
|
||||||
"w:p": [
|
|
||||||
{
|
|
||||||
"w:pPr": [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -79,4 +67,28 @@ describe("TableRow", () => {
|
|||||||
expect(() => tableRow.getCell(1)).to.throw();
|
expect(() => tableRow.getCell(1)).to.throw();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#setHeight", () => {
|
||||||
|
it("should set row height", () => {
|
||||||
|
const tableRow = new TableRow([]);
|
||||||
|
tableRow.setHeight(100, HeightRule.EXACT);
|
||||||
|
const tree = new Formatter().format(tableRow);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:tr": [
|
||||||
|
{
|
||||||
|
"w:trPr": [
|
||||||
|
{
|
||||||
|
"w:trHeight": {
|
||||||
|
_attr: {
|
||||||
|
"w:hRule": "exact",
|
||||||
|
"w:val": 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user