Compare commits

...

38 Commits
8.2.0 ... 8.2.3

Author SHA1 Message Date
d5d80550e7 Version bump 2023-09-26 23:00:51 +01:00
23a0a59454 Use .mjs for ESM 2023-09-26 22:59:32 +01:00
ccc391607a Merge pull request #2331 from hshoja/doc/update-style-with-xml
Update styling with xml  docs
2023-09-11 21:04:32 +01:00
968c3aed0f Update styling-with-xml doc 2023-09-10 15:57:48 +02:00
9c7a80729b Merge branch 'master' of github.com:dolanmiu/docx 2023-08-06 20:10:11 +01:00
5f26ca1c94 Update numbering docs 2023-08-06 20:10:03 +01:00
3b9f80fb1a Merge pull request #2259 from dolanmiu/feat/bump-prettier
Bump prettier
2023-07-21 22:13:17 +01:00
8da57bec51 Bump prettier
Fix new prettier issues
2023-07-21 20:11:52 +01:00
63db9f290c Version bump 2023-07-20 22:44:30 +01:00
e8bd4bd6c6 Merge pull request #2256 from dolanmiu/feature/tweak-build
Remove default browser export
2023-07-20 22:42:56 +01:00
28d93b0c42 Remove default browser export
Fixes Angular issue
2023-07-20 20:46:53 +01:00
95f8e37006 Version bump 2023-07-19 02:10:13 +01:00
87083cb264 Merge pull request #2240 from dolanmiu/dependabot/npm_and_yarn/vite-plugin-dts-3.3.1
build(deps-dev): bump vite-plugin-dts from 2.3.0 to 3.3.1
2023-07-19 01:49:10 +01:00
1e8dc95c9c Merge pull request #2227 from dolanmiu/dependabot/npm_and_yarn/vitest/ui-0.33.0
build(deps-dev): bump @vitest/ui from 0.32.2 to 0.33.0
2023-07-19 01:49:04 +01:00
abfa242c28 build(deps-dev): bump @vitest/ui from 0.32.2 to 0.33.0
Bumps [@vitest/ui](https://github.com/vitest-dev/vitest/tree/HEAD/packages/ui) from 0.32.2 to 0.33.0.
- [Release notes](https://github.com/vitest-dev/vitest/releases)
- [Commits](https://github.com/vitest-dev/vitest/commits/v0.33.0/packages/ui)

---
updated-dependencies:
- dependency-name: "@vitest/ui"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-19 00:37:38 +00:00
56b5414152 build(deps-dev): bump vite-plugin-dts from 2.3.0 to 3.3.1
Bumps [vite-plugin-dts](https://github.com/qmhc/vite-plugin-dts) from 2.3.0 to 3.3.1.
- [Release notes](https://github.com/qmhc/vite-plugin-dts/releases)
- [Changelog](https://github.com/qmhc/vite-plugin-dts/blob/main/CHANGELOG.md)
- [Commits](https://github.com/qmhc/vite-plugin-dts/compare/v2.3.0...v3.3.1)

---
updated-dependencies:
- dependency-name: vite-plugin-dts
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-19 00:37:28 +00:00
8f46060be2 Merge pull request #2235 from dolanmiu/dependabot/npm_and_yarn/types/node-20.4.2
build(deps): bump @types/node from 20.3.2 to 20.4.2
2023-07-19 01:36:41 +01:00
93b17ca2af Merge pull request #2226 from dolanmiu/dependabot/npm_and_yarn/vitest/coverage-v8-0.33.0
build(deps-dev): bump @vitest/coverage-v8 from 0.32.2 to 0.33.0
2023-07-19 01:36:27 +01:00
66008115b8 build(deps-dev): bump @vitest/coverage-v8 from 0.32.2 to 0.33.0
Bumps [@vitest/coverage-v8](https://github.com/vitest-dev/vitest/tree/HEAD/packages/coverage-v8) from 0.32.2 to 0.33.0.
- [Release notes](https://github.com/vitest-dev/vitest/releases)
- [Commits](https://github.com/vitest-dev/vitest/commits/v0.33.0/packages/coverage-v8)

---
updated-dependencies:
- dependency-name: "@vitest/coverage-v8"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-19 00:23:34 +00:00
55697a7c32 build(deps): bump @types/node from 20.3.2 to 20.4.2
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.3.2 to 20.4.2.
- [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-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-19 00:22:54 +00:00
e9b259db6b Merge pull request #2241 from dolanmiu/dependabot/npm_and_yarn/eslint-plugin-jsdoc-46.4.4
build(deps-dev): bump eslint-plugin-jsdoc from 46.4.2 to 46.4.4
2023-07-19 01:22:29 +01:00
55c51f7af1 Merge pull request #2238 from dolanmiu/dependabot/npm_and_yarn/eslint-8.45.0
build(deps-dev): bump eslint from 8.43.0 to 8.45.0
2023-07-19 01:22:22 +01:00
4e7fd6a6dc Merge pull request #2242 from dolanmiu/dependabot/npm_and_yarn/esbuild/win32-x64-0.18.14
build(deps-dev): bump @esbuild/win32-x64 from 0.18.10 to 0.18.14
2023-07-19 01:22:06 +01:00
6294ec448f Merge pull request #2234 from dolanmiu/dependabot/npm_and_yarn/typescript-eslint/parser-5.62.0
build(deps-dev): bump @typescript-eslint/parser from 5.60.1 to 5.62.0
2023-07-19 01:21:48 +01:00
668198b5d1 Merge pull request #2228 from dolanmiu/dependabot/npm_and_yarn/vitest-0.33.0
build(deps-dev): bump vitest from 0.32.2 to 0.33.0
2023-07-19 01:21:41 +01:00
56b2ffe706 Merge pull request #2209 from dolanmiu/dependabot/npm_and_yarn/typescript-5.1.6
build(deps-dev): bump typescript from 5.1.3 to 5.1.6
2023-07-19 01:21:35 +01:00
2ab06ffe36 Merge pull request #2244 from dolanmiu/feature/build-fixes
Fix `vite` build issues
2023-07-19 01:19:15 +01:00
0c51082bb9 Add logging output to demo 2023-07-18 21:07:19 +01:00
9a9a2019f6 Do not polyfill buffer 2023-07-18 21:06:35 +01:00
d94348f5ca Export correct type in patchDocument 2023-07-18 20:49:43 +01:00
4c10741862 build(deps-dev): bump @esbuild/win32-x64 from 0.18.10 to 0.18.14
Bumps [@esbuild/win32-x64](https://github.com/evanw/esbuild) from 0.18.10 to 0.18.14.
- [Release notes](https://github.com/evanw/esbuild/releases)
- [Changelog](https://github.com/evanw/esbuild/blob/main/CHANGELOG.md)
- [Commits](https://github.com/evanw/esbuild/compare/v0.18.10...v0.18.14)

---
updated-dependencies:
- dependency-name: "@esbuild/win32-x64"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-18 11:17:06 +00:00
222a25e4e2 Compile umd version as .js format 2023-07-18 01:53:56 +01:00
5fd4490c4f build(deps-dev): bump eslint-plugin-jsdoc from 46.4.2 to 46.4.4
Bumps [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc) from 46.4.2 to 46.4.4.
- [Release notes](https://github.com/gajus/eslint-plugin-jsdoc/releases)
- [Changelog](https://github.com/gajus/eslint-plugin-jsdoc/blob/main/.releaserc)
- [Commits](https://github.com/gajus/eslint-plugin-jsdoc/compare/v46.4.2...v46.4.4)

---
updated-dependencies:
- dependency-name: eslint-plugin-jsdoc
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-17 11:58:39 +00:00
e1cc65cb97 build(deps-dev): bump eslint from 8.43.0 to 8.45.0
Bumps [eslint](https://github.com/eslint/eslint) from 8.43.0 to 8.45.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.43.0...v8.45.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-07-17 11:57:25 +00:00
991f837bc1 build(deps-dev): bump @typescript-eslint/parser from 5.60.1 to 5.62.0
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 5.60.1 to 5.62.0.
- [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.62.0/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-07-11 11:42:13 +00:00
87b3035465 build(deps-dev): bump vitest from 0.32.2 to 0.33.0
Bumps [vitest](https://github.com/vitest-dev/vitest/tree/HEAD/packages/vitest) from 0.32.2 to 0.33.0.
- [Release notes](https://github.com/vitest-dev/vitest/releases)
- [Commits](https://github.com/vitest-dev/vitest/commits/v0.33.0/packages/vitest)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-07 11:26:34 +00:00
4498305a6c Remove gitter from README 2023-07-04 12:38:54 +01:00
cac7abba91 build(deps-dev): bump typescript from 5.1.3 to 5.1.6
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 5.1.3 to 5.1.6.
- [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-06-30 11:39:27 +00:00
11 changed files with 1157 additions and 1184 deletions

View File

@ -12,7 +12,6 @@
[![Downloads per month][downloads-image]][downloads-url] [![Downloads per month][downloads-image]][downloads-url]
[![GitHub Action Workflow Status][github-actions-workflow-image]][github-actions-workflow-url] [![GitHub Action Workflow Status][github-actions-workflow-image]][github-actions-workflow-url]
[![Known Vulnerabilities][snky-image]][snky-url] [![Known Vulnerabilities][snky-image]][snky-url]
[![Chat on Gitter][gitter-image]][gitter-url]
[![PRs Welcome][pr-image]][pr-url] [![PRs Welcome][pr-image]][pr-url]
[![codecov][codecov-image]][codecov-url] [![codecov][codecov-image]][codecov-url]
@ -107,8 +106,6 @@ Made with 💖
[github-actions-workflow-url]: https://github.com/dolanmiu/docx/actions [github-actions-workflow-url]: https://github.com/dolanmiu/docx/actions
[snky-image]: https://snyk.io/test/github/dolanmiu/docx/badge.svg [snky-image]: https://snyk.io/test/github/dolanmiu/docx/badge.svg
[snky-url]: https://snyk.io/test/github/dolanmiu/docx [snky-url]: https://snyk.io/test/github/dolanmiu/docx
[gitter-image]: https://badges.gitter.im/dolanmiu/docx.svg
[gitter-url]: https://gitter.im/docx-lib/Lobby
[pr-image]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg [pr-image]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
[pr-url]: http://makeapullrequest.com [pr-url]: http://makeapullrequest.com
[codecov-image]: https://codecov.io/gh/dolanmiu/docx/branch/master/graph/badge.svg [codecov-image]: https://codecov.io/gh/dolanmiu/docx/branch/master/graph/badge.svg

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!doctype html>
<html> <html>
<head> <head>
<script src="../build/index.umd.cjs"></script> <script src="../build/index.umd.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js"></script>
</head> </head>

View File

@ -5,9 +5,9 @@ import inquirer from "inquirer";
import { $ } from "execa"; import { $ } from "execa";
export type Answers = { export type Answers = {
type: "list" | "number"; readonly type: "list" | "number";
demoNumber?: number; readonly demoNumber?: number;
demoFile?: number; readonly demoFile?: number;
}; };
const dir = "./demo"; const dir = "./demo";
@ -15,8 +15,7 @@ const fileNames = fs.readdirSync(dir);
const keys = fileNames.map((f) => path.parse(f).name); const keys = fileNames.map((f) => path.parse(f).name);
const getFileNumber = (file: string): number => { const getFileNumber = (file: string): number => {
const nameParts = file.split("-"); const [firstPart] = file.split("-");
const firstPart = nameParts[0];
return Number(firstPart); return Number(firstPart);
}; };
@ -35,15 +34,15 @@ const answers = await inquirer.prompt<Answers>([
name: "demoFile", name: "demoFile",
message: "What demo do you wish to run?", message: "What demo do you wish to run?",
choices: demoFiles, choices: demoFiles,
filter: (input) => parseInt(input.split("-")[0]), filter: (input) => parseInt(input.split("-")[0], 10),
when: (answers) => answers.type === "list", when: (a) => a.type === "list",
}, },
{ {
type: "number", type: "number",
name: "demoNumber", name: "demoNumber",
message: "What demo do you wish to run? (Enter a number)", message: "What demo do you wish to run? (Enter a number)",
default: 1, default: 1,
when: (answers) => answers.type === "number", when: (a) => a.type === "number",
}, },
]); ]);
@ -56,6 +55,7 @@ if (files.length === 0) {
const filePath = path.join(dir, files[0]); const filePath = path.join(dir, files[0]);
console.log(`Running demo ${demoNumber}: ${files[0]}`); console.log(`Running demo ${demoNumber}: ${files[0]}`);
await $`ts-node --project demo/tsconfig.json ${filePath}`; const { stdout } = await $`ts-node --project demo/tsconfig.json ${filePath}`;
console.log(stdout);
console.log("Successfully created document!"); console.log("Successfully created document!");
} }

View File

@ -1,5 +1,7 @@
# Bullets and Numbering # Bullets and Numbering
!> Bullets and Numbering requires an understanding of [Sections](usage/sections.md) and [Paragraphs](usage/paragraph.md).
`docx` is quite flexible in its bullets and numbering system, allowing `docx` is quite flexible in its bullets and numbering system, allowing
the user great freedom in how bullets and numbers are to be styled and the user great freedom in how bullets and numbers are to be styled and
displayed. E.g., numbers can be shown using Arabic numerals, roman displayed. E.g., numbers can be shown using Arabic numerals, roman
@ -8,112 +10,128 @@ format also supports re-using bullets/numbering styles throughout the
document, so that different lists using the same style need not document, so that different lists using the same style need not
redefine them. redefine them.
Because of this flexibility, bullets and numbering in DOCX involves a ## Configuration
couple of moving pieces:
1. Document-level bullets/numbering definitions (abstract) Numbering is configured by adding config into `Document`:
2. Document-level bullets/numbering definitions (concrete)
3. Paragraph-level bullets/numbering selection
## Document-level bullets/numbering definitions (abstract)
Every document contains a set of abstract bullets/numbering
definitions which define the formatting and layout of paragraphs using
those bullets/numbering. An abstract numbering system defines how
bullets/numbers are to be shown for lists, including any sublists that
may be used. Thus each abstract definition includes a series of
_levels_ which form a sequence starting at 0 indicating the top-level
list look and increasing from there to describe the sublists, then
sub-sublists, etc. Each level includes the following properties:
* **level**: This is its 0-based index in the definition stack
* **numberFormat**: This indicates how the bullet or number should be
generated. Options include `bullet` (meaning don't count), `decimal`
(arabic numerals), `upperRoman`, `lowerRoman`, `hex`, and many
more.
* **levelText**: This is a format string using the output of the
`numberFormat` function and generating a string to insert before
every item in the list. You may use `%1`, `%2`, ... to reference the
numbers from each numbering level before this one. Thus a level
text of `%d)` with a number format of `lowerLetter` would result in
the sequence "a)", "b)", ...
* and a few others, which you can see in the OOXML spec section 17.9.6
## Document-level bullets/numbering definitions (concrete)
Concrete definitions are sort of like concrete subclasses of the
abstract definitions. They indicate their parent and are allowed to
override certain level definitions. Thus two lists that differ only in
how sub-sub-lists are to be displayed can share the same abstract
numbering definition and have slightly different concrete definitions.
## Paragraph-level bullets/numbering selection
In order to use a bullets/numbering definition (which must be
concrete), paragraphs need to select it, similar to applying a CSS
class to an element, using both the concrete numbering definition ID
and the level number that the paragraph should be at. Additionally, MS
Word and LibreOffice typically apply a "ListParagraph" style to
paragraphs that are being numbered.
## Using bullets/numbering in `docx`
`docx` includes a pre-defined bullet style which you can add to your
paragraphs using `para.bullets()`. If you require different bullet
styles or numbering of any kind, you'll have to use the
`docx.Numbering` class.
First you need to create a new numbering container class and use it to
create your abstract numbering style, define your levels, and create
your concrete numbering style:
```ts ```ts
const numbering = new docx.Numbering(); new Document({
numbering: {
const abstractNum = numbering.createAbstractNumbering(); config: [...]
abstractNum.createLevel(0, "upperRoman", "%1", "start").addParagraphProperty(new Indent(720, 260));
abstractNum.createLevel(1, "decimal", "%2.", "start").addParagraphProperty(new Indent(1440, 980));
abstractNum.createLevel(2, "lowerLetter", "%3)", "start").addParagraphProperty(new Indent(2160, 1700));
const concrete = numbering.createConcreteNumbering(abstractNum);
```
You can then apply your concrete style to paragraphs using the
`setNumbering` method:
```ts
topLevelP.setNumbering(concrete, 0);
subP.setNumbering(concrete, 1);
subSubP.setNumbering(concrete, 2);
```
## Unindent numbering
Default:1. test
After:1.test
Use default numbering have indent,If you want unindent numbering
How to custom number see the demo:
https://runkit.com/dolanmiu/docx-demo3
```ts
enum LevelSuffix {
NOTHING = "nothing",
SPACE = "space",
TAB = "tab"
} }
})
```
// custom numbering Each `config` entry includes the following properties:
const levels=[
. Each level includes the following properties:
| Property | Type | Notes | Possible Values |
| --------- | ----------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| reference | `string` | Required | A unique `string` |
| levels | `ILevelOptions[]` | Required | a series of _levels_ which form a sequence starting at 0 indicating the top-level list look and increasing from there to describe the sublists, then sub-sublists, etc |
### Level Options
Levels define the numbering definition itself, what it looks like, the indention, the alignment and the style. The reason why it is an array is because it allows the ability to create sub-lists. A sub list will have a different configuration because you may want the sub-list to have a different indentation or different bullet.
| Property | Type | Notes | Possible Values |
| --------- | ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| level | `number` | Required | The list level this definition is for. `0` is for the root level, `1` is for a sub list, `2` is for a sub-sub-list etc. |
| format | `LevelFormat` | Optional | `DECIMAL`, `UPPER_ROMAN`, `LOWER_ROMAN`, `UPPER_LETTER`, `LOWER_LETTER`, `ORDINAL`, `CARDINAL_TEXT`, `ORDINAL_TEXT`, `HEX`, `CHICAGO`, `IDEOGRAPH__DIGITAL`, `JAPANESE_COUNTING`, `AIUEO`, `IROHA`, `DECIMAL_FULL_WIDTH`, `DECIMAL_HALF_WIDTH`, `JAPANESE_LEGAL`, `JAPANESE_DIGITAL_TEN_THOUSAND`, `DECIMAL_ENCLOSED_CIRCLE`, `DECIMAL_FULL_WIDTH2`, `AIUEO_FULL_WIDTH`, `IROHA_FULL_WIDTH`, `DECIMAL_ZERO`, `BULLET`, `GANADA`, `CHOSUNG`, `DECIMAL_ENCLOSED_FULLSTOP`, `DECIMAL_ENCLOSED_PARENTHESES`, `DECIMAL_ENCLOSED_CIRCLE_CHINESE`, `IDEOGRAPH_ENCLOSED_CIRCLE`, `IDEOGRAPH_TRADITIONAL`, `IDEOGRAPH_ZODIAC`, `IDEOGRAPH_ZODIAC_TRADITIONAL`, `TAIWANESE_COUNTING`, `IDEOGRAPH_LEGAL_TRADITIONAL`, `TAIWANESE_COUNTING_THOUSAND`, `TAIWANESE_DIGITAL`, `CHINESE_COUNTING`, `CHINESE_LEGAL_SIMPLIFIED`, `CHINESE_COUNTING_THOUSAND`, `KOREAN_DIGITAL`, `KOREAN_COUNTING`, `KOREAN_LEGAL`, `KOREAN_DIGITAL2`, `VIETNAMESE_COUNTING`, `RUSSIAN_LOWER`, `RUSSIAN_UPPER`, `NONE`, `NUMBER_IN_DASH`, `HEBREW1`, `HEBREW2`, `ARABIC_ALPHA`, `ARABIC_ABJAD`, `HINDI_VOWELS`, `HINDI_CONSONANTS`, `HINDI_NUMBERS`, `HINDI_COUNTING`, `THAI_LETTERS`, `THAI_NUMBERS`, `THAI_COUNTING`, `BAHT_TEXT`, `DOLLAR_TEXT`, `CUSTOM` |
| text | `string` | Optional | A unique `string` to describe the shape of the bullet |
| alignment | `string` | Required | `START`, `CENTER`, `END`, `BOTH`, `MEDIUM_KASHIDA`, `DISTRIBUTE`, `NUM_TAB`, `HIGH_KASHIDA`, `LOW_KASHIDA`, `THAI_DISTRIBUTE`, `LEFT`, `RIGHT`, `JUSTIFIED` |
| style | `string` | Optional | [Sections](usage/styling-with-js.md) |
## Using ordered lists in `docx`
Add a `numbering` section to the `Document` to numbering style, define your levels. Use `LevelFormat.UPPER_ROMAN` for the `format` in `levels`:
```ts
const doc = new Document({
...
numbering: {
config: [
{
reference: "my-numbering",
levels: [
{ {
level: 0, level: 0,
format: "decimal", format: LevelFormat.UPPER_ROMAN,
text: "%1.", text: "%1",
alignment: AlignmentType.START, alignment: AlignmentType.START,
suffix: LevelSuffix.NOTHING, // Cancel intent style: {
}] paragraph: {
indent: { left: 2880, hanging: 2420 },
},
},
},
...
],
},
],
},
...
});
``` ```
And then on a `Paragraph`, we can add use the numbering created:
```ts
new Paragraph({
text: "Hey you!",
numbering: {
reference: "my-numbering",
level: 0,
},
}),
```
## Un-ordered lists / Bullet points
Add a `numbering` section to the `Document` to numbering style, define your levels. Use `LevelFormat.BULLET` for the `format` in `levels`:
```ts
const doc = new Document({
...
numbering: {
config: [
{
reference: "my-bullet-points",
levels: [
{
level: 0,
format: LevelFormat.BULLET,
text: "\u1F60",
alignment: AlignmentType.LEFT,
style: {
paragraph: {
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.25) },
},
},
},
],
},
],
},
...
});
```
And then on a `Paragraph`, we can add use the numbering created:
```ts
new Paragraph({
text: "Hey you!",
numbering: {
reference: "my-bullet-points",
level: 0,
},
}),
```
## Full Example
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/3-numbering-and-bullet-points.ts ":include")
_Source: https://github.com/dolanmiu/docx/blob/master/demo/3-numbering-and-bullet-points.ts_

View File

@ -9,11 +9,16 @@
![image](https://user-images.githubusercontent.com/2917613/41195113-65edebfa-6c1f-11e8-97b4-77de2d60044a.png) ![image](https://user-images.githubusercontent.com/2917613/41195113-65edebfa-6c1f-11e8-97b4-77de2d60044a.png)
![image](https://user-images.githubusercontent.com/2917613/41195126-ca99c36c-6c1f-11e8-9e58-19e5f69b3b87.png) ![image](https://user-images.githubusercontent.com/2917613/41195126-ca99c36c-6c1f-11e8-9e58-19e5f69b3b87.png)
*Note*: Font and color selection from the theme are currently not supported.
3. You can even create a totally new `Style`: 3. You can even create a totally new `Style`:
![image](https://user-images.githubusercontent.com/2917613/41195135-f0f7862a-6c1f-11e8-8be4-dd6d8fe5be03.png) ![image](https://user-images.githubusercontent.com/2917613/41195135-f0f7862a-6c1f-11e8-8be4-dd6d8fe5be03.png)
![image](https://user-images.githubusercontent.com/2917613/41195139-0ec52130-6c20-11e8-8fae-f6b44b43fdf8.png) ![image](https://user-images.githubusercontent.com/2917613/41195139-0ec52130-6c20-11e8-8fae-f6b44b43fdf8.png)
*Note*: When selecting the style type, it is important to consider the component being used.
4. Save 4. Save
5. Re-name the saved `.docx` file to `.zip` and un-zip 5. Re-name the saved `.docx` file to `.zip` and un-zip
6. Find `styles.xml` 6. Find `styles.xml`

2022
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,20 +1,17 @@
{ {
"name": "docx", "name": "docx",
"version": "8.2.0", "version": "8.2.3",
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.", "description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
"type": "module", "type": "module",
"main": "build/index.umd.cjs", "main": "build/index.umd.js",
"module": "./build/index.js", "module": "./build/index.mjs",
"types": "./build/index.d.ts", "types": "./build/index.d.ts",
"exports": { "exports": {
".": { ".": {
"browser": {
"default": "./build/index.umd.cjs"
},
"require": "./build/index.cjs", "require": "./build/index.cjs",
"types": "./build/index.d.ts", "types": "./build/index.d.ts",
"import": "./build/index.js", "import": "./build/index.mjs",
"default": "./build/index.js" "default": "./build/index.mjs"
} }
}, },
"files": [ "files": [
@ -58,7 +55,6 @@
], ],
"dependencies": { "dependencies": {
"@types/node": "^20.3.1", "@types/node": "^20.3.1",
"fflate": "^0.8.0",
"jszip": "^3.10.1", "jszip": "^3.10.1",
"nanoid": "^4.0.2", "nanoid": "^4.0.2",
"xml": "^1.0.1", "xml": "^1.0.1",
@ -78,8 +74,8 @@
"@types/xml": "^1.0.8", "@types/xml": "^1.0.8",
"@typescript-eslint/eslint-plugin": "^5.36.1", "@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1", "@typescript-eslint/parser": "^5.36.1",
"@vitest/coverage-v8": "^0.32.0", "@vitest/coverage-v8": "^0.33.0",
"@vitest/ui": "^0.32.0", "@vitest/ui": "^0.33.0",
"cspell": "^6.2.2", "cspell": "^6.2.2",
"docsify-cli": "^4.3.0", "docsify-cli": "^4.3.0",
"eslint": "^8.23.0", "eslint": "^8.23.0",
@ -94,17 +90,17 @@
"inquirer": "^9.2.7", "inquirer": "^9.2.7",
"jsdom": "^22.1.0", "jsdom": "^22.1.0",
"pre-commit": "^1.2.2", "pre-commit": "^1.2.2",
"prettier": "^2.3.1", "prettier": "^3.0.0",
"ts-node": "^10.2.1", "ts-node": "^10.2.1",
"tsconfig-paths": "^4.0.0", "tsconfig-paths": "^4.0.0",
"typedoc": "^0.24.8", "typedoc": "^0.24.8",
"typescript": "5.1.3", "typescript": "5.1.6",
"unzipper": "^0.10.11", "unzipper": "^0.10.11",
"vite": "^4.3.2", "vite": "^4.3.2",
"vite-plugin-dts": "^2.3.0", "vite-plugin-dts": "^3.3.1",
"vite-plugin-node-polyfills": "^0.9.0", "vite-plugin-node-polyfills": "^0.9.0",
"vite-tsconfig-paths": "^4.2.0", "vite-tsconfig-paths": "^4.2.0",
"vitest": "^0.32.0" "vitest": "^0.33.0"
}, },
"engines": { "engines": {
"node": ">=10" "node": ">=10"

View File

@ -17,7 +17,11 @@ export class FooterWrapper implements IViewWrapper {
private readonly footer: Footer; private readonly footer: Footer;
private readonly relationships: Relationships; private readonly relationships: Relationships;
public constructor(private readonly media: Media, referenceId: number, initContent?: XmlComponent) { public constructor(
private readonly media: Media,
referenceId: number,
initContent?: XmlComponent,
) {
this.footer = new Footer(referenceId, initContent); this.footer = new Footer(referenceId, initContent);
this.relationships = new Relationships(); this.relationships = new Relationships();
} }

View File

@ -17,7 +17,11 @@ export class HeaderWrapper implements IViewWrapper {
private readonly header: Header; private readonly header: Header;
private readonly relationships: Relationships; private readonly relationships: Relationships;
public constructor(private readonly media: Media, referenceId: number, initContent?: XmlComponent) { public constructor(
private readonly media: Media,
referenceId: number,
initContent?: XmlComponent,
) {
this.header = new Header(referenceId, initContent); this.header = new Header(referenceId, initContent);
this.relationships = new Relationships(); this.relationships = new Relationships();
} }

View File

@ -53,7 +53,7 @@ export interface PatchDocumentOptions {
const imageReplacer = new ImageReplacer(); const imageReplacer = new ImageReplacer();
export const patchDocument = async (data: InputDataType, options: PatchDocumentOptions): Promise<Buffer> => { export const patchDocument = async (data: InputDataType, options: PatchDocumentOptions): Promise<Uint8Array> => {
const zipContent = await JSZip.loadAsync(data); const zipContent = await JSZip.loadAsync(data);
const contexts = new Map<string, IContext>(); const contexts = new Map<string, IContext>();
const file = { const file = {
@ -68,11 +68,11 @@ export const patchDocument = async (data: InputDataType, options: PatchDocumentO
const hyperlinkRelationshipAdditions: IHyperlinkRelationshipAddition[] = []; const hyperlinkRelationshipAdditions: IHyperlinkRelationshipAddition[] = [];
let hasMedia = false; let hasMedia = false;
const binaryContentMap = new Map<string, Buffer>(); const binaryContentMap = new Map<string, Uint8Array>();
for (const [key, value] of Object.entries(zipContent.files)) { for (const [key, value] of Object.entries(zipContent.files)) {
if (!key.endsWith(".xml") && !key.endsWith(".rels")) { if (!key.endsWith(".xml") && !key.endsWith(".rels")) {
binaryContentMap.set(key, await value.async("nodebuffer")); binaryContentMap.set(key, await value.async("uint8array"));
continue; continue;
} }
@ -213,7 +213,7 @@ export const patchDocument = async (data: InputDataType, options: PatchDocumentO
} }
return zip.generateAsync({ return zip.generateAsync({
type: "nodebuffer", type: "uint8array",
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
compression: "DEFLATE", compression: "DEFLATE",
}); });

View File

@ -9,7 +9,10 @@ export default defineConfig({
tsconfigPaths(), tsconfigPaths(),
dts(), dts(),
nodePolyfills({ nodePolyfills({
exclude: ["fs"], exclude: [],
globals: {
Buffer: false,
},
protocolImports: true, protocolImports: true,
}), }),
], ],
@ -26,7 +29,25 @@ export default defineConfig({
lib: { lib: {
entry: [resolve(__dirname, "src/index.ts")], entry: [resolve(__dirname, "src/index.ts")],
name: "docx", name: "docx",
fileName: "index", fileName: (d) => {
if (d === "umd") {
return "index.umd.js";
}
if (d === "cjs") {
return "index.cjs";
}
if (d === "es") {
return "index.mjs";
}
if (d === "iife") {
return "index.iife.js";
}
return "unknown";
},
formats: ["iife", "es", "cjs", "umd"], formats: ["iife", "es", "cjs", "umd"],
}, },
outDir: resolve(__dirname, "build"), outDir: resolve(__dirname, "build"),