- Feature: added 'rejectNullish' setting. When set to
true
, this setting ensurescreateReport
throws aNullishCommandResultError
when the result of an INS, HTML, IMAGE, or LINK command isnull
orundefined
. This is useful as nullish return values usually indicate a mistake in the template or the invoking code. Defaults tofalse
. - Enhancement: typed Errors to facilitate more fine-grained downstream error handling.
- PR #121 Improved detection of built-in commands in templates to avoid confusion with javascript symbols.
- #107 Library now correctly recognizes user-defined commands with non-alphanumeric names (like Chinese characters).
- #131: .docx template files originating from Office365 or SharePoint can now be used (PR #132)
- #112 Failing on the first error that is encountered while rendering a template is now optional behaviour (but still the default). Use
failFast: false
to collect all errors in a template before failing. This allows for less cumbersome interactive correction of typos or other mistakes in template commands. - #33 SVGs can now be inserted into the templates directly, based on excellent work by @lwallent.
- #113 fixed a regression caused by relying on incomplete jsZip type definitions.
- #83 fixed a bug that occurred when links were used in FOR loops.
- Added docstrings (thanks @mathe42 !)
-
Removed Flow and switched entire codebase over to TypeScript. In the process a few minor soundness issues were fixed.
-
Breaking change Removed dependency on Node filesystem APIs so the library no longer needs a separate node and browser entrypoint, simplifying maintenance and development. This has the following implications for the public API, justifying the version bump to 4.0.0:
-
You can no longer provide image data as a path, and need to provide an
ArrayBuffer
or base64-encoded string instead. -
You can no longer provide a template as a filesystem path, and you'll need to read it into a Buffer first.
-
Removed
output: 'buffer'
argument. The output ofcreateReport
is now always aUint8Array
, unless the debug argument_probe
is specified.
-
The README and examples have also been updated to reflect the above changes.
- Avoid issue when a single paragraph contains
END-IF/FOR
for a previous loop andIF/FOR
for a new one (#72). - Fix hyperlink styles (#64).
- Allow different left/right command delimiters, e.g.
cmdDelimiter: ['{', '}']
(#66, #70). - Allow omission of the
INS
(or=
) command (#70).
- Breaking change: removed
replaceImages
,replaceImagesBase64
options (deprecated since v2.4.0). Please use theIMAGE
command instead. - Breaking change for users of the
vm2
sandbox: replacedvm2Sandbox
option (which caused headaches for users in the browser) withrunJs
, a custom hook for JS snippet execution. If you want to use vm2:
import createReport from 'docx-templates';
import { VM, VMScript } from 'vm2';
createReport({
template: /* ... */,
data: /* ... */,
runJs: ({ sandbox }) => {
const script = new VMScript(
`
__result__ = eval(__code__);
`
).compile();
const vm2 = new VM({ sandbox });
vm2.run(script);
const { VMError, Buffer, ...modifiedSandbox } = vm2._context;
const result = modifiedSandbox.__result__;
return { modifiedSandbox, result };
}
})
- Let alternate text be specified for images (@emilong, #57).
- Fix race condition in which a file was generated and was later used by another section of the processor (added cache in zip module) (should solve #44).
- Accept Buffer in
template
and'buffer'
inoutput
.
- Support
null
as output from a JS snippet in Word (#39).
IMAGE
: add BMP support (#34).
- Add
HTML
command (!!!) (@vdechef, #32). - Fix browser examples by shimming
vm2
(@vdechef, #35).
- Add
LINK
command (!!!) (#20).
- Bugfix: fix multiline query extraction (#21).
- Bugfix: correctly escape output attributes to avoid issues like #24 (watermask).
- Bugfix: avoid messing up of images inserted in the document body with those inserted in the header (#25).
- Add
vm2Sandbox
option for higher security in JS execution (@nheisterkamp, #26).
- Support
IMAGE
command in headers, footers, etc. (#19).
- Add
IMAGE
command (!!!). - Made it a monorepo: main package + examples.
- Deprecates
replaceImages
andreplaceImagesBase64
options (please use theIMAGE
command).
- Compress generated reports to reduce size (@vdechef, #13).
- Add browser support (@vdechef, #10)
- Add
IF
/END-IF
- Bugfix: Remove
babel-polyfill
dependency, replace by the lightweightbabel-runtime
+babel-plugin-transform-runtime
(#7)
- Add
replaceImages
option (including base64 support viareplaceImagesBase64
option) [based on #5]
- Fix a case in which the tool hangs indefinitely when a query is expected and not found.
- [M] Add support for commands in headers, footers and elsewhere
- Breaking changes:
SHORTHAND
has been renamedALIAS
- Alias resolution syntax has changed:
+++[name]+++
is no longer supported; use+++*name+++
instead (for coherence with other commands)
- Non-breaking:
- [M] Add support for JS code in
INS
,VAR
andFOR
- [M] Add
EXEC
command (no output) - [M] Add shorthand notation:
=
forINS
,!
forEXEC
,*
shorthand for alias resolution - [M] Improve robustness:
- Much more robust internal algorithm
- Now allows command delimiters to be split across multiple
w:t
elements+ - Better handling of spaces in commands
- Better handling of spaces in text with interspersed commands
- [M] Process line breaks in input strings correctly, producing
<w:br/>
tags (can be disabled) - [M] Allow insertion of literal XML (with configurable delimiter,
||
by default) - [m] Allow customisation of the command delimiter
- [M] Allow loops in a single paragraph
- [m] Remove archive.bulk() deprecation warning
- [M] Add support for JS code in
- [M] Add docs
- [M] First public release