Compare commits

...

39 Commits
8.0.1 ... 8.0.3

Author SHA1 Message Date
bb686bbcbe Version bump 2023-04-20 00:58:11 +01:00
c898d0a3c3 Merge pull request #2087 from lentyaevpk/fix/myoffice-numbering-render
fix: added unique numeric id creator to avoid numbering render errors
2023-04-19 18:09:42 +01:00
704c678333 fix: unit tests fix 2023-04-19 16:51:03 +03:00
c59c5350fd fix: added unique numeric id creator to avoid numbering render errors 2023-04-18 15:15:38 +03:00
accb1d44d0 Version bump 2023-04-05 02:03:30 +01:00
b61f798cd9 Merge pull request #2059 from dolanmiu/dependabot/npm_and_yarn/typescript-eslint/parser-5.57.1
build(deps-dev): bump @typescript-eslint/parser from 5.56.0 to 5.57.1
2023-04-04 22:43:40 +01:00
be2ec9d4cf Merge pull request #2058 from dolanmiu/dependabot/npm_and_yarn/typescript-eslint/eslint-plugin-5.57.1
build(deps-dev): bump @typescript-eslint/eslint-plugin from 5.56.0 to 5.57.1
2023-04-04 22:43:34 +01:00
514fbb1c09 Merge pull request #2054 from dolanmiu/dependabot/npm_and_yarn/typescript-5.0.3
build(deps-dev): bump typescript from 5.0.2 to 5.0.3
2023-04-04 22:43:25 +01:00
8ce397f61e Merge pull request #2052 from dolanmiu/dependabot/npm_and_yarn/tsconfig-paths-4.2.0
build(deps-dev): bump tsconfig-paths from 4.1.2 to 4.2.0
2023-04-04 22:43:19 +01:00
3b0dfb8489 Merge pull request #2049 from dolanmiu/dependabot/npm_and_yarn/types/node-18.15.11
build(deps): bump @types/node from 18.15.7 to 18.15.11
2023-04-04 22:43:09 +01:00
f4933deaf2 Merge pull request #2048 from dolanmiu/dependabot/npm_and_yarn/eslint-8.37.0
build(deps-dev): bump eslint from 8.36.0 to 8.37.0
2023-04-04 22:42:59 +01:00
add2273551 Merge pull request #2045 from dolanmiu/dependabot/npm_and_yarn/types/webpack-5.28.1
build(deps-dev): bump @types/webpack from 5.28.0 to 5.28.1
2023-04-04 22:42:52 +01:00
91b00466a0 Merge pull request #2040 from dolanmiu/dependabot/npm_and_yarn/sinon-15.0.3
build(deps-dev): bump sinon from 15.0.2 to 15.0.3
2023-04-04 22:42:45 +01:00
d0612e115e Merge pull request #2038 from dolanmiu/dependabot/npm_and_yarn/cspell-6.31.1
build(deps-dev): bump cspell from 6.30.2 to 6.31.1
2023-04-04 22:42:37 +01:00
e4a6cbe887 Merge pull request #2053 from dolanmiu/feat/fix-templating
#2028 - Null check
2023-04-04 22:38:16 +01:00
0386810714 Write tests and simplify logic 2023-04-04 22:21:01 +01:00
d4585f60b3 build(deps-dev): bump @typescript-eslint/parser from 5.56.0 to 5.57.1
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 5.56.0 to 5.57.1.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.57.1/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-04 11:57:39 +00:00
18f015a959 build(deps-dev): bump @typescript-eslint/eslint-plugin
Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 5.56.0 to 5.57.1.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.57.1/packages/eslint-plugin)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-04 11:56:55 +00:00
10c866bdea Add tests 2023-03-31 17:16:05 +01:00
680c938dcf build(deps-dev): bump typescript from 5.0.2 to 5.0.3
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 5.0.2 to 5.0.3.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/commits)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-31 11:57:07 +00:00
c3a617fefd #2028 - Null check 2023-03-31 00:13:36 +01:00
6362b498a6 Add docsify sign off sheet 2023-03-30 20:14:08 +01:00
2e30ab29be Update cspell json 2023-03-30 19:59:23 +01:00
44568023cd Add documentation to basedOn 2023-03-30 19:54:33 +01:00
c57aaa856d Update comments demo 2023-03-30 19:43:09 +01:00
0f4f24c3f3 build(deps-dev): bump tsconfig-paths from 4.1.2 to 4.2.0
Bumps [tsconfig-paths](https://github.com/dividab/tsconfig-paths) from 4.1.2 to 4.2.0.
- [Release notes](https://github.com/dividab/tsconfig-paths/releases)
- [Changelog](https://github.com/dividab/tsconfig-paths/blob/master/CHANGELOG.md)
- [Commits](https://github.com/dividab/tsconfig-paths/compare/v4.1.2...v4.2.0)

---
updated-dependencies:
- dependency-name: tsconfig-paths
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-30 11:56:49 +00:00
2fe7a2e3d3 build(deps): bump @types/node from 18.15.7 to 18.15.11
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 18.15.7 to 18.15.11.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-29 11:57:27 +00:00
20b62f5768 build(deps-dev): bump eslint from 8.36.0 to 8.37.0
Bumps [eslint](https://github.com/eslint/eslint) from 8.36.0 to 8.37.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.36.0...v8.37.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-29 11:56:56 +00:00
ab063eee08 Add helper function patchDocument example 2023-03-28 20:16:34 +01:00
66c7624b40 build(deps-dev): bump @types/webpack from 5.28.0 to 5.28.1
Bumps [@types/webpack](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/webpack) from 5.28.0 to 5.28.1.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/webpack)

---
updated-dependencies:
- dependency-name: "@types/webpack"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-28 11:58:06 +00:00
bfc302023f build(deps-dev): bump sinon from 15.0.2 to 15.0.3
Bumps [sinon](https://github.com/sinonjs/sinon) from 15.0.2 to 15.0.3.
- [Release notes](https://github.com/sinonjs/sinon/releases)
- [Changelog](https://github.com/sinonjs/sinon/blob/main/docs/changelog.md)
- [Commits](https://github.com/sinonjs/sinon/compare/v15.0.2...v15.0.3)

---
updated-dependencies:
- dependency-name: sinon
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-27 11:57:32 +00:00
3505912f74 build(deps-dev): bump cspell from 6.30.2 to 6.31.1
Bumps [cspell](https://github.com/streetsidesoftware/cspell) from 6.30.2 to 6.31.1.
- [Release notes](https://github.com/streetsidesoftware/cspell/releases)
- [Changelog](https://github.com/streetsidesoftware/cspell/blob/main/CHANGELOG.md)
- [Commits](https://github.com/streetsidesoftware/cspell/compare/v6.30.2...v6.31.1)

---
updated-dependencies:
- dependency-name: cspell
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-27 11:57:03 +00:00
ec379f2e4d Update documentation 2023-03-26 04:05:41 +01:00
2d17954104 Merge pull request #2034 from dolanmiu/dependabot/npm_and_yarn/types/node-18.15.7
build(deps): bump @types/node from 18.15.5 to 18.15.7
2023-03-24 15:11:58 +00:00
01c834b16b Merge pull request #2035 from dolanmiu/dependabot/npm_and_yarn/prettier-2.8.7
build(deps-dev): bump prettier from 2.8.6 to 2.8.7
2023-03-24 15:11:52 +00:00
2aeb2c2e88 Merge pull request #2036 from dolanmiu/dependabot/npm_and_yarn/webpack-5.76.3
build(deps-dev): bump webpack from 5.76.2 to 5.76.3
2023-03-24 15:11:45 +00:00
be88086434 build(deps-dev): bump webpack from 5.76.2 to 5.76.3
Bumps [webpack](https://github.com/webpack/webpack) from 5.76.2 to 5.76.3.
- [Release notes](https://github.com/webpack/webpack/releases)
- [Commits](https://github.com/webpack/webpack/compare/v5.76.2...v5.76.3)

---
updated-dependencies:
- dependency-name: webpack
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-24 11:57:59 +00:00
28f0cc681d build(deps-dev): bump prettier from 2.8.6 to 2.8.7
Bumps [prettier](https://github.com/prettier/prettier) from 2.8.6 to 2.8.7.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.8.6...2.8.7)

---
updated-dependencies:
- dependency-name: prettier
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-24 11:57:30 +00:00
def29c535b build(deps): bump @types/node from 18.15.5 to 18.15.7
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 18.15.5 to 18.15.7.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-24 11:57:04 +00:00
23 changed files with 703 additions and 465 deletions

View File

@ -4,34 +4,40 @@
"version": "0.2",
// language - current active spelling language
"language": "en_US",
"dictionaries": ["en_US", "typescript", "softwareTerms", "fonts", "npm"],
"dictionaries": [
"en_US",
"typescript",
"softwareTerms",
"fonts",
"npm"
],
// words - list of words to be always considered correct
"words": [
"Xmlable",
"Abjad",
"aiueo",
"ATLEAST",
"chosung",
"clippy",
"datas",
"docsify",
"dolan",
"falsey",
"Initializable",
"iroha",
"jsonify",
"jszip",
"NUMPAGES",
"odttf",
"ooxml",
"panose",
"rels",
"rsid",
"twip",
"twips",
"jsonify",
"falsey",
"aiueo",
"iroha",
"aiueo",
"iroha",
"chosung",
"Abjad",
"Initializable",
"rels",
"dolan",
"xmlify",
"Xmlifyed",
"Xmlable",
"xmlified",
"datas",
"jszip",
"rsid",
"NUMPAGES",
"ATLEAST",
"ooxml",
"clippy",
"docsify"
"xmlify",
"Xmlifyed"
],
"ignoreRegExpList": [
"/\"w:.+\"/",
@ -51,10 +57,15 @@
"/<element name=\"[a-z]+\"/gi",
"/<attribute name=\"[a-z]+\"/gi"
],
"ignorePaths": ["package.json", "docs/api"],
"ignorePaths": [
"package.json",
"docs/api"
],
"allowCompoundWords": true,
// flagWords - list of words to be always considered incorrect
// This is useful for offensive words and common spelling errors.
// For example "hte" should be "the"
"flagWords": ["hte"]
"flagWords": [
"hte"
]
}

View File

@ -32,6 +32,55 @@ const doc = new Document({
}),
],
},
{
id: 1,
author: "Bob Ross",
date: new Date(),
children: [
new Paragraph({
children: [
new TextRun({
text: "Some initial text content",
}),
],
}),
new Paragraph({
children: [
new TextRun({
text: "comment text content",
}),
],
}),
],
},
{
id: 2,
author: "John Doe",
date: new Date(),
children: [
new Paragraph({
children: [
new TextRun({
text: "Hello World",
}),
],
}),
],
},
{
id: 3,
author: "Beatriz",
date: new Date(),
children: [
new Paragraph({
children: [
new TextRun({
text: "Another reply",
}),
],
}),
],
},
],
},
sections: [
@ -53,6 +102,32 @@ const doc = new Document({
}),
],
}),
new Paragraph({
children: [
new CommentRangeStart(1),
new CommentRangeStart(2),
new CommentRangeStart(3),
new TextRun({
text: "Some text which need commenting",
bold: true,
}),
new CommentRangeEnd(1),
new TextRun({
children: [new CommentReference(1)],
bold: true,
}),
new CommentRangeEnd(2),
new TextRun({
children: [new CommentReference(2)],
bold: true,
}),
new CommentRangeEnd(3),
new TextRun({
children: [new CommentReference(3)],
bold: true,
}),
],
}),
],
},
],

View File

@ -0,0 +1,31 @@
// Patch a document with patches
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { IPatch, patchDocument, PatchType, TextRun } from "../build";
export const font = "Trebuchet MS";
export const getPatches = (fields: { [key: string]: string }) => {
const patches: { [key: string]: IPatch } = {};
for (const field in fields) {
patches[field] = {
type: PatchType.PARAGRAPH,
children: [new TextRun({ text: fields[field], font })],
};
}
return patches;
};
const patches = getPatches({
name: "Mr",
table_heading_1: "John",
item_1: "Doe",
paragraph_replace: "Lorem ipsum paragraph",
});
patchDocument(fs.readFileSync("demo/assets/simple-template.docx"), {
patches,
}).then((doc) => {
fs.writeFileSync("My Document.docx", doc);
});

View File

@ -0,0 +1,29 @@
// Patch a document with patches
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { IPatch, patchDocument, PatchType, TextRun } from "../build";
export const font = "Trebuchet MS";
export const getPatches = (fields: { [key: string]: string }) => {
const patches: { [key: string]: IPatch } = {};
for (const field in fields) {
patches[field] = {
type: PatchType.PARAGRAPH,
children: [new TextRun({ text: fields[field], font })],
};
}
return patches;
};
const patches = getPatches({
salutation: "Mr.",
"first-name": "John",
});
patchDocument(fs.readFileSync("demo/assets/simple-template-3.docx"), {
patches,
}).then((doc) => {
fs.writeFileSync("My Document.docx", doc);
});

Binary file not shown.

View File

@ -38,6 +38,7 @@
<script src="https://unpkg.com/docsify-copy-code@2"></script>
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-typescript.min.js"></script>
<script src="https://unpkg.com/docsify-sign-off-sheet@1.0.0/dist/index.iife.js"></script>
<script src="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/index.min.js" type="text/javascript"></script>
</body>
</html>

View File

@ -305,4 +305,12 @@ Example: https://github.com/dolanmiu/docx/blob/master/demo/15-page-break-before.
## Page break control
Paragraphs have `.keepLines()` and `.keepNext()` methods that allow restricting page breaks within and between paragraphs. See [this Microsoft article](https://support.office.com/en-us/article/Keep-lines-and-paragraphs-together-d72af534-926f-4c4b-830a-abfc2daa3bfa) for more details)
Paragraphs have `keepLines` and `keepNext` properties that allow restricting page breaks within and between paragraphs. See [this Microsoft article](https://support.office.com/en-us/article/Keep-lines-and-paragraphs-together-d72af534-926f-4c4b-830a-abfc2daa3bfa) for more details.
```ts
const paragraph = new Paragraph({
text: "Stay on the same page",
keepLines: true,
keepNext: true,
});
```

829
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "docx",
"version": "8.0.1",
"version": "8.0.3",
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
"main": "build/index.js",
"scripts": {
@ -104,7 +104,7 @@
"tsconfig-paths": "^4.0.0",
"tsconfig-paths-webpack-plugin": "^4.0.0",
"typedoc": "^0.23.2",
"typescript": "5.0.2",
"typescript": "5.0.3",
"unzipper": "^0.10.11",
"webpack": "^5.28.0",
"webpack-cli": "^5.0.0"

View File

@ -41,11 +41,11 @@ const createAnchor = (drawingOptions: IDrawingOptions): Anchor =>
describe("Anchor", () => {
before(() => {
stub(convenienceFunctions, "uniqueNumericId").callsFake(() => 0);
stub(convenienceFunctions, "docPropertiesUniqueNumericId").callsFake(() => 0);
});
after(() => {
(convenienceFunctions.uniqueNumericId as SinonStub).restore();
(convenienceFunctions.docPropertiesUniqueNumericId as SinonStub).restore();
});
let anchor: Anchor;

View File

@ -2,7 +2,7 @@
import { IContext, IXmlableObject, NextAttributeComponent, XmlComponent } from "@file/xml-components";
import { ConcreteHyperlink } from "@file/paragraph";
import { uniqueNumericId } from "@util/convenience-functions";
import { docPropertiesUniqueNumericId } from "@util/convenience-functions";
import { createHyperlinkClick } from "./doc-properties-children";
@ -32,7 +32,7 @@ export class DocProperties extends XmlComponent {
new NextAttributeComponent({
id: {
key: "id",
value: uniqueNumericId(),
value: docPropertiesUniqueNumericId(),
},
name: {
key: "name",

View File

@ -31,11 +31,11 @@ const createDrawing = (drawingOptions?: IDrawingOptions): Drawing =>
describe("Drawing", () => {
before(() => {
stub(convenienceFunctions, "uniqueNumericId").callsFake(() => 0);
stub(convenienceFunctions, "docPropertiesUniqueNumericId").callsFake(() => 0);
});
after(() => {
(convenienceFunctions.uniqueNumericId as SinonStub).restore();
(convenienceFunctions.docPropertiesUniqueNumericId as SinonStub).restore();
});
let currentBreak: Drawing;

View File

@ -8,11 +8,13 @@ import { Numbering } from "./numbering";
describe("Numbering", () => {
before(() => {
stub(convenienceFunctions, "uniqueNumericId").callsFake(() => 0);
stub(convenienceFunctions, "abstractNumUniqueNumericId").callsFake(() => 0);
stub(convenienceFunctions, "concreteNumUniqueNumericId").callsFake(() => 0);
});
after(() => {
(convenienceFunctions.uniqueNumericId as SinonStub).restore();
(convenienceFunctions.abstractNumUniqueNumericId as SinonStub).restore();
(convenienceFunctions.concreteNumUniqueNumericId as SinonStub).restore();
});
describe("#constructor", () => {

View File

@ -2,7 +2,7 @@
// https://stackoverflow.com/questions/58622437/purpose-of-abstractnum-and-numberinginstance
import { AlignmentType } from "@file/paragraph";
import { IContext, IXmlableObject, XmlComponent } from "@file/xml-components";
import { convertInchesToTwip, uniqueNumericId } from "@util/convenience-functions";
import { abstractNumUniqueNumericId, concreteNumUniqueNumericId, convertInchesToTwip } from "@util/convenience-functions";
import { DocumentAttributes } from "../document/document-attributes";
import { AbstractNumbering } from "./abstract-numbering";
@ -55,7 +55,7 @@ export class Numbering extends XmlComponent {
}),
);
const abstractNumbering = new AbstractNumbering(uniqueNumericId(), [
const abstractNumbering = new AbstractNumbering(abstractNumUniqueNumericId(), [
{
level: 0,
format: LevelFormat.BULLET,
@ -176,7 +176,7 @@ export class Numbering extends XmlComponent {
this.abstractNumberingMap.set("default-bullet-numbering", abstractNumbering);
for (const con of options.config) {
this.abstractNumberingMap.set(con.reference, new AbstractNumbering(uniqueNumericId(), con.levels));
this.abstractNumberingMap.set(con.reference, new AbstractNumbering(abstractNumUniqueNumericId(), con.levels));
this.referenceConfigMap.set(con.reference, con.levels);
}
}
@ -209,7 +209,7 @@ export class Numbering extends XmlComponent {
const firstLevelStartNumber = referenceConfigLevels && referenceConfigLevels[0].start;
const concreteNumberingSettings = {
numId: uniqueNumericId(),
numId: concreteNumUniqueNumericId(),
abstractNumId: abstractNumbering.id,
reference,
instance,

View File

@ -1,6 +1,6 @@
// http://officeopenxml.com/WPbookmark.php
import { XmlComponent } from "@file/xml-components";
import { uniqueNumericId } from "@util/convenience-functions";
import { bookmarkUniqueNumericId } from "@util/convenience-functions";
import { ParagraphChild } from "../paragraph";
import { BookmarkEndAttributes, BookmarkStartAttributes } from "./bookmark-attributes";
@ -11,7 +11,7 @@ export class Bookmark {
public readonly end: BookmarkEnd;
public constructor(options: { readonly id: string; readonly children: readonly ParagraphChild[] }) {
const linkId = uniqueNumericId();
const linkId = bookmarkUniqueNumericId();
this.start = new BookmarkStart(options.id, linkId);
this.children = options.children;

View File

@ -20,12 +20,12 @@ import { TextRun } from "./run";
describe("Paragraph", () => {
before(() => {
stub(convenienceFunctions, "uniqueId").callsFake(() => "test-unique-id");
stub(convenienceFunctions, "uniqueNumericId").callsFake(() => -101);
stub(convenienceFunctions, "bookmarkUniqueNumericId").callsFake(() => -101);
});
after(() => {
(convenienceFunctions.uniqueId as SinonStub).restore();
(convenienceFunctions.uniqueNumericId as SinonStub).restore();
(convenienceFunctions.bookmarkUniqueNumericId as SinonStub).restore();
});
describe("#constructor()", () => {

View File

@ -23,7 +23,13 @@ export interface ILevelParagraphStylePropertiesOptions {
readonly leftTabStop?: number;
readonly indent?: IIndentAttributesProperties;
readonly spacing?: ISpacingProperties;
/**
* Specifies that the paragraph (or at least part of it) should be rendered on the same page as the next paragraph when possible. If multiple paragraphs are to be kept together but they exceed a page, then the set of paragraphs begin on a new page and page breaks are used thereafter as needed.
*/
readonly keepNext?: boolean;
/**
* Specifies that all lines of the paragraph are to be kept on a single page when possible.
*/
readonly keepLines?: boolean;
readonly outlineLevel?: number;
}

View File

@ -11,12 +11,12 @@ import { ImageRun } from "./image-run";
describe("ImageRun", () => {
before(() => {
stub(convenienceFunctions, "uniqueId").callsFake(() => "test-unique-id");
stub(convenienceFunctions, "uniqueNumericId").callsFake(() => 0);
stub(convenienceFunctions, "docPropertiesUniqueNumericId").callsFake(() => 0);
});
after(() => {
(convenienceFunctions.uniqueId as SinonStub).restore();
(convenienceFunctions.uniqueNumericId as SinonStub).restore();
(convenienceFunctions.docPropertiesUniqueNumericId as SinonStub).restore();
});
describe("#constructor()", () => {

View File

@ -41,6 +41,13 @@ export interface IStyleAttributes {
export interface IStyleOptions {
readonly name?: string;
/**
* Specifies the style upon which the current style is based-that is, the style from which the current style inherits. It is the mechanism for implementing style inheritance.
* Note that if the type of the current style must match the type of the style upon which it is based or the basedOn element will be ignored.
* However, if the current style is a numbering style, then the `basedOn` element is ignored.
*
* **WARNING**: You cannot set `basedOn` to be the same as `name`. This is akin to inheriting from itself. This creates a cyclic dependency and cause undesirable behavior.
*/
readonly basedOn?: string;
readonly next?: string;
readonly link?: string;

View File

@ -86,6 +86,59 @@ describe("paragraph-split-inject", () => {
),
).to.throw();
});
it("should continue if text run doesn't have text", () => {
expect(() =>
findRunElementIndexWithToken(
{
name: "w:p",
type: "element",
elements: [
{
name: "w:r",
type: "element",
elements: [
{
name: "w:t",
type: "element",
},
],
},
],
},
"hello",
),
).to.throw();
});
it("should continue if text run doesn't have text", () => {
expect(() =>
findRunElementIndexWithToken(
{
name: "w:p",
type: "element",
elements: [
{
name: "w:r",
type: "element",
elements: [
{
name: "w:t",
type: "element",
elements: [
{
type: "text",
},
],
},
],
},
],
},
"hello",
),
).to.throw();
});
});
describe("splitRunElement", () => {

View File

@ -8,7 +8,11 @@ export const findRunElementIndexWithToken = (paragraphElement: Element, token: s
const textElement = (element.elements ?? []).filter((e) => e.type === "element" && e.name === "w:t");
for (const text of textElement) {
if ((text.elements?.[0].text as string)?.includes(token)) {
if (!text.elements?.[0]) {
continue;
}
if ((text.elements[0].text as string)?.includes(token)) {
return i;
}
}

View File

@ -1,6 +1,6 @@
import { expect } from "chai";
import { convertInchesToTwip, convertMillimetersToTwip, uniqueId, uniqueNumericId } from "./convenience-functions";
import { convertInchesToTwip, convertMillimetersToTwip, uniqueId, uniqueNumericIdCreator } from "./convenience-functions";
describe("Utility", () => {
describe("#convertMillimetersToTwip", () => {
@ -17,8 +17,9 @@ describe("Utility", () => {
});
});
describe("#uniqueNumericId", () => {
describe("#uniqueNumericIdCreator", () => {
it("should generate a unique incrementing ID", () => {
const uniqueNumericId = uniqueNumericIdCreator();
expect(uniqueNumericId()).to.not.be.undefined;
});
});

View File

@ -1,12 +1,19 @@
import { nanoid } from "nanoid/non-secure";
let currentCount = 0;
// Twip - twentieths of a point
export const convertMillimetersToTwip = (millimeters: number): number => Math.floor((millimeters / 25.4) * 72 * 20);
export const convertInchesToTwip = (inches: number): number => Math.floor(inches * 72 * 20);
export const uniqueNumericId = (): number => ++currentCount;
export const uniqueNumericIdCreator = (initial = 0): (() => number) => {
let currentCount = initial;
return () => ++currentCount;
};
export const abstractNumUniqueNumericId = uniqueNumericIdCreator();
export const concreteNumUniqueNumericId = uniqueNumericIdCreator(1); // Setting initial to 1 as we have numId = 1 for "default-bullet-numbering"
export const docPropertiesUniqueNumericId = uniqueNumericIdCreator();
export const bookmarkUniqueNumericId = uniqueNumericIdCreator();
export const uniqueId = (): string => nanoid().toLowerCase();