pptx-templates 0.3.1 → 0.3.3
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 +187 -4
- package/CHANGELOG.md +51 -1
- package/README.md +239 -49
- package/dist/extensions/cli/index.js +11 -3
- package/dist/extensions/cli/index.js.map +1 -1
- package/dist/extensions/template-lint/cli.d.ts +57 -2
- package/dist/extensions/template-lint/cli.js +222 -106
- package/dist/extensions/template-lint/cli.js.map +1 -1
- package/dist/extensions/template-lint/config.d.ts +51 -0
- package/dist/extensions/template-lint/config.js +229 -0
- package/dist/extensions/template-lint/config.js.map +1 -0
- package/dist/extensions/template-lint/index.d.ts +4 -1
- package/dist/extensions/template-lint/index.js +5 -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 +34 -0
- package/dist/extensions/template-lint/lint.js +129 -17
- package/dist/extensions/template-lint/lint.js.map +1 -1
- package/dist/extensions/template-lint/skeleton.d.ts +43 -0
- package/dist/extensions/template-lint/skeleton.js +174 -0
- package/dist/extensions/template-lint/skeleton.js.map +1 -0
- package/dist/extensions/template-lint/usage-cli.d.ts +6 -0
- package/dist/extensions/template-lint/usage-cli.js +140 -0
- package/dist/extensions/template-lint/usage-cli.js.map +1 -0
- package/dist/extensions/template-lint/usage.d.ts +49 -0
- package/dist/extensions/template-lint/usage.js +256 -0
- package/dist/extensions/template-lint/usage.js.map +1 -0
- package/dist/extensions/template-lint/watch.d.ts +19 -5
- package/dist/extensions/template-lint/watch.js +41 -14
- package/dist/extensions/template-lint/watch.js.map +1 -1
- package/dist/extensions/template-logic/expression.d.ts +17 -1
- package/dist/extensions/template-logic/expression.js +43 -21
- package/dist/extensions/template-logic/expression.js.map +1 -1
- 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
|
|
|
@@ -934,6 +934,16 @@ To check a template for mistakes before rendering, use the
|
|
|
934
934
|
reject `write()` with an error message that names the tag.
|
|
935
935
|
- Text inserted from your data is never rendered again, so a value that
|
|
936
936
|
contains `{{` stays literal.
|
|
937
|
+
- A tag ends at the first closing delimiter, even inside a string or an
|
|
938
|
+
object literal: `{{'a}}b'}}` and `{{ {a: {b: 1}}.a }}` break, as do
|
|
939
|
+
`${'}'}` with `${`/`}` and `[[ [1, [2]] ]]` with `[[`/`]]`. Pick delimiters
|
|
940
|
+
that don't occur in your expressions. The same applies to text right
|
|
941
|
+
before a tag: in `[[[name]]`, the tag starts at the first `[[`. The
|
|
942
|
+
[linter](https://daborsten.github.io/pptx-templates/template-lint.md) reports both cases.
|
|
943
|
+
- Opening and closing delimiters may differ (`[[`/`]]`, `<%`/`%>`,
|
|
944
|
+
`${`/`}`, `«`/`»`) or be the same (`+++`). Pass the same ones to the
|
|
945
|
+
linter (`--opening-tag`, `--closing-tag`, or `openingTag`/`closingTag` in
|
|
946
|
+
`pptx-templates.json`), or it checks the wrong tags.
|
|
937
947
|
|
|
938
948
|
## Shape Geometry
|
|
939
949
|
|
|
@@ -1102,6 +1112,55 @@ with Ctrl+C.
|
|
|
1102
1112
|
- In a terminal, the screen is cleared before each run.
|
|
1103
1113
|
- `--watch` cannot be combined with `--json`.
|
|
1104
1114
|
|
|
1115
|
+
### Config file
|
|
1116
|
+
|
|
1117
|
+
When decks need different data, list them in `pptx-templates.json`. Each
|
|
1118
|
+
entry pairs a file pattern with the data (or schema) for the decks it
|
|
1119
|
+
matches:
|
|
1120
|
+
|
|
1121
|
+
```text
|
|
1122
|
+
pptx-templates.json
|
|
1123
|
+
data/
|
|
1124
|
+
cover_de.json cover_en.json
|
|
1125
|
+
report_de.json report_en.json
|
|
1126
|
+
customer-a/
|
|
1127
|
+
cover_de.pptx cover_en.pptx
|
|
1128
|
+
report_de.pptx report_en.pptx
|
|
1129
|
+
customer-b/
|
|
1130
|
+
cover_de.pptx cover_en.pptx
|
|
1131
|
+
```
|
|
1132
|
+
|
|
1133
|
+
```json
|
|
1134
|
+
{
|
|
1135
|
+
"templates": [
|
|
1136
|
+
{ "files": "{customer}/cover_{lang}.pptx", "data": "data/cover_{lang}.json" },
|
|
1137
|
+
{ "files": "{customer}/report_{lang}.pptx", "data": "data/report_{lang}.json" }
|
|
1138
|
+
]
|
|
1139
|
+
}
|
|
1140
|
+
```
|
|
1141
|
+
|
|
1142
|
+
```bash
|
|
1143
|
+
npx pptx-templates lint # reads pptx-templates.json in this folder
|
|
1144
|
+
npx pptx-templates lint --watch
|
|
1145
|
+
npx pptx-templates lint --config other.json
|
|
1146
|
+
```
|
|
1147
|
+
|
|
1148
|
+
- `files` is a pattern or a list of patterns, relative to the config file.
|
|
1149
|
+
`*` matches any part of a name, `**` any number of folders, and
|
|
1150
|
+
`{name}` matches like `*` and remembers the part: `data` and `schema`
|
|
1151
|
+
fill it in. Above, `customer-a/cover_en.pptx` gets
|
|
1152
|
+
`data/cover_en.json`.
|
|
1153
|
+
- A pattern that matches no file is fine (customer-b has no report);
|
|
1154
|
+
the command notes it. If no pattern matches anything, that is an error.
|
|
1155
|
+
- Data next to the decks works the same:
|
|
1156
|
+
`{ "files": "{customer}/deck_{lang}.pptx", "data": "{customer}/data_{lang}.json" }`.
|
|
1157
|
+
- A deck that two entries match is an error, so the data is never ambiguous.
|
|
1158
|
+
- Optional top-level `openingTag`, `closingTag` and `fixSmartQuotes` apply to
|
|
1159
|
+
all decks; the same options on the command line win.
|
|
1160
|
+
- With `--watch`, saving any deck, data file or the config file lints again,
|
|
1161
|
+
and new decks or folders that match a pattern are picked up.
|
|
1162
|
+
- Folders starting with `.` and `node_modules` are not searched.
|
|
1163
|
+
|
|
1105
1164
|
## What it checks
|
|
1106
1165
|
|
|
1107
1166
|
| Rule | Severity | Finds |
|
|
@@ -1179,6 +1238,130 @@ If you render with `fixSmartQuotes: true`, lint with the same option
|
|
|
1179
1238
|
(`--fix-smart-quotes` on the command line), so the linter accepts the same
|
|
1180
1239
|
tags as the renderer.
|
|
1181
1240
|
|
|
1241
|
+
## Data usage
|
|
1242
|
+
|
|
1243
|
+
`templateDataUsage` answers the opposite question: which fields of the data
|
|
1244
|
+
do the tags read, and which does no tag read? It shows what a template needs
|
|
1245
|
+
from the data, and what the data could drop.
|
|
1246
|
+
|
|
1247
|
+
```ts
|
|
1248
|
+
import { templateDataUsage } from 'pptx-templates';
|
|
1249
|
+
|
|
1250
|
+
const usage = await templateDataUsage('templates/Offer.pptx', {
|
|
1251
|
+
data: { user: { name: 'Ada', mail: 'ada@example.com' }, items: [{ name: 'Apples', price: 1.5 }] },
|
|
1252
|
+
});
|
|
1253
|
+
// usage.used: [{ path: 'user.name', locations: [{ part: 'ppt/slides/slide1.xml', slide: 1, shape: 'Title' }] },
|
|
1254
|
+
// { path: 'items', … }, { path: 'items[].name', … }, { path: 'items[].price', … }]
|
|
1255
|
+
// usage.unused: ['user.mail']
|
|
1256
|
+
// usage.missing: paths the tags read that are not in the data
|
|
1257
|
+
```
|
|
1258
|
+
|
|
1259
|
+
On the command line:
|
|
1260
|
+
|
|
1261
|
+
```bash
|
|
1262
|
+
npx pptx-templates usage templates/Offer.pptx --data example.json
|
|
1263
|
+
npx pptx-templates usage cover_de.pptx cover_en.pptx --schema data.schema.json
|
|
1264
|
+
```
|
|
1265
|
+
|
|
1266
|
+
```text
|
|
1267
|
+
templates/Offer.pptx
|
|
1268
|
+
used (4)
|
|
1269
|
+
user.name slide 1 › "Title"
|
|
1270
|
+
items slide 2 › "Table"
|
|
1271
|
+
items[].name slide 2 › "Table"
|
|
1272
|
+
items[].price slide 2 › "Table"
|
|
1273
|
+
unused (1)
|
|
1274
|
+
user.mail
|
|
1275
|
+
```
|
|
1276
|
+
|
|
1277
|
+
With several files, a last section lists the fields that none of them
|
|
1278
|
+
reads. With a [config file](#config-file), that section comes once per data
|
|
1279
|
+
file, for the decks that share it (`npx pptx-templates usage` alone reads
|
|
1280
|
+
`pptx-templates.json`). `--json` prints the result as JSON, and `--watch`
|
|
1281
|
+
runs again on every save, as with `lint`. Without `--data` or `--schema`,
|
|
1282
|
+
only the read paths are listed.
|
|
1283
|
+
|
|
1284
|
+
How paths are counted:
|
|
1285
|
+
|
|
1286
|
+
- **Loops and EXEC are traced back to the data.** In
|
|
1287
|
+
`{{FOR p IN items}}{{p.price}}{{END-FOR}}`, `p.price` reads `items[].price`
|
|
1288
|
+
(`[]`: every entry). `{{EXEC a = user.address}}{{a.city}}` reads
|
|
1289
|
+
`user.address.city`.
|
|
1290
|
+
- **Output vs. tested.** A value that is output or passed on as a whole
|
|
1291
|
+
(`{{user}}`, `{{format(user)}}`, `{{items.map(i => i.name)}}`, `{{user[key]}}`)
|
|
1292
|
+
covers every field below it. A value that is only tested (`{{IF user}}`,
|
|
1293
|
+
`{{IF items.length > 0}}`) counts itself, not its fields.
|
|
1294
|
+
- **Unused subtrees are one entry**: `intern` rather than `intern.id`,
|
|
1295
|
+
`intern.note`. `items[]` means no field of any entry is read.
|
|
1296
|
+
- Fields the data shows in only some list entries count for all entries.
|
|
1297
|
+
- Tags in layouts, masters, notes and charts are not rendered, so they do not
|
|
1298
|
+
count. Neither does data your own code reads outside the tags.
|
|
1299
|
+
|
|
1300
|
+
## Example data from the tags
|
|
1301
|
+
|
|
1302
|
+
`templateDataSkeleton` goes the other way: it builds example data from the
|
|
1303
|
+
tags. Every path a tag reads gets a placeholder, so a new template can be
|
|
1304
|
+
linted and rendered before the real data exists. Several decks give one
|
|
1305
|
+
combined object.
|
|
1306
|
+
|
|
1307
|
+
```ts
|
|
1308
|
+
import { templateDataSkeleton } from 'pptx-templates';
|
|
1309
|
+
|
|
1310
|
+
const { data, functions } = await templateDataSkeleton([
|
|
1311
|
+
'templates/Offer.pptx',
|
|
1312
|
+
'templates/Invoice.pptx',
|
|
1313
|
+
]);
|
|
1314
|
+
// data: { user: { name: 'user.name', vip: true },
|
|
1315
|
+
// items: [{ name: 'items[].name', price: 1 }] }
|
|
1316
|
+
// functions: ['money'], called as money(…): pass it as additionalJsContext
|
|
1317
|
+
```
|
|
1318
|
+
|
|
1319
|
+
The placeholders:
|
|
1320
|
+
|
|
1321
|
+
| The tags… | Placeholder |
|
|
1322
|
+
|---|---|
|
|
1323
|
+
| output the value: `{{user.name}}` | its path as text: `"user.name"` |
|
|
1324
|
+
| only test it: `{{IF user.vip}}` | `true` |
|
|
1325
|
+
| call a number method or calculate with it: `{{item.price.toFixed(2)}}`, `{{total * 2}}` | `1` |
|
|
1326
|
+
| loop over it or call a list method: `{{FOR i IN items}}`, `{{tags.join(', ')}}` | a list with one entry |
|
|
1327
|
+
|
|
1328
|
+
Loops and EXEC names are traced back to the data as in
|
|
1329
|
+
[data usage](#data-usage). Names that are called (`{{money(total)}}`) are
|
|
1330
|
+
helpers, not data, and are listed in `functions`; so are methods of an
|
|
1331
|
+
object (`{{user.format()}}` lists `user.format` and gives `user: {}`). A
|
|
1332
|
+
value that is only compared (`{{IF total > 100}}`) counts as tested, and
|
|
1333
|
+
operands of `+` get their path as text. Tags with errors are counted in
|
|
1334
|
+
`errorCount`.
|
|
1335
|
+
|
|
1336
|
+
On the command line:
|
|
1337
|
+
|
|
1338
|
+
```bash
|
|
1339
|
+
npx pptx-templates init templates/Offer.pptx templates/Invoice.pptx # prints the data
|
|
1340
|
+
npx pptx-templates init templates/*.pptx -o data/example.json
|
|
1341
|
+
npx pptx-templates init # every data file of pptx-templates.json
|
|
1342
|
+
```
|
|
1343
|
+
|
|
1344
|
+
```text
|
|
1345
|
+
created data/example.json 2 top-level field(s) from 2 file(s)
|
|
1346
|
+
```
|
|
1347
|
+
|
|
1348
|
+
If the file exists, `init` completes it instead of replacing it: values you
|
|
1349
|
+
filled in stay, only fields that are missing are added, and list entries
|
|
1350
|
+
that are objects each get the missing fields. An empty list stays empty.
|
|
1351
|
+
Run it again after you add tags:
|
|
1352
|
+
|
|
1353
|
+
```text
|
|
1354
|
+
completed data/example.json 1 field(s) added from 2 file(s)
|
|
1355
|
+
+ items[].discount
|
|
1356
|
+
```
|
|
1357
|
+
|
|
1358
|
+
A data file that is not valid JSON is never touched. With a
|
|
1359
|
+
[config file](#config-file), `init` writes each `data` file it names from
|
|
1360
|
+
the decks mapped to it (entries without `data` are skipped), and creates
|
|
1361
|
+
missing folders. The `{name}` placeholders work as for `lint`: with
|
|
1362
|
+
`data/cover_{lang}.json`, all `cover_de.pptx` decks of all customers fill
|
|
1363
|
+
`data/cover_de.json`.
|
|
1364
|
+
|
|
1182
1365
|
## Modify Tables
|
|
1183
1366
|
|
|
1184
1367
|
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.
|
|
@@ -2469,7 +2652,7 @@ If the output opens with a PowerPoint repair prompt and the checks above don't p
|
|
|
2469
2652
|
2. Remove exotic elements (animations, embedded videos, ThinkCell remnants) from the template.
|
|
2470
2653
|
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.
|
|
2471
2654
|
|
|
2472
|
-
Another powerful check: run the repo's [OOXML schema validator](https://daborsten.github.io/pptx-templates/testing.md#ooxml-schema-validation-validatepptx) (`
|
|
2655
|
+
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.
|
|
2473
2656
|
|
|
2474
2657
|
If none of these could help, please don't hesitate to [talk about it](https://github.com/DaBorsten/pptx-templates/issues/new).
|
|
2475
2658
|
|
|
@@ -2478,8 +2661,8 @@ If none of these could help, please don't hesitate to [talk about it](https://gi
|
|
|
2478
2661
|
You can run all unit tests using these commands:
|
|
2479
2662
|
|
|
2480
2663
|
```
|
|
2481
|
-
|
|
2482
|
-
|
|
2664
|
+
bun run test
|
|
2665
|
+
bun run test-coverage
|
|
2483
2666
|
```
|
|
2484
2667
|
|
|
2485
2668
|
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,54 @@ semver, with the pre-1.0 convention that **breaking changes bump the minor**.
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.3.3] - 2026-11-14
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `templateDataSkeleton` and `pptx-templates init`: example data built from
|
|
14
|
+
the tags of one or more templates, every read path with a placeholder
|
|
15
|
+
(the path as text, `true` for tested values, `1` for numbers, a
|
|
16
|
+
one-entry list for loops). Several decks give one combined file. An
|
|
17
|
+
existing data file is completed, not replaced: its values stay, missing
|
|
18
|
+
fields are added. Without file arguments, `init` writes every data file
|
|
19
|
+
of `pptx-templates.json` from the decks mapped to it. Called names
|
|
20
|
+
(`{{money(x)}}`) are reported as helpers instead of data.
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- Docs site: new design. One neutral grey scale with an orange accent used
|
|
25
|
+
sparingly, Geist and Geist Mono (self-hosted), framed code panels with a
|
|
26
|
+
quiet syntax theme, restyled sidebar, table of contents, tables and
|
|
27
|
+
footer, and a matching dark mode. The sidebar is grouped into sections
|
|
28
|
+
(Get started, Modify content, Templates, Build decks, Help, Reference);
|
|
29
|
+
the navbar shows the version and npm/GitHub as icons. URLs, llms.txt and
|
|
30
|
+
the Markdown twins are unchanged.
|
|
31
|
+
- npm package page links the docs site (`homepage` in `package.json`)
|
|
32
|
+
instead of the GitHub README.
|
|
33
|
+
- README rewritten around templating in the .pptx file: tags, tables,
|
|
34
|
+
linter, then the code API. New npm `description` and `keywords`.
|
|
35
|
+
- Removed the `npm audit` / `image-size` note from README and Getting
|
|
36
|
+
started: since 0.2.1 the package no longer installs `image-size`.
|
|
37
|
+
- Docs: installing the package shows npm and Bun, working on a clone of
|
|
38
|
+
the repository (install, dev, tests, validation) uses Bun instead of
|
|
39
|
+
Yarn.
|
|
40
|
+
|
|
41
|
+
## [0.3.2] - 2026-11-13
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
- `templateDataUsage` and `pptx-templates usage`: which fields of the data
|
|
46
|
+
the tags of a template read, which fields no tag reads, and which read
|
|
47
|
+
paths are not in the data. Loop variables and EXEC names are traced back
|
|
48
|
+
to the data (`produkte[].preis`); with several files, the command also
|
|
49
|
+
lists the fields none of them reads. Supports `--json` and `--watch`.
|
|
50
|
+
- Config file `pptx-templates.json` for `lint` and `usage`: file patterns,
|
|
51
|
+
each with its own data or schema. `{name}` placeholders carry parts of
|
|
52
|
+
the deck path into the data path (`{customer}/cover_{lang}.pptx` →
|
|
53
|
+
`data/cover_{lang}.json`). Without file arguments, the commands read
|
|
54
|
+
`pptx-templates.json` from the current folder; `--watch` picks up new
|
|
55
|
+
decks and folders that match.
|
|
56
|
+
|
|
9
57
|
## [0.3.1] - 2026-11-13
|
|
10
58
|
|
|
11
59
|
### Added
|
|
@@ -185,7 +233,9 @@ for that history.
|
|
|
185
233
|
into one `.png` part. The fallback now gets the same placeholder PNG that
|
|
186
234
|
pptxgenjs 3.12 wrote.
|
|
187
235
|
|
|
188
|
-
[Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.
|
|
236
|
+
[Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.3...HEAD
|
|
237
|
+
[0.3.3]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.2...v0.3.3
|
|
238
|
+
[0.3.2]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.1...v0.3.2
|
|
189
239
|
[0.3.1]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.0...v0.3.1
|
|
190
240
|
[0.3.0]: https://github.com/DaBorsten/pptx-templates/compare/v0.2.1...v0.3.0
|
|
191
241
|
[0.2.1]: https://github.com/DaBorsten/pptx-templates/compare/v0.2.0...v0.2.1
|
package/README.md
CHANGED
|
@@ -1,87 +1,277 @@
|
|
|
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
|
+
- A `pptx-templates.json` maps many decks to their data, for example one data
|
|
194
|
+
file per language for every customer folder:
|
|
195
|
+
|
|
196
|
+
```json
|
|
197
|
+
{
|
|
198
|
+
"templates": [
|
|
199
|
+
{ "files": "{customer}/cover_{lang}.pptx", "data": "data/cover_{lang}.json" }
|
|
200
|
+
]
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Both commands are also available from code:
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
import { lintTemplate, listTemplateCommands } from 'pptx-templates';
|
|
208
|
+
|
|
209
|
+
const { issues, errorCount } = await lintTemplate('templates/Offer.pptx', {
|
|
210
|
+
data: { customer: { name: 'Ada', vip: true }, items: [] },
|
|
53
211
|
});
|
|
212
|
+
const commands = await listTemplateCommands('templates/Offer.pptx');
|
|
213
|
+
```
|
|
54
214
|
|
|
55
|
-
|
|
56
|
-
.loadRoot('RootTemplate.pptx')
|
|
57
|
-
.load('SlideWithGraph.pptx', 'graph')
|
|
58
|
-
.load('SlideWithShapes.pptx', 'shapes');
|
|
215
|
+
More in [Template Linter](https://daborsten.github.io/pptx-templates/template-lint).
|
|
59
216
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
217
|
+
## When tags are not enough
|
|
218
|
+
|
|
219
|
+
Charts, images and shape geometry are easier to set from code. Every slide
|
|
220
|
+
callback can change single shapes by the name they have in PowerPoint's
|
|
221
|
+
Selection Pane:
|
|
65
222
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
223
|
+
```ts
|
|
224
|
+
pres.addSlide('offer', 1, (slide) => {
|
|
225
|
+
slide.modifyElement('Title', modify.setText('Offer 2026'));
|
|
226
|
+
slide.modifyElement('Logo', modify.setCornerRadius('10%'));
|
|
227
|
+
});
|
|
70
228
|
```
|
|
71
229
|
|
|
72
|
-
The
|
|
230
|
+
The [`modify.*` helpers](https://daborsten.github.io/pptx-templates/helpers)
|
|
231
|
+
fill [charts](https://daborsten.github.io/pptx-templates/charts) and
|
|
232
|
+
[tables](https://daborsten.github.io/pptx-templates/tables), swap
|
|
233
|
+
[images](https://daborsten.github.io/pptx-templates/images), crop pictures to
|
|
234
|
+
[any preset shape](https://daborsten.github.io/pptx-templates/shape-geometry)
|
|
235
|
+
and move or resize elements. For shapes that don't exist in any template,
|
|
236
|
+
[PptxGenJS is built in](https://daborsten.github.io/pptx-templates/generation).
|
|
237
|
+
|
|
238
|
+
## How it compares
|
|
239
|
+
|
|
240
|
+
| | pptx-templates | [PptxGenJS](https://github.com/gitbrent/PptxGenJS) | [pptx-automizer](https://github.com/singerla/pptx-automizer) |
|
|
241
|
+
|---|---|---|---|
|
|
242
|
+
| Slide design lives in | the .pptx, edited in PowerPoint | your code | the .pptx |
|
|
243
|
+
| Text logic | tags in the slide: `IF`, `FOR`, … | your code | a callback per shape, simple `{{tag}}` replacement |
|
|
244
|
+
| Repeat table rows from a list | `{{FOR}}` in the row | your code | from code |
|
|
245
|
+
| Template linter | yes | no | no |
|
|
246
|
+
|
|
247
|
+
Pick PptxGenJS when there is no designed template and the code should draw
|
|
248
|
+
every slide. Pick `pptx-templates` when someone designs the slides in
|
|
249
|
+
PowerPoint and your code only brings the data.
|
|
250
|
+
|
|
251
|
+
## Documentation
|
|
252
|
+
|
|
253
|
+
Guides for every feature and the API reference are at
|
|
254
|
+
**[daborsten.github.io/pptx-templates](https://daborsten.github.io/pptx-templates/)**.
|
|
73
255
|
|
|
74
|
-
|
|
256
|
+
Using an AI assistant? Point it to
|
|
257
|
+
[AI-INSTRUCTOR.md](https://github.com/DaBorsten/pptx-templates/blob/main/AI-INSTRUCTOR.md),
|
|
258
|
+
a condensed guide to the whole library that ships with the npm package.
|
|
75
259
|
|
|
76
|
-
##
|
|
260
|
+
## Contributing
|
|
77
261
|
|
|
78
|
-
|
|
262
|
+
Bug reports, ideas and pull requests are welcome:
|
|
263
|
+
[open an issue](https://github.com/DaBorsten/pptx-templates/issues/new). For a
|
|
264
|
+
security problem, follow the
|
|
265
|
+
[security policy](https://github.com/DaBorsten/pptx-templates/blob/main/SECURITY.md)
|
|
266
|
+
instead.
|
|
79
267
|
|
|
80
|
-
|
|
268
|
+
## Credits
|
|
81
269
|
|
|
82
|
-
|
|
270
|
+
`pptx-templates` is a fork of [pptx-automizer](https://github.com/singerla/pptx-automizer),
|
|
271
|
+
which copies slides and edits the OOXML underneath. The tag syntax comes from
|
|
272
|
+
[docx-templates](https://github.com/guigrpa/docx-templates), so if you fill
|
|
273
|
+
Word templates that way, you already know it.
|
|
83
274
|
|
|
84
|
-
|
|
275
|
+
## License
|
|
85
276
|
|
|
86
|
-
|
|
87
|
-
- [docx-templates](https://github.com/guigrpa/docx-templates)
|
|
277
|
+
MIT
|
|
@@ -15,16 +15,24 @@ 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
|
|
18
|
+
const init_cli_1 = require("../template-lint/init-cli");
|
|
19
|
+
const usage_cli_1 = require("../template-lint/usage-cli");
|
|
20
|
+
const USAGE = `Usage: pptx-templates <command> [options]
|
|
19
21
|
|
|
20
22
|
Commands:
|
|
21
|
-
lint <file.pptx>...
|
|
23
|
+
lint <file.pptx>... Check the {{…}} tags of templates
|
|
24
|
+
usage <file.pptx>... Show which data fields the tags read, and which not
|
|
25
|
+
init <file.pptx>... Write example data with every field the tags read
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+
Run pptx-templates <command> --help for the options of a command.`;
|
|
24
28
|
const runCli = (args, io) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
29
|
const [command, ...rest] = args;
|
|
26
30
|
if (command === 'lint')
|
|
27
31
|
return (0, cli_1.runLintCommand)(rest, io);
|
|
32
|
+
if (command === 'usage')
|
|
33
|
+
return (0, usage_cli_1.runUsageCommand)(rest, io);
|
|
34
|
+
if (command === 'init')
|
|
35
|
+
return (0, init_cli_1.runInitCommand)(rest, io);
|
|
28
36
|
if (command === '-h' || command === '--help') {
|
|
29
37
|
io.stdout(`${USAGE}\n`);
|
|
30
38
|
return 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/cli/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/cli/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA;;GAEG;AACH,8CAA4E;AAC5E,wDAA2D;AAC3D,0DAA6D;AAE7D,MAAM,KAAK,GAAG;;;;;;;kEAOoD,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,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;AAfW,QAAA,MAAM,UAejB;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"}
|