pptx-templates 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AI-INSTRUCTOR.md +147 -7
- package/CHANGELOG.md +55 -1
- package/README.md +242 -49
- package/dist/extensions/cli/index.js +8 -0
- package/dist/extensions/cli/index.js.map +1 -1
- package/dist/extensions/index.d.ts +2 -0
- package/dist/extensions/index.js +3 -1
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/template-lint/index.d.ts +3 -1
- package/dist/extensions/template-lint/index.js +4 -1
- package/dist/extensions/template-lint/index.js.map +1 -1
- package/dist/extensions/template-lint/init-cli.d.ts +4 -0
- package/dist/extensions/template-lint/init-cli.js +244 -0
- package/dist/extensions/template-lint/init-cli.js.map +1 -0
- package/dist/extensions/template-lint/lint.d.ts +25 -1
- package/dist/extensions/template-lint/lint.js +37 -4
- package/dist/extensions/template-lint/lint.js.map +1 -1
- package/dist/extensions/template-lint/skeleton.d.ts +51 -0
- package/dist/extensions/template-lint/skeleton.js +199 -0
- package/dist/extensions/template-lint/skeleton.js.map +1 -0
- package/dist/extensions/template-lint/usage.d.ts +1 -0
- package/dist/extensions/template-lint/usage.js +4 -3
- package/dist/extensions/template-lint/usage.js.map +1 -1
- package/dist/extensions/template-logic/expression.d.ts +13 -0
- package/dist/extensions/template-logic/expression.js +53 -8
- package/dist/extensions/template-logic/expression.js.map +1 -1
- package/dist/extensions/template-logic/images.d.ts +6 -2
- package/dist/extensions/template-logic/images.js +62 -12
- package/dist/extensions/template-logic/images.js.map +1 -1
- package/dist/extensions/template-logic/renderer.js +1 -1
- package/dist/extensions/template-logic/renderer.js.map +1 -1
- package/dist/extensions/template-logic/types.d.ts +15 -2
- package/dist/extensions/template-render/cli.d.ts +6 -0
- package/dist/extensions/template-render/cli.js +205 -0
- package/dist/extensions/template-render/cli.js.map +1 -0
- package/dist/extensions/template-render/index.d.ts +19 -0
- package/dist/extensions/template-render/index.js +129 -0
- package/dist/extensions/template-render/index.js.map +1 -0
- package/package.json +14 -15
package/AI-INSTRUCTOR.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<!-- GENERATED FILE — do not edit AI-INSTRUCTOR.md directly.
|
|
2
2
|
Source: tools/ai-instructor/template.md + the docs/ pages it includes.
|
|
3
|
-
Rebuild:
|
|
3
|
+
Rebuild: bun run docs:ai (drift is caught by __tests__/ai-instructor.test.ts) -->
|
|
4
4
|
|
|
5
5
|
# AI Instructor: Generating PowerPoint with pptx-templates
|
|
6
6
|
|
|
@@ -751,7 +751,26 @@ tables) are not commands: `renderTemplate` leaves them in the text, so
|
|
|
751
751
|
|
|
752
752
|
### Images
|
|
753
753
|
|
|
754
|
-
`{{IMAGE …}}` takes an object like in docx-templates
|
|
754
|
+
`{{IMAGE …}}` takes the picture itself or an object like in docx-templates.
|
|
755
|
+
The picture can be a `Buffer`, a data URL, or a file path relative to the
|
|
756
|
+
`imageRoot` option, so the template needs no code:
|
|
757
|
+
|
|
758
|
+
```ts
|
|
759
|
+
import fs from 'fs';
|
|
760
|
+
import { renderDeck } from 'pptx-templates';
|
|
761
|
+
|
|
762
|
+
await renderDeck('templates/Offer.pptx', {
|
|
763
|
+
vip: true,
|
|
764
|
+
logoVip: fs.readFileSync('images/vip.png'), // a Buffer …
|
|
765
|
+
logoStandard: 'images/standard.png', // … or a path below imageRoot
|
|
766
|
+
}, { imageRoot: process.cwd() });
|
|
767
|
+
```
|
|
768
|
+
|
|
769
|
+
```text
|
|
770
|
+
{{IF vip}}{{IMAGE logoVip}}{{ELSE}}{{IMAGE logoStandard}}{{END-IF}}
|
|
771
|
+
```
|
|
772
|
+
|
|
773
|
+
The object form adds size, shape and border:
|
|
755
774
|
|
|
756
775
|
```ts
|
|
757
776
|
import fs from 'fs';
|
|
@@ -776,8 +795,8 @@ pres.addSlide('TextReplace.pptx', 1, (slide) => {
|
|
|
776
795
|
|
|
777
796
|
| Property | Effect |
|
|
778
797
|
|---|---|
|
|
779
|
-
| `data` | `Buffer`, `ArrayBuffer`, base64 string
|
|
780
|
-
| `extension` | `.png`, `.jpg`, `.jpeg` or `.gif`. Optional
|
|
798
|
+
| `data` | `Buffer`, `ArrayBuffer`, base64 string, data URL (`data:image/png;base64,…`) or file path below `imageRoot` (`images/logo.png`) |
|
|
799
|
+
| `extension` | `.png`, `.jpg`, `.jpeg` or `.gif`. Optional: taken from a data URL or path, else from the first bytes of the data |
|
|
781
800
|
| `width`, `height` | Size in cm. With only one of them, the other keeps the aspect ratio. Without both, the picture fits into the shape, keeping its aspect ratio |
|
|
782
801
|
| `alt` | Alternative text |
|
|
783
802
|
| `rotation` | Rotation in degrees, clockwise |
|
|
@@ -794,6 +813,10 @@ the shape is removed and only the pictures remain.
|
|
|
794
813
|
|
|
795
814
|
- The shape needs its own position and size. Placeholders that inherit
|
|
796
815
|
them from the layout are not supported.
|
|
816
|
+
- A string that ends in `.png`, `.jpg`, `.jpeg` or `.gif` is a file path
|
|
817
|
+
(base64 has no dot). It is read from `imageRoot` and cannot leave that
|
|
818
|
+
folder; without `imageRoot` it is an error. `null`, `undefined` and `''`
|
|
819
|
+
place nothing.
|
|
797
820
|
- `IMAGE` in table cells is not supported.
|
|
798
821
|
- Identical images are stored only once in the output.
|
|
799
822
|
- `IMAGE` writes a media file, so it needs `slide.modify(modify.renderTemplate(…))`.
|
|
@@ -906,6 +929,47 @@ pres.addSlide('TextReplace.pptx', 1, (slide) => {
|
|
|
906
929
|
| `failFast` | `true` | `false`: keep going and throw one error listing all failed commands at the end |
|
|
907
930
|
| `processLineBreaks` | `true` | Turn `\n` in inserted values into line breaks |
|
|
908
931
|
| `fixSmartQuotes` | `false` | Replace typographic quotes (`“ ” „ ‘ ’ ‚`) with straight ones before parsing, as in docx-templates |
|
|
932
|
+
| `imageRoot` | | Folder that file paths in `{{IMAGE}}` values are read from (`"images/logo.png"`). Paths cannot leave it |
|
|
933
|
+
|
|
934
|
+
### Rendering a whole deck
|
|
935
|
+
|
|
936
|
+
When every slide of a template is filled with the same data, `renderDeck`
|
|
937
|
+
saves the `addSlide` loop: it renders the tags of each slide and returns the
|
|
938
|
+
new .pptx as a `Buffer`. Masters, layouts and the slide order stay as they
|
|
939
|
+
are in the template.
|
|
940
|
+
|
|
941
|
+
```ts
|
|
942
|
+
import fs from 'fs';
|
|
943
|
+
import { renderDeck } from 'pptx-templates';
|
|
944
|
+
|
|
945
|
+
const pptx = await renderDeck(
|
|
946
|
+
'templates/Offer.pptx',
|
|
947
|
+
{ customer: { name: 'Ada', vip: true }, items: [] },
|
|
948
|
+
{ additionalJsContext: { euro: (n: number) => `${n.toFixed(2)} €` } },
|
|
949
|
+
);
|
|
950
|
+
fs.writeFileSync('output/Offer-Ada.pptx', pptx);
|
|
951
|
+
```
|
|
952
|
+
|
|
953
|
+
It takes the [options](#options) of `renderTemplate`, plus `slides` to keep
|
|
954
|
+
only some slides in a new order (`slides: [3, 1]`). A tag that fails rejects
|
|
955
|
+
with a `TemplateRenderError` whose message starts with the slide number:
|
|
956
|
+
`slide 2: {{euro(p.preis)}}: Not a function …`.
|
|
957
|
+
|
|
958
|
+
The same from the command line:
|
|
959
|
+
|
|
960
|
+
```bash
|
|
961
|
+
npx pptx-templates render templates/Offer.pptx --data data.json -o output/Offer-Ada.pptx
|
|
962
|
+
npx pptx-templates render templates/Offer.pptx --data data.json --helpers helpers.js -o out.pptx --slides 3,1
|
|
963
|
+
```
|
|
964
|
+
|
|
965
|
+
Picture paths in the data (`{ "logo": "images/logo.png" }` with
|
|
966
|
+
`{{IMAGE logo}}`) are read relative to the folder of the data file;
|
|
967
|
+
`--image-root <dir>` sets another folder.
|
|
968
|
+
|
|
969
|
+
`--helpers` loads a JavaScript module whose exports the tags can call, such
|
|
970
|
+
as `module.exports = { euro: (n) => n.toFixed(2) + ' €' }`. It runs as code,
|
|
971
|
+
so only pass files you trust. The exit code is `0` when the file was written,
|
|
972
|
+
`1` when a tag failed and `2` for an invalid call or an unreadable file.
|
|
909
973
|
|
|
910
974
|
### Listing the commands of a template
|
|
911
975
|
|
|
@@ -934,6 +998,16 @@ To check a template for mistakes before rendering, use the
|
|
|
934
998
|
reject `write()` with an error message that names the tag.
|
|
935
999
|
- Text inserted from your data is never rendered again, so a value that
|
|
936
1000
|
contains `{{` stays literal.
|
|
1001
|
+
- A tag ends at the first closing delimiter, even inside a string or an
|
|
1002
|
+
object literal: `{{'a}}b'}}` and `{{ {a: {b: 1}}.a }}` break, as do
|
|
1003
|
+
`${'}'}` with `${`/`}` and `[[ [1, [2]] ]]` with `[[`/`]]`. Pick delimiters
|
|
1004
|
+
that don't occur in your expressions. The same applies to text right
|
|
1005
|
+
before a tag: in `[[[name]]`, the tag starts at the first `[[`. The
|
|
1006
|
+
[linter](https://daborsten.github.io/pptx-templates/template-lint.md) reports both cases.
|
|
1007
|
+
- Opening and closing delimiters may differ (`[[`/`]]`, `<%`/`%>`,
|
|
1008
|
+
`${`/`}`, `«`/`»`) or be the same (`+++`). Pass the same ones to the
|
|
1009
|
+
linter (`--opening-tag`, `--closing-tag`, or `openingTag`/`closingTag` in
|
|
1010
|
+
`pptx-templates.json`), or it checks the wrong tags.
|
|
937
1011
|
|
|
938
1012
|
## Shape Geometry
|
|
939
1013
|
|
|
@@ -1287,6 +1361,72 @@ How paths are counted:
|
|
|
1287
1361
|
- Tags in layouts, masters, notes and charts are not rendered, so they do not
|
|
1288
1362
|
count. Neither does data your own code reads outside the tags.
|
|
1289
1363
|
|
|
1364
|
+
## Example data from the tags
|
|
1365
|
+
|
|
1366
|
+
`templateDataSkeleton` goes the other way: it builds example data from the
|
|
1367
|
+
tags. Every path a tag reads gets a placeholder, so a new template can be
|
|
1368
|
+
linted and rendered before the real data exists. Several decks give one
|
|
1369
|
+
combined object.
|
|
1370
|
+
|
|
1371
|
+
```ts
|
|
1372
|
+
import { templateDataSkeleton } from 'pptx-templates';
|
|
1373
|
+
|
|
1374
|
+
const { data, functions } = await templateDataSkeleton([
|
|
1375
|
+
'templates/Offer.pptx',
|
|
1376
|
+
'templates/Invoice.pptx',
|
|
1377
|
+
]);
|
|
1378
|
+
// data: { user: { name: 'user.name', vip: true },
|
|
1379
|
+
// items: [{ name: 'items[].name', price: 1 }] }
|
|
1380
|
+
// functions: ['money'], called as money(…): pass it as additionalJsContext
|
|
1381
|
+
```
|
|
1382
|
+
|
|
1383
|
+
The placeholders:
|
|
1384
|
+
|
|
1385
|
+
| The tags… | Placeholder |
|
|
1386
|
+
|---|---|
|
|
1387
|
+
| output the value: `{{user.name}}` | its path as text: `"user.name"` |
|
|
1388
|
+
| only test it: `{{IF user.vip}}` | `true` |
|
|
1389
|
+
| call a number method or calculate with it: `{{item.price.toFixed(2)}}`, `{{total * 2}}` | `1` |
|
|
1390
|
+
| loop over it or call a list method: `{{FOR i IN items}}`, `{{tags.join(', ')}}` | a list with one entry |
|
|
1391
|
+
| place it as a picture: `{{IMAGE logo}}`, `{{IMAGE ({ data: logo })}}` | `null`, and the path is listed in `images` |
|
|
1392
|
+
|
|
1393
|
+
Loops and EXEC names are traced back to the data as in
|
|
1394
|
+
[data usage](#data-usage). Names that are called (`{{money(total)}}`) are
|
|
1395
|
+
helpers, not data, and are listed in `functions`; so are methods of an
|
|
1396
|
+
object (`{{user.format()}}` lists `user.format` and gives `user: {}`). A
|
|
1397
|
+
value that is only compared (`{{IF total > 100}}`) counts as tested, and
|
|
1398
|
+
operands of `+` get their path as text. Tags with errors are counted in
|
|
1399
|
+
`errorCount`.
|
|
1400
|
+
|
|
1401
|
+
On the command line:
|
|
1402
|
+
|
|
1403
|
+
```bash
|
|
1404
|
+
npx pptx-templates init templates/Offer.pptx templates/Invoice.pptx # prints the data
|
|
1405
|
+
npx pptx-templates init templates/*.pptx -o data/example.json
|
|
1406
|
+
npx pptx-templates init # every data file of pptx-templates.json
|
|
1407
|
+
```
|
|
1408
|
+
|
|
1409
|
+
```text
|
|
1410
|
+
created data/example.json 2 top-level field(s) from 2 file(s)
|
|
1411
|
+
```
|
|
1412
|
+
|
|
1413
|
+
If the file exists, `init` completes it instead of replacing it: values you
|
|
1414
|
+
filled in stay, only fields that are missing are added, and list entries
|
|
1415
|
+
that are objects each get the missing fields. An empty list stays empty.
|
|
1416
|
+
Run it again after you add tags:
|
|
1417
|
+
|
|
1418
|
+
```text
|
|
1419
|
+
completed data/example.json 1 field(s) added from 2 file(s)
|
|
1420
|
+
+ items[].discount
|
|
1421
|
+
```
|
|
1422
|
+
|
|
1423
|
+
A data file that is not valid JSON is never touched. With a
|
|
1424
|
+
[config file](#config-file), `init` writes each `data` file it names from
|
|
1425
|
+
the decks mapped to it (entries without `data` are skipped), and creates
|
|
1426
|
+
missing folders. The `{name}` placeholders work as for `lint`: with
|
|
1427
|
+
`data/cover_{lang}.json`, all `cover_de.pptx` decks of all customers fill
|
|
1428
|
+
`data/cover_de.json`.
|
|
1429
|
+
|
|
1290
1430
|
## Modify Tables
|
|
1291
1431
|
|
|
1292
1432
|
You can use a PowerPoint table and add/modify data and style. It is also possible to add rows and columns and to style cells.
|
|
@@ -2577,7 +2717,7 @@ If the output opens with a PowerPoint repair prompt and the checks above don't p
|
|
|
2577
2717
|
2. Remove exotic elements (animations, embedded videos, ThinkCell remnants) from the template.
|
|
2578
2718
|
3. Isolate the failing slide by bisecting your `addSlide` calls — comment out half of them, re-run, and narrow down until the offending slide (or modification) is found.
|
|
2579
2719
|
|
|
2580
|
-
Another powerful check: run the repo's [OOXML schema validator](https://daborsten.github.io/pptx-templates/testing.md#ooxml-schema-validation-validatepptx) (`
|
|
2720
|
+
Another powerful check: run the repo's [OOXML schema validator](https://daborsten.github.io/pptx-templates/testing.md#ooxml-schema-validation-validatepptx) (`bun run validate:pptx`) on your output — it usually names the exact part and element PowerPoint chokes on.
|
|
2581
2721
|
|
|
2582
2722
|
If none of these could help, please don't hesitate to [talk about it](https://github.com/DaBorsten/pptx-templates/issues/new).
|
|
2583
2723
|
|
|
@@ -2586,8 +2726,8 @@ If none of these could help, please don't hesitate to [talk about it](https://gi
|
|
|
2586
2726
|
You can run all unit tests using these commands:
|
|
2587
2727
|
|
|
2588
2728
|
```
|
|
2589
|
-
|
|
2590
|
-
|
|
2729
|
+
bun run test
|
|
2730
|
+
bun run test-coverage
|
|
2591
2731
|
```
|
|
2592
2732
|
|
|
2593
2733
|
See [Testing and Validation Tools](https://daborsten.github.io/pptx-templates/testing.md) for the full test system — archive invariants, the docs-examples compile gate, schema validation and visual regression.
|
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,58 @@ semver, with the pre-1.0 convention that **breaking changes bump the minor**.
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.3.4] - 2026-11-15
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `renderDeck` and `pptx-templates render`: fill the tags of every slide of
|
|
14
|
+
a template with one set of data and get the new .pptx, without writing the
|
|
15
|
+
`addSlide` loop. `slides` (`--slides 3,1`) keeps only some slides, in that
|
|
16
|
+
order; `--helpers` loads a module whose exports the tags can call. A
|
|
17
|
+
failing tag names its slide (`slide 2: {{euro(p.preis)}}: …`); the command
|
|
18
|
+
exits with `1` then.
|
|
19
|
+
- `{{IMAGE logo}}`: the value can be the picture itself (a Buffer, a data
|
|
20
|
+
URL or a file path) instead of `{ data, extension }`. A path such as
|
|
21
|
+
`"images/logo.png"` is read from the new `imageRoot` option and cannot
|
|
22
|
+
leave that folder; `pptx-templates render` uses the folder of the data
|
|
23
|
+
file, `--image-root` another one. `extension` is optional everywhere: the
|
|
24
|
+
type comes from the first bytes of the data.
|
|
25
|
+
- `templateDataSkeleton` lists the paths `{{IMAGE}}` places in `images`
|
|
26
|
+
(also `({ data: x })` and both sides of `a ? b : c`) and gives them
|
|
27
|
+
`null` instead of their path as text.
|
|
28
|
+
|
|
29
|
+
## [0.3.3] - 2026-11-14
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
|
|
33
|
+
- `templateDataSkeleton` and `pptx-templates init`: example data built from
|
|
34
|
+
the tags of one or more templates, every read path with a placeholder
|
|
35
|
+
(the path as text, `true` for tested values, `1` for numbers, a
|
|
36
|
+
one-entry list for loops). Several decks give one combined file. An
|
|
37
|
+
existing data file is completed, not replaced: its values stay, missing
|
|
38
|
+
fields are added. Without file arguments, `init` writes every data file
|
|
39
|
+
of `pptx-templates.json` from the decks mapped to it. Called names
|
|
40
|
+
(`{{money(x)}}`) are reported as helpers instead of data.
|
|
41
|
+
|
|
42
|
+
### Changed
|
|
43
|
+
|
|
44
|
+
- Docs site: new design. One neutral grey scale with an orange accent used
|
|
45
|
+
sparingly, Geist and Geist Mono (self-hosted), framed code panels with a
|
|
46
|
+
quiet syntax theme, restyled sidebar, table of contents, tables and
|
|
47
|
+
footer, and a matching dark mode. The sidebar is grouped into sections
|
|
48
|
+
(Get started, Modify content, Templates, Build decks, Help, Reference);
|
|
49
|
+
the navbar shows the version and npm/GitHub as icons. URLs, llms.txt and
|
|
50
|
+
the Markdown twins are unchanged.
|
|
51
|
+
- npm package page links the docs site (`homepage` in `package.json`)
|
|
52
|
+
instead of the GitHub README.
|
|
53
|
+
- README rewritten around templating in the .pptx file: tags, tables,
|
|
54
|
+
linter, then the code API. New npm `description` and `keywords`.
|
|
55
|
+
- Removed the `npm audit` / `image-size` note from README and Getting
|
|
56
|
+
started: since 0.2.1 the package no longer installs `image-size`.
|
|
57
|
+
- Docs: installing the package shows npm and Bun, working on a clone of
|
|
58
|
+
the repository (install, dev, tests, validation) uses Bun instead of
|
|
59
|
+
Yarn.
|
|
60
|
+
|
|
9
61
|
## [0.3.2] - 2026-11-13
|
|
10
62
|
|
|
11
63
|
### Added
|
|
@@ -201,7 +253,9 @@ for that history.
|
|
|
201
253
|
into one `.png` part. The fallback now gets the same placeholder PNG that
|
|
202
254
|
pptxgenjs 3.12 wrote.
|
|
203
255
|
|
|
204
|
-
[Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.
|
|
256
|
+
[Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.4...HEAD
|
|
257
|
+
[0.3.4]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.3...v0.3.4
|
|
258
|
+
[0.3.3]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.2...v0.3.3
|
|
205
259
|
[0.3.2]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.1...v0.3.2
|
|
206
260
|
[0.3.1]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.0...v0.3.1
|
|
207
261
|
[0.3.0]: https://github.com/DaBorsten/pptx-templates/compare/v0.2.1...v0.3.0
|
package/README.md
CHANGED
|
@@ -1,87 +1,280 @@
|
|
|
1
|
-
# pptx-templates
|
|
1
|
+
# pptx-templates
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/pptx-templates)
|
|
4
4
|
[](https://github.com/DaBorsten/pptx-templates/actions/workflows/ci.yml)
|
|
5
5
|
[](https://github.com/DaBorsten/pptx-templates/blob/main/LICENSE)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
**Fill PowerPoint templates with data.** Design the slide in PowerPoint, type
|
|
8
|
+
`{{tags}}` into it, and render it from JavaScript or TypeScript.
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
```text
|
|
11
|
+
Offer for {{customer.name}} Offer for Ada
|
|
12
|
+
{{FOR item IN items}} → Apples: 1.50 €
|
|
13
|
+
{{item.name}}: {{item.price.toFixed(2)}} € Pears: 2.00 €
|
|
14
|
+
{{END-FOR}}
|
|
15
|
+
```
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
The library edits your .pptx instead of rebuilding it. Fonts, colors,
|
|
18
|
+
positions, masters and layouts stay exactly as the designer left
|
|
19
|
+
them, and the designer can change the template later without touching your
|
|
20
|
+
code.
|
|
12
21
|
|
|
13
|
-
|
|
22
|
+
- **Logic in the slide**: values, `IF`/`ELSE`, `FOR` loops over paragraphs and
|
|
23
|
+
table rows, variables, HTML, links and images, all written as text in
|
|
24
|
+
PowerPoint
|
|
25
|
+
- **One slide per record**: render the same template slide for every customer,
|
|
26
|
+
project or month into one deck
|
|
27
|
+
- **A linter for templates**: `npx pptx-templates lint` finds broken tags,
|
|
28
|
+
unclosed blocks and misspelled field names before you render, also in CI and
|
|
29
|
+
in watch mode while the deck is open in PowerPoint
|
|
30
|
+
- **Safe expressions**: tags run in a small interpreter, not `eval`, and can't
|
|
31
|
+
reach Node.js
|
|
32
|
+
- **Charts, tables and images from code** when a tag is not enough
|
|
33
|
+
- TypeScript types included, runs on Node.js 20+ and Bun, MIT licensed
|
|
14
34
|
|
|
15
|
-
|
|
35
|
+
## Installation
|
|
16
36
|
|
|
17
|
-
|
|
18
|
-
- Modify [Text](https://daborsten.github.io/pptx-templates/text) · [Tables](https://daborsten.github.io/pptx-templates/tables) · [Charts](https://daborsten.github.io/pptx-templates/charts) · [Images](https://daborsten.github.io/pptx-templates/images) · [Masters & Layouts](https://daborsten.github.io/pptx-templates/masters-layouts)
|
|
19
|
-
- [Generate shapes with PptxGenJS](https://daborsten.github.io/pptx-templates/generation) · [Hyperlinks](https://daborsten.github.io/pptx-templates/hyperlinks) · [Slide management](https://daborsten.github.io/pptx-templates/slide-management)
|
|
20
|
-
- [Helper utilities](https://daborsten.github.io/pptx-templates/helpers) · [Output](https://daborsten.github.io/pptx-templates/output) · [Requirements and limitations](https://daborsten.github.io/pptx-templates/limitations) · [Troubleshooting](https://daborsten.github.io/pptx-templates/troubleshooting)
|
|
21
|
-
- [API reference](https://daborsten.github.io/pptx-templates/api)
|
|
37
|
+
With npm:
|
|
22
38
|
|
|
23
|
-
|
|
39
|
+
```bash
|
|
40
|
+
npm install pptx-templates
|
|
41
|
+
```
|
|
24
42
|
|
|
25
|
-
|
|
43
|
+
With Bun:
|
|
26
44
|
|
|
45
|
+
```bash
|
|
46
|
+
bun add pptx-templates
|
|
27
47
|
```
|
|
28
|
-
|
|
48
|
+
|
|
49
|
+
## Quick start
|
|
50
|
+
|
|
51
|
+
**1. Write the template.** Put this into a text box on slide 1 of
|
|
52
|
+
`templates/Offer.pptx` and format it however you like:
|
|
53
|
+
|
|
54
|
+
```text
|
|
55
|
+
Offer for {{customer.name}}
|
|
56
|
+
{{IF customer.vip}}
|
|
57
|
+
Thank you for being a loyal customer.
|
|
58
|
+
{{ELSE}}
|
|
59
|
+
Have a look at our new offers.
|
|
60
|
+
{{END-IF}}
|
|
61
|
+
{{FOR item IN items}}
|
|
62
|
+
{{$idx + 1}}. {{item.name}}: {{item.price.toFixed(2)}} €
|
|
63
|
+
{{END-FOR}}
|
|
29
64
|
```
|
|
30
65
|
|
|
31
|
-
|
|
66
|
+
**2. Render it.**
|
|
32
67
|
|
|
68
|
+
```ts
|
|
69
|
+
import Automizer, { modify } from 'pptx-templates';
|
|
70
|
+
|
|
71
|
+
const pres = new Automizer({
|
|
72
|
+
templateDir: 'templates',
|
|
73
|
+
outputDir: 'output',
|
|
74
|
+
removeExistingSlides: true,
|
|
75
|
+
})
|
|
76
|
+
.loadRoot('Offer.pptx')
|
|
77
|
+
.load('Offer.pptx', 'offer');
|
|
78
|
+
|
|
79
|
+
const data = {
|
|
80
|
+
customer: { name: 'Ada', vip: true },
|
|
81
|
+
items: [
|
|
82
|
+
{ name: 'Apples', price: 1.5 },
|
|
83
|
+
{ name: 'Pears', price: 2 },
|
|
84
|
+
],
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
pres.addSlide('offer', 1, (slide) => {
|
|
88
|
+
// renders every text box and table on the slide
|
|
89
|
+
slide.modify(modify.renderTemplate(data));
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
await pres.write('Offer-Ada.pptx');
|
|
33
93
|
```
|
|
34
|
-
|
|
94
|
+
|
|
95
|
+
**3. Open `output/Offer-Ada.pptx`.** The text box now reads:
|
|
96
|
+
|
|
97
|
+
```text
|
|
98
|
+
Offer for Ada
|
|
99
|
+
Thank you for being a loyal customer.
|
|
100
|
+
1. Apples: 1.50 €
|
|
101
|
+
2. Pears: 2.00 €
|
|
35
102
|
```
|
|
36
103
|
|
|
37
|
-
|
|
104
|
+
Lines that held only control tags (`IF`, `END-IF`, `FOR`, …) are gone, and
|
|
105
|
+
every inserted value has the formatting of the tag it replaced.
|
|
38
106
|
|
|
39
|
-
|
|
107
|
+
## One slide per record
|
|
40
108
|
|
|
41
|
-
|
|
109
|
+
Add the same template slide once per entry. Each copy gets its own data:
|
|
42
110
|
|
|
43
111
|
```ts
|
|
44
|
-
|
|
112
|
+
const customers = [
|
|
113
|
+
{ name: 'Ada', vip: true },
|
|
114
|
+
{ name: 'Grace', vip: false },
|
|
115
|
+
];
|
|
45
116
|
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
117
|
+
for (const customer of customers) {
|
|
118
|
+
pres.addSlide('offer', 1, (slide) => {
|
|
119
|
+
slide.modify(modify.renderTemplate({ customer, items: [] }));
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
await pres.write('All-Offers.pptx');
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Load several template files and mix their slides to build a full deck: a
|
|
127
|
+
title slide from one file, a chart slide from another, a closing slide from a
|
|
128
|
+
third.
|
|
129
|
+
|
|
130
|
+
## Tags
|
|
131
|
+
|
|
132
|
+
| Tag | Effect |
|
|
133
|
+
|---|---|
|
|
134
|
+
| `{{expr}}` | Insert a value. `\n` becomes a line break, arrays are joined with `, ` |
|
|
135
|
+
| `{{IF expr}}` … `{{ELSE-IF expr}}` … `{{ELSE}}` … `{{END-IF}}` | Keep the first branch whose condition is true |
|
|
136
|
+
| `{{FOR item IN list}}` … `{{END-FOR}}` | Repeat paragraphs or table rows. `$idx` is the index |
|
|
137
|
+
| `{{EXEC total = 0}}`, `{{! total = total + x}}` | Set variables for the rest of the slide |
|
|
138
|
+
| `{{ALIAS name command}}`, `{{*name}}` | Shorthand for a command you use often |
|
|
139
|
+
| `{{HTML expr}}` | Insert HTML as formatted text: bold, italic, lists, links |
|
|
140
|
+
| `{{LINK expr}}` | Insert a hyperlink, to a URL or to a slide of the output |
|
|
141
|
+
| `{{IMAGE expr}}` | Place a picture where the text box is, optionally cropped to a shape with a border |
|
|
142
|
+
|
|
143
|
+
Expressions are JavaScript without the dangerous parts: property paths,
|
|
144
|
+
comparisons, `&&`, `||`, `??`, `? :`, arrow functions
|
|
145
|
+
(`items.filter(i => i.active)`), methods of the values (`name.toUpperCase()`)
|
|
146
|
+
and functions you pass in the data.
|
|
147
|
+
|
|
148
|
+
**Table rows** repeat when `{{FOR}}` opens in the first cell and
|
|
149
|
+
`{{END-FOR}}` closes in the last cell of the same row:
|
|
150
|
+
|
|
151
|
+
| `{{FOR p IN products}}{{p.name}}` | `{{p.price}} €{{END-FOR}}` |
|
|
152
|
+
|---|---|
|
|
153
|
+
|
|
154
|
+
**Watch out for smart quotes.** `{{IF name == 'Ada'}}` needs straight
|
|
155
|
+
quotes, and PowerPoint turns them into `‘Ada’` as you type. Either turn
|
|
156
|
+
AutoCorrect off (*File › Options › Proofing › AutoCorrect Options... ›
|
|
157
|
+
AutoFormat As You Type > Replace as you type > "Straight quotes" with ‟smart quotes“*) or render with
|
|
158
|
+
`modify.renderTemplate(data, { fixSmartQuotes: true })`, which straightens
|
|
159
|
+
them before parsing. The linter finds tags where it already happened.
|
|
160
|
+
|
|
161
|
+
Full reference: [Template Logic](https://daborsten.github.io/pptx-templates/template-logic).
|
|
162
|
+
|
|
163
|
+
## Check templates before you render
|
|
164
|
+
|
|
165
|
+
Templates get edited in PowerPoint, often by people who never run the code.
|
|
166
|
+
The linter reports what they broke, slide by slide, with the wrong part
|
|
167
|
+
underlined:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
npx pptx-templates lint templates/*.pptx --data example.json
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
```text
|
|
174
|
+
Offer.pptx
|
|
175
|
+
slide 1 › "Price"
|
|
176
|
+
error Unterminated string in template expression "item.price.toFixed(2) + ' €" (syntax)
|
|
177
|
+
tag: {{item.price.toFixed(2) + ' €}}
|
|
178
|
+
~~~
|
|
179
|
+
|
|
180
|
+
1 problem(s): 1 error(s), 0 warning(s)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
It finds unclosed `IF`/`FOR` blocks, tags split by a line break and quotes
|
|
184
|
+
replaced by AutoCorrect. With example data or a JSON Schema, it also finds
|
|
185
|
+
misspelled field names (`user.nmae` → *did you mean "name"?*).
|
|
186
|
+
|
|
187
|
+
- `--watch` lints again every time you press Ctrl+S in PowerPoint.
|
|
188
|
+
- The exit code fails a CI job when a template is broken.
|
|
189
|
+
- `npx pptx-templates usage` lists which data fields the tags read, and which
|
|
190
|
+
ones no tag reads.
|
|
191
|
+
- `npx pptx-templates init` writes example data with every field the tags
|
|
192
|
+
read, combined over several decks; run again, it only adds what is missing.
|
|
193
|
+
- `npx pptx-templates render deck.pptx --data data.json -o out.pptx` fills
|
|
194
|
+
every slide with the data, to see the result without writing code
|
|
195
|
+
(`renderDeck()` from code).
|
|
196
|
+
- A `pptx-templates.json` maps many decks to their data, for example one data
|
|
197
|
+
file per language for every customer folder:
|
|
198
|
+
|
|
199
|
+
```json
|
|
200
|
+
{
|
|
201
|
+
"templates": [
|
|
202
|
+
{ "files": "{customer}/cover_{lang}.pptx", "data": "data/cover_{lang}.json" }
|
|
203
|
+
]
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Both commands are also available from code:
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
import { lintTemplate, listTemplateCommands } from 'pptx-templates';
|
|
211
|
+
|
|
212
|
+
const { issues, errorCount } = await lintTemplate('templates/Offer.pptx', {
|
|
213
|
+
data: { customer: { name: 'Ada', vip: true }, items: [] },
|
|
53
214
|
});
|
|
215
|
+
const commands = await listTemplateCommands('templates/Offer.pptx');
|
|
216
|
+
```
|
|
54
217
|
|
|
55
|
-
|
|
56
|
-
.loadRoot('RootTemplate.pptx')
|
|
57
|
-
.load('SlideWithGraph.pptx', 'graph')
|
|
58
|
-
.load('SlideWithShapes.pptx', 'shapes');
|
|
218
|
+
More in [Template Linter](https://daborsten.github.io/pptx-templates/template-lint).
|
|
59
219
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
220
|
+
## When tags are not enough
|
|
221
|
+
|
|
222
|
+
Charts, images and shape geometry are easier to set from code. Every slide
|
|
223
|
+
callback can change single shapes by the name they have in PowerPoint's
|
|
224
|
+
Selection Pane:
|
|
65
225
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
226
|
+
```ts
|
|
227
|
+
pres.addSlide('offer', 1, (slide) => {
|
|
228
|
+
slide.modifyElement('Title', modify.setText('Offer 2026'));
|
|
229
|
+
slide.modifyElement('Logo', modify.setCornerRadius('10%'));
|
|
230
|
+
});
|
|
70
231
|
```
|
|
71
232
|
|
|
72
|
-
The
|
|
233
|
+
The [`modify.*` helpers](https://daborsten.github.io/pptx-templates/helpers)
|
|
234
|
+
fill [charts](https://daborsten.github.io/pptx-templates/charts) and
|
|
235
|
+
[tables](https://daborsten.github.io/pptx-templates/tables), swap
|
|
236
|
+
[images](https://daborsten.github.io/pptx-templates/images), crop pictures to
|
|
237
|
+
[any preset shape](https://daborsten.github.io/pptx-templates/shape-geometry)
|
|
238
|
+
and move or resize elements. For shapes that don't exist in any template,
|
|
239
|
+
[PptxGenJS is built in](https://daborsten.github.io/pptx-templates/generation).
|
|
240
|
+
|
|
241
|
+
## How it compares
|
|
242
|
+
|
|
243
|
+
| | pptx-templates | [PptxGenJS](https://github.com/gitbrent/PptxGenJS) | [pptx-automizer](https://github.com/singerla/pptx-automizer) |
|
|
244
|
+
|---|---|---|---|
|
|
245
|
+
| Slide design lives in | the .pptx, edited in PowerPoint | your code | the .pptx |
|
|
246
|
+
| Text logic | tags in the slide: `IF`, `FOR`, … | your code | a callback per shape, simple `{{tag}}` replacement |
|
|
247
|
+
| Repeat table rows from a list | `{{FOR}}` in the row | your code | from code |
|
|
248
|
+
| Template linter | yes | no | no |
|
|
249
|
+
|
|
250
|
+
Pick PptxGenJS when there is no designed template and the code should draw
|
|
251
|
+
every slide. Pick `pptx-templates` when someone designs the slides in
|
|
252
|
+
PowerPoint and your code only brings the data.
|
|
253
|
+
|
|
254
|
+
## Documentation
|
|
255
|
+
|
|
256
|
+
Guides for every feature and the API reference are at
|
|
257
|
+
**[daborsten.github.io/pptx-templates](https://daborsten.github.io/pptx-templates/)**.
|
|
73
258
|
|
|
74
|
-
|
|
259
|
+
Using an AI assistant? Point it to
|
|
260
|
+
[AI-INSTRUCTOR.md](https://github.com/DaBorsten/pptx-templates/blob/main/AI-INSTRUCTOR.md),
|
|
261
|
+
a condensed guide to the whole library that ships with the npm package.
|
|
75
262
|
|
|
76
|
-
##
|
|
263
|
+
## Contributing
|
|
77
264
|
|
|
78
|
-
|
|
265
|
+
Bug reports, ideas and pull requests are welcome:
|
|
266
|
+
[open an issue](https://github.com/DaBorsten/pptx-templates/issues/new). For a
|
|
267
|
+
security problem, follow the
|
|
268
|
+
[security policy](https://github.com/DaBorsten/pptx-templates/blob/main/SECURITY.md)
|
|
269
|
+
instead.
|
|
79
270
|
|
|
80
|
-
|
|
271
|
+
## Credits
|
|
81
272
|
|
|
82
|
-
|
|
273
|
+
`pptx-templates` is a fork of [pptx-automizer](https://github.com/singerla/pptx-automizer),
|
|
274
|
+
which copies slides and edits the OOXML underneath. The tag syntax comes from
|
|
275
|
+
[docx-templates](https://github.com/guigrpa/docx-templates), so if you fill
|
|
276
|
+
Word templates that way, you already know it.
|
|
83
277
|
|
|
84
|
-
|
|
278
|
+
## License
|
|
85
279
|
|
|
86
|
-
|
|
87
|
-
- [docx-templates](https://github.com/guigrpa/docx-templates)
|
|
280
|
+
MIT
|
|
@@ -15,12 +15,16 @@ exports.runCli = void 0;
|
|
|
15
15
|
* `npx pptx-templates <command>` (the package's `bin`). Fork extension.
|
|
16
16
|
*/
|
|
17
17
|
const cli_1 = require("../template-lint/cli");
|
|
18
|
+
const init_cli_1 = require("../template-lint/init-cli");
|
|
18
19
|
const usage_cli_1 = require("../template-lint/usage-cli");
|
|
20
|
+
const cli_2 = require("../template-render/cli");
|
|
19
21
|
const USAGE = `Usage: pptx-templates <command> [options]
|
|
20
22
|
|
|
21
23
|
Commands:
|
|
22
24
|
lint <file.pptx>... Check the {{…}} tags of templates
|
|
23
25
|
usage <file.pptx>... Show which data fields the tags read, and which not
|
|
26
|
+
init <file.pptx>... Write example data with every field the tags read
|
|
27
|
+
render <file.pptx> Fill the tags with data and write a new .pptx
|
|
24
28
|
|
|
25
29
|
Run pptx-templates <command> --help for the options of a command.`;
|
|
26
30
|
const runCli = (args, io) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -29,6 +33,10 @@ const runCli = (args, io) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
29
33
|
return (0, cli_1.runLintCommand)(rest, io);
|
|
30
34
|
if (command === 'usage')
|
|
31
35
|
return (0, usage_cli_1.runUsageCommand)(rest, io);
|
|
36
|
+
if (command === 'init')
|
|
37
|
+
return (0, init_cli_1.runInitCommand)(rest, io);
|
|
38
|
+
if (command === 'render')
|
|
39
|
+
return (0, cli_2.runRenderCommand)(rest, io);
|
|
32
40
|
if (command === '-h' || command === '--help') {
|
|
33
41
|
io.stdout(`${USAGE}\n`);
|
|
34
42
|
return 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/cli/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA;;GAEG;AACH,8CAA4E;AAC5E,0DAA6D;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/cli/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA;;GAEG;AACH,8CAA4E;AAC5E,wDAA2D;AAC3D,0DAA6D;AAC7D,gDAA0D;AAE1D,MAAM,KAAK,GAAG;;;;;;;;kEAQoD,CAAC;AAE5D,MAAM,MAAM,GAAG,CAAO,IAAc,EAAE,EAAS,EAAmB,EAAE;IACzE,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAChC,IAAI,OAAO,KAAK,MAAM;QAAE,OAAO,IAAA,oBAAc,EAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACxD,IAAI,OAAO,KAAK,OAAO;QAAE,OAAO,IAAA,2BAAe,EAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC1D,IAAI,OAAO,KAAK,MAAM;QAAE,OAAO,IAAA,yBAAc,EAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACxD,IAAI,OAAO,KAAK,QAAQ;QAAE,OAAO,IAAA,sBAAgB,EAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC5D,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC7C,EAAE,CAAC,MAAM,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC;QACxB,OAAO,CAAC,CAAC;IACX,CAAC;IACD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,EAAE,CAAC,MAAM,CAAC,wBAAwB,KAAK,IAAI,CAAC,CAAC;QAC7C,OAAO,CAAC,CAAC;IACX,CAAC;IACD,EAAE,CAAC,MAAM,CAAC,oBAAoB,OAAO,SAAS,KAAK,IAAI,CAAC,CAAC;IACzD,OAAO,CAAC,CAAC;AACX,CAAC,CAAA,CAAC;AAhBW,QAAA,MAAM,UAgBjB;AAEF,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC5B,IAAA,cAAM,EAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;QAC5B,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;QAC5C,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;QAC5C,KAAK,EAAE,IAAA,mBAAa,GAAE;QACtB,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK;KACpC,CAAC,CAAC,IAAI,CACL,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,EACnC,CAAC,KAAK,EAAE,EAAE;;QACR,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,mCAAI,KAAK,IAAI,CAAC,CAAC;QACnD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -6,5 +6,7 @@ export declare const extensionModifiers: {
|
|
|
6
6
|
};
|
|
7
7
|
export * from './template-logic';
|
|
8
8
|
export * from './template-lint';
|
|
9
|
+
export { renderDeck } from './template-render';
|
|
10
|
+
export type { RenderDeckOptions } from './template-render';
|
|
9
11
|
export { ShapePresets } from './shape-geometry';
|
|
10
12
|
export type { ShapePreset, RoundedShapePreset, CornerRadius, ShapeAdjustments, ImageBorder, } from './shape-geometry';
|