pptx-templates 0.3.2 → 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 +79 -4
- package/CHANGELOG.md +34 -1
- package/README.md +239 -49
- package/dist/extensions/cli/index.js +4 -0
- package/dist/extensions/cli/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 +23 -1
- package/dist/extensions/template-lint/lint.js +31 -3
- 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.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 +7 -0
- package/dist/extensions/template-logic/expression.js +23 -8
- 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
|
|
|
@@ -1287,6 +1297,71 @@ How paths are counted:
|
|
|
1287
1297
|
- Tags in layouts, masters, notes and charts are not rendered, so they do not
|
|
1288
1298
|
count. Neither does data your own code reads outside the tags.
|
|
1289
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
|
+
|
|
1290
1365
|
## Modify Tables
|
|
1291
1366
|
|
|
1292
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.
|
|
@@ -2577,7 +2652,7 @@ If the output opens with a PowerPoint repair prompt and the checks above don't p
|
|
|
2577
2652
|
2. Remove exotic elements (animations, embedded videos, ThinkCell remnants) from the template.
|
|
2578
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.
|
|
2579
2654
|
|
|
2580
|
-
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.
|
|
2581
2656
|
|
|
2582
2657
|
If none of these could help, please don't hesitate to [talk about it](https://github.com/DaBorsten/pptx-templates/issues/new).
|
|
2583
2658
|
|
|
@@ -2586,8 +2661,8 @@ If none of these could help, please don't hesitate to [talk about it](https://gi
|
|
|
2586
2661
|
You can run all unit tests using these commands:
|
|
2587
2662
|
|
|
2588
2663
|
```
|
|
2589
|
-
|
|
2590
|
-
|
|
2664
|
+
bun run test
|
|
2665
|
+
bun run test-coverage
|
|
2591
2666
|
```
|
|
2592
2667
|
|
|
2593
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,38 @@ 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
|
+
|
|
9
41
|
## [0.3.2] - 2026-11-13
|
|
10
42
|
|
|
11
43
|
### Added
|
|
@@ -201,7 +233,8 @@ for that history.
|
|
|
201
233
|
into one `.png` part. The fallback now gets the same placeholder PNG that
|
|
202
234
|
pptxgenjs 3.12 wrote.
|
|
203
235
|
|
|
204
|
-
[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
|
|
205
238
|
[0.3.2]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.1...v0.3.2
|
|
206
239
|
[0.3.1]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.0...v0.3.1
|
|
207
240
|
[0.3.0]: https://github.com/DaBorsten/pptx-templates/compare/v0.2.1...v0.3.0
|
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,12 +15,14 @@ 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");
|
|
19
20
|
const USAGE = `Usage: pptx-templates <command> [options]
|
|
20
21
|
|
|
21
22
|
Commands:
|
|
22
23
|
lint <file.pptx>... Check the {{…}} tags of templates
|
|
23
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
|
|
24
26
|
|
|
25
27
|
Run pptx-templates <command> --help for the options of a command.`;
|
|
26
28
|
const runCli = (args, io) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -29,6 +31,8 @@ const runCli = (args, io) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
29
31
|
return (0, cli_1.runLintCommand)(rest, io);
|
|
30
32
|
if (command === 'usage')
|
|
31
33
|
return (0, usage_cli_1.runUsageCommand)(rest, io);
|
|
34
|
+
if (command === 'init')
|
|
35
|
+
return (0, init_cli_1.runInitCommand)(rest, io);
|
|
32
36
|
if (command === '-h' || command === '--help') {
|
|
33
37
|
io.stdout(`${USAGE}\n`);
|
|
34
38
|
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;AAE7D,MAAM,KAAK,GAAG
|
|
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"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export { lintTemplate, templateDataUsage } from './lint';
|
|
1
|
+
export { lintTemplate, templateDataSkeleton, templateDataUsage } from './lint';
|
|
2
|
+
export { mergeDataSkeleton } from './skeleton';
|
|
3
|
+
export type { TemplateDataSkeleton } from './skeleton';
|
|
2
4
|
export type { JsonSchema, LintTemplateOptions, TemplateLintIssue, TemplateLintResult, TemplateLintRule, TemplateLintSeverity, } from './types';
|
|
3
5
|
export type { DataUsageEntry, DataUsageLocation, TemplateDataUsage, } from './usage';
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.templateDataUsage = exports.lintTemplate = void 0;
|
|
3
|
+
exports.mergeDataSkeleton = exports.templateDataUsage = exports.templateDataSkeleton = exports.lintTemplate = void 0;
|
|
4
4
|
var lint_1 = require("./lint");
|
|
5
5
|
Object.defineProperty(exports, "lintTemplate", { enumerable: true, get: function () { return lint_1.lintTemplate; } });
|
|
6
|
+
Object.defineProperty(exports, "templateDataSkeleton", { enumerable: true, get: function () { return lint_1.templateDataSkeleton; } });
|
|
6
7
|
Object.defineProperty(exports, "templateDataUsage", { enumerable: true, get: function () { return lint_1.templateDataUsage; } });
|
|
8
|
+
var skeleton_1 = require("./skeleton");
|
|
9
|
+
Object.defineProperty(exports, "mergeDataSkeleton", { enumerable: true, get: function () { return skeleton_1.mergeDataSkeleton; } });
|
|
7
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/template-lint/index.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/template-lint/index.ts"],"names":[],"mappings":";;;AAAA,+BAA+E;AAAtE,oGAAA,YAAY,OAAA;AAAE,4GAAA,oBAAoB,OAAA;AAAE,yGAAA,iBAAiB,OAAA;AAC9D,uCAA+C;AAAtC,6GAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CliIO } from './cli';
|
|
2
|
+
export declare const INIT_USAGE = "Usage: pptx-templates init <file.pptx>... [-o <data.json>] [options]\n pptx-templates init [--config <file.json>] [options]\n\nWrites example data for PowerPoint templates: every field the {{\u2026}} tags\nread, with a placeholder value. Several decks give one combined file.\n\nAn existing data file is completed, not replaced: its values stay, only\nmissing fields are added. Run it again after you add tags.\n\nOptions:\n -o, --out <data.json> Write to this file (default: print the data)\n -c, --config <file.json> Write the data files a config file names, each\n from the decks mapped to it; without files,\n pptx-templates.json in this folder is used\n --opening-tag <text> Tag start (default: {{)\n --closing-tag <text> Tag end (default: }})\n --fix-smart-quotes Accept typographic quotes, like renderTemplate's\n fixSmartQuotes option\n --color / --no-color Force colors on or off\n -h, --help Show this help\n\nPlaceholders: the path as text (\"kunde.name\"), true for values that are only\ntested ({{IF kunde.vip}}), 1 for numbers (preis.toFixed(2), preis * 2), one\nentry for lists ({{FOR p IN produkte}}).\nExit code: 0 done, 2 invalid call or unreadable file.";
|
|
3
|
+
/** `pptx-templates init …`; resolves to the exit code. */
|
|
4
|
+
export declare const runInitCommand: (args: string[], io: CliIO) => Promise<number>;
|