pptx-templates 0.1.3 → 0.2.0
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 +152 -2
- package/CHANGELOG.md +36 -1
- package/README.md +2 -0
- package/dist/extensions/cli/index.d.ts +6 -0
- package/dist/extensions/cli/index.js +51 -0
- package/dist/extensions/cli/index.js.map +1 -0
- package/dist/extensions/index.d.ts +3 -1
- package/dist/extensions/index.js +1 -0
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/template-lint/cli.d.ts +15 -0
- package/dist/extensions/template-lint/cli.js +226 -0
- package/dist/extensions/template-lint/cli.js.map +1 -0
- package/dist/extensions/template-lint/data-model.d.ts +43 -0
- package/dist/extensions/template-lint/data-model.js +289 -0
- package/dist/extensions/template-lint/data-model.js.map +1 -0
- package/dist/extensions/template-lint/hints.d.ts +5 -0
- package/dist/extensions/template-lint/hints.js +66 -0
- package/dist/extensions/template-lint/hints.js.map +1 -0
- package/dist/extensions/template-lint/index.d.ts +2 -0
- package/dist/extensions/template-lint/index.js +6 -0
- package/dist/extensions/template-lint/index.js.map +1 -0
- package/dist/extensions/template-lint/lint.d.ts +11 -0
- package/dist/extensions/template-lint/lint.js +596 -0
- package/dist/extensions/template-lint/lint.js.map +1 -0
- package/dist/extensions/template-lint/types.d.ts +82 -0
- package/dist/extensions/template-lint/types.js +3 -0
- package/dist/extensions/template-lint/types.js.map +1 -0
- package/dist/extensions/template-logic/commands.d.ts +11 -0
- package/dist/extensions/template-logic/commands.js +14 -1
- package/dist/extensions/template-logic/commands.js.map +1 -1
- package/dist/extensions/template-logic/expression.d.ts +40 -3
- package/dist/extensions/template-logic/expression.js +139 -39
- package/dist/extensions/template-logic/expression.js.map +1 -1
- package/dist/extensions/template-logic/list-commands.js +6 -1
- package/dist/extensions/template-logic/list-commands.js.map +1 -1
- package/dist/extensions/template-logic/renderer.js +14 -3
- package/dist/extensions/template-logic/renderer.js.map +1 -1
- package/dist/extensions/template-logic/types.d.ts +7 -0
- package/dist/index.d.ts +1 -1
- package/package.json +12 -10
package/AI-INSTRUCTOR.md
CHANGED
|
@@ -742,6 +742,10 @@ way keeps or removes the row. A row that holds nothing but control tags is
|
|
|
742
742
|
dropped. `ELSE` cannot span rows. Merged cells (`rowSpan`) are not adjusted,
|
|
743
743
|
and the table frame's height is set to the sum of its row heights.
|
|
744
744
|
|
|
745
|
+
Markers like `{{each:row}}` for `modify.setTable`'s `expand` (nested
|
|
746
|
+
tables) are not commands: `renderTemplate` leaves them in the text, so
|
|
747
|
+
`setTable` still finds them.
|
|
748
|
+
|
|
745
749
|
### Images
|
|
746
750
|
|
|
747
751
|
`{{IMAGE …}}` takes an object like in docx-templates:
|
|
@@ -805,8 +809,20 @@ your own functions (passed in `data`) and methods of the values
|
|
|
805
809
|
They are evaluated by a small built-in interpreter, not with `eval`, so a
|
|
806
810
|
template cannot run arbitrary code: there are no assignments outside `EXEC`,
|
|
807
811
|
no `new`, and keys like `constructor`, `prototype` or `__proto__` are
|
|
808
|
-
rejected.
|
|
809
|
-
|
|
812
|
+
rejected.
|
|
813
|
+
|
|
814
|
+
Strings need straight quotes: `'Ada'` (or `"Ada"`). PowerPoint's AutoCorrect
|
|
815
|
+
replaces typed quotes with typographic ones (`’Ada’`, `“Ada”`), which are a
|
|
816
|
+
syntax error. Switch that off once in *File › Options › Proofing ›
|
|
817
|
+
AutoCorrect Options › AutoFormat As You Type › "Straight quotes" with "smart
|
|
818
|
+
quotes"*. The [template linter](https://daborsten.github.io/pptx-templates/template-lint.md) finds tags that already
|
|
819
|
+
contain typographic quotes.
|
|
820
|
+
|
|
821
|
+
As in docx-templates, the `fixSmartQuotes` option replaces typographic
|
|
822
|
+
quotes with straight ones before a command is parsed (`“ ” „` → `"`,
|
|
823
|
+
`‘ ’ ‚` → `'`). The replacement covers the whole command, including quotes
|
|
824
|
+
inside a string: `{{'Ada’s'}}` then becomes `'Ada's'` and fails. Guillemets
|
|
825
|
+
(`»Ada«`) are not replaced.
|
|
810
826
|
|
|
811
827
|
Wrap an object literal in parentheses: `{{LINK ({ url: x })}}`. Without them,
|
|
812
828
|
the `}}` of the object closes the tag.
|
|
@@ -850,6 +866,7 @@ pres.addSlide('TextReplace.pptx', 1, (slide) => {
|
|
|
850
866
|
| `errorHandler(error, command)` | | Called when a command fails. Its return value is used instead (inserted text, condition, list, …) |
|
|
851
867
|
| `failFast` | `true` | `false`: keep going and throw one error listing all failed commands at the end |
|
|
852
868
|
| `processLineBreaks` | `true` | Turn `\n` in inserted values into line breaks |
|
|
869
|
+
| `fixSmartQuotes` | `false` | Replace typographic quotes (`“ ” „ ‘ ’ ‚`) with straight ones before parsing, as in docx-templates |
|
|
853
870
|
|
|
854
871
|
### Listing the commands of a template
|
|
855
872
|
|
|
@@ -864,6 +881,9 @@ const commands = await listTemplateCommands('templates/Offer.pptx');
|
|
|
864
881
|
// [{ slide: 1, shape: 'Title', raw: '{{IF user.vip}}', type: 'IF', code: 'user.vip' }, …]
|
|
865
882
|
```
|
|
866
883
|
|
|
884
|
+
To check a template for mistakes before rendering, use the
|
|
885
|
+
[template linter](https://daborsten.github.io/pptx-templates/template-lint.md).
|
|
886
|
+
|
|
867
887
|
### Good to know
|
|
868
888
|
|
|
869
889
|
- PowerPoint often splits text into several runs, even inside a tag (spell
|
|
@@ -968,6 +988,136 @@ and `border`.
|
|
|
968
988
|
{{IMAGE ({ data: logo, extension: '.png', width: 4, cornerRadius: '10%', border: { color: '#1f4e79', width: 2 } })}}
|
|
969
989
|
```
|
|
970
990
|
|
|
991
|
+
## Template Linter
|
|
992
|
+
|
|
993
|
+
A mistake in a [template](https://daborsten.github.io/pptx-templates/template-logic.md) usually shows up only when you
|
|
994
|
+
render it: an `{{IF}}` without `{{END-IF}}`, a typo in a variable name, or a
|
|
995
|
+
quote that PowerPoint's AutoCorrect turned into `’`. `lintTemplate` reads a
|
|
996
|
+
.pptx and reports these problems up front, slide by slide and shape by shape.
|
|
997
|
+
|
|
998
|
+
```ts
|
|
999
|
+
import { lintTemplate } from 'pptx-templates';
|
|
1000
|
+
|
|
1001
|
+
const { issues, errorCount } = await lintTemplate('templates/Offer.pptx', {
|
|
1002
|
+
data: { user: { name: 'Ada', vip: true }, items: [{ name: 'Apples', price: 1.5 }] },
|
|
1003
|
+
});
|
|
1004
|
+
// [{ severity: 'warning', rule: 'unknown-property', slide: 2, shape: 'Title',
|
|
1005
|
+
// tag: '{{user.nmae}}', range: { start: 7, end: 11 },
|
|
1006
|
+
// message: '"nmae" does not exist on "user" (object); did you mean "name"?',
|
|
1007
|
+
// part: 'ppt/slides/slide2.xml' }, …]
|
|
1008
|
+
```
|
|
1009
|
+
|
|
1010
|
+
`range` marks the characters of `tag` the issue is about (0-based, `end`
|
|
1011
|
+
exclusive): the unterminated string, the unexpected character, the unknown
|
|
1012
|
+
property. Where there is nothing more precise, for an unclosed block, say,
|
|
1013
|
+
it covers the whole tag.
|
|
1014
|
+
|
|
1015
|
+
### Command line
|
|
1016
|
+
|
|
1017
|
+
```bash
|
|
1018
|
+
npx pptx-templates lint deck.pptx
|
|
1019
|
+
npx pptx-templates lint templates/*.pptx --data example.json
|
|
1020
|
+
npx pptx-templates lint deck.pptx --schema data.schema.json --max-warnings 0
|
|
1021
|
+
npx pptx-templates lint deck.pptx --json
|
|
1022
|
+
```
|
|
1023
|
+
|
|
1024
|
+
The output underlines the part of the tag that is wrong:
|
|
1025
|
+
|
|
1026
|
+
```text
|
|
1027
|
+
deck.pptx
|
|
1028
|
+
slide 1 › "Textfeld 3"
|
|
1029
|
+
error Unterminated string in template expression "euro(p.preis) + 'Test`" (syntax)
|
|
1030
|
+
tag: {{euro(p.preis) + 'Test`}}
|
|
1031
|
+
~~~~~~
|
|
1032
|
+
```
|
|
1033
|
+
|
|
1034
|
+
In a terminal, errors and the underline are red, warnings yellow, and the
|
|
1035
|
+
rule name and `tag:`/`hint:` labels dimmed. Colors are off when the output is
|
|
1036
|
+
piped, when `NO_COLOR` is set, or with `--no-color`; `--color` or
|
|
1037
|
+
`FORCE_COLOR=1` turns them on, for CI logs that render ANSI.
|
|
1038
|
+
|
|
1039
|
+
The exit code is `0` without errors, `1` with errors (or more warnings than
|
|
1040
|
+
`--max-warnings`) and `2` for an invalid call or an unreadable file, so the
|
|
1041
|
+
command can run in CI. `--opening-tag` and `--closing-tag` set other
|
|
1042
|
+
delimiters.
|
|
1043
|
+
|
|
1044
|
+
## What it checks
|
|
1045
|
+
|
|
1046
|
+
| Rule | Severity | Finds |
|
|
1047
|
+
|---|---|---|
|
|
1048
|
+
| `syntax` | error | Tags that cannot be parsed. The hint names the usual cause: quotes or characters replaced by AutoCorrect (`(c)` → `©`, `...` → `…`, `->` → `→`), `=` instead of `==`, `AND` instead of `&&`, a misspelled command (`{{END IF}}`, `{{FOR x items}}`). Also blocked keys like `constructor` or `__proto__`, which `renderTemplate` would only reject while rendering |
|
|
1049
|
+
| `unterminated-tag` | error | `{{` without `}}` or the other way round. Often a tag split by a line break (Shift+Enter) or by Enter. Such text stays in the output as it is |
|
|
1050
|
+
| `unclosed-block` | error | `IF`/`FOR` without `END-IF`/`END-FOR` in the same shape or table |
|
|
1051
|
+
| `unmatched-tag` | error | `END-IF`, `END-FOR`, `ELSE`, `ELSE-IF` without an opening tag, or an `ELSE` after `ELSE` |
|
|
1052
|
+
| `unknown-alias` | error | `{{*name}}` without `{{ALIAS name …}}` on the slide |
|
|
1053
|
+
| `unsupported-location` | error | `IMAGE` in a table cell, `IMAGE` in a placeholder that inherits its position from the layout, `ELSE` that spans table rows |
|
|
1054
|
+
| `unsupported-location` | warning | Tags in slide layouts, masters, speaker notes, charts and SmartArt. `renderTemplate` does not render them, so they stay as they are |
|
|
1055
|
+
| `unknown-variable` | warning | A name that is not in `data`/`schema`/`additionalJsContext` and not defined by `FOR`, `EXEC` or an arrow function |
|
|
1056
|
+
| `unknown-property` | warning | A property path that does not exist, including methods: `user.name.lenght` on a string |
|
|
1057
|
+
| `not-a-list` | warning | `FOR` over a value that is not a list in the data |
|
|
1058
|
+
|
|
1059
|
+
The last three run only with `data` or `schema`. Without them, the linter
|
|
1060
|
+
cannot know which names your data has. Names inside `FOR` loops are checked
|
|
1061
|
+
against the first entry of the list.
|
|
1062
|
+
|
|
1063
|
+
Markers like `{{each:row}}`, which `modify.setTable` uses to expand nested
|
|
1064
|
+
tables (`expand: [{ tag: '{{each:row}}', … }]`), are not template tags. The
|
|
1065
|
+
linter skips them, and `renderTemplate` leaves them in the text for
|
|
1066
|
+
`setTable`.
|
|
1067
|
+
|
|
1068
|
+
## Example data or JSON Schema
|
|
1069
|
+
|
|
1070
|
+
`data` is an example of what you pass to `renderTemplate`. A property that is
|
|
1071
|
+
missing in the example is reported, so the example should contain every
|
|
1072
|
+
optional property, too. A property that is `null` in the example is not
|
|
1073
|
+
checked further.
|
|
1074
|
+
|
|
1075
|
+
`schema` is a JSON Schema of the data. `$ref` to local definitions, `anyOf`,
|
|
1076
|
+
`oneOf`, `allOf`, `items`, `prefixItems`, `patternProperties` and
|
|
1077
|
+
`additionalProperties` are understood. An object with `properties` counts as
|
|
1078
|
+
closed unless it sets `additionalProperties`: a name that is not listed is
|
|
1079
|
+
reported, which is what catches typos. An object without `properties`
|
|
1080
|
+
accepts any name.
|
|
1081
|
+
|
|
1082
|
+
```ts
|
|
1083
|
+
import { lintTemplate } from 'pptx-templates';
|
|
1084
|
+
|
|
1085
|
+
const result = await lintTemplate('templates/Offer.pptx', {
|
|
1086
|
+
schema: {
|
|
1087
|
+
type: 'object',
|
|
1088
|
+
properties: {
|
|
1089
|
+
user: { type: 'object', properties: { name: { type: 'string' } } },
|
|
1090
|
+
items: { type: 'array', items: { $ref: '#/$defs/item' } },
|
|
1091
|
+
},
|
|
1092
|
+
$defs: {
|
|
1093
|
+
item: { type: 'object', properties: { name: { type: 'string' }, price: { type: 'number' } } },
|
|
1094
|
+
},
|
|
1095
|
+
},
|
|
1096
|
+
additionalJsContext: { money: (n: number) => `${n.toFixed(2)} €` },
|
|
1097
|
+
});
|
|
1098
|
+
```
|
|
1099
|
+
|
|
1100
|
+
| Option | Effect |
|
|
1101
|
+
|---|---|
|
|
1102
|
+
| `data` | Example data; turns on the name checks |
|
|
1103
|
+
| `schema` | JSON Schema of the data; can be combined with `data` |
|
|
1104
|
+
| `additionalJsContext` | Same as in `renderTemplate`: helper names that are not in the data |
|
|
1105
|
+
| `openingTag`, `closingTag`, `cmdDelimiter` | Other tag delimiters, as in `renderTemplate` |
|
|
1106
|
+
| `fixSmartQuotes` | Accept typographic quotes, as `renderTemplate` does with the same option. CLI: `--fix-smart-quotes` |
|
|
1107
|
+
|
|
1108
|
+
## Quotes from AutoCorrect
|
|
1109
|
+
|
|
1110
|
+
Strings in tags need straight quotes (`{{IF name == 'Ada'}}`). PowerPoint
|
|
1111
|
+
replaces typed quotes with typographic ones (`{{IF name == ’Ada’}}`), which
|
|
1112
|
+
`renderTemplate` rejects. The linter reports such a tag as a `syntax` error
|
|
1113
|
+
before you render. Switch the replacement off once in *File › Options ›
|
|
1114
|
+
Proofing › AutoCorrect Options › AutoFormat As You Type › "Straight quotes"
|
|
1115
|
+
with "smart quotes"*, then type the quotes in the tag again.
|
|
1116
|
+
|
|
1117
|
+
If you render with `fixSmartQuotes: true`, lint with the same option
|
|
1118
|
+
(`--fix-smart-quotes` on the command line), so the linter accepts the same
|
|
1119
|
+
tags as the renderer.
|
|
1120
|
+
|
|
971
1121
|
## Modify Tables
|
|
972
1122
|
|
|
973
1123
|
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.
|
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,40 @@ semver, with the pre-1.0 convention that **breaking changes bump the minor**.
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.2.0] - 2026-11-07
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `lintTemplate(pptx, options?)` checks the `{{…}}` tags of a template before
|
|
14
|
+
rendering: syntax errors (with hints for quotes and characters replaced by
|
|
15
|
+
PowerPoint's AutoCorrect and for misspelled commands like `{{END IF}}`),
|
|
16
|
+
blocked keys (`constructor`, `__proto__`), unclosed or unmatched `IF`/`FOR`/`ELSE`, tags
|
|
17
|
+
split by a line break, tags where `renderTemplate` cannot render them
|
|
18
|
+
(layouts, masters, notes, charts, SmartArt, `IMAGE` in tables or in
|
|
19
|
+
placeholders without their own position) and, given example `data` or a
|
|
20
|
+
JSON `schema`, names and property paths that are not in the data
|
|
21
|
+
(`src/extensions/template-lint/`). Each issue carries the `range` of the
|
|
22
|
+
wrong characters in the tag; the CLI underlines it with `~~~`.
|
|
23
|
+
- CLI: `npx pptx-templates lint deck.pptx [--data data.json] [--schema schema.json]`
|
|
24
|
+
(`src/extensions/cli/`).
|
|
25
|
+
- `renderTemplate` and `listTemplateCommands` leave `{{each:…}}` markers of
|
|
26
|
+
`modify.setTable`'s `expand` (nested tables) as text instead of failing on
|
|
27
|
+
them; `lintTemplate` skips them too.
|
|
28
|
+
|
|
29
|
+
### Documentation
|
|
30
|
+
|
|
31
|
+
- Getting started explains the `image-size` advisories `npm audit` reports via
|
|
32
|
+
`pptxgenjs` (not reachable) and the `overrides` entry that silences them.
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
|
|
36
|
+
- **Breaking:** strings in template expressions need straight quotes
|
|
37
|
+
(`'Ada'`, `"Ada"`). Typographic quotes from PowerPoint's AutoCorrect
|
|
38
|
+
(`“Ada”`, `‘Ada’`, `„Ada“`) were accepted before and are now a syntax
|
|
39
|
+
error, as in docx-templates. Switch off AutoCorrect's "smart quotes" and
|
|
40
|
+
retype them, or render with the new `fixSmartQuotes: true` option
|
|
41
|
+
(docx-templates compatible). `lintTemplate` finds the affected tags.
|
|
42
|
+
|
|
9
43
|
## [0.1.3] - 2026-11-05
|
|
10
44
|
|
|
11
45
|
### Security
|
|
@@ -74,7 +108,8 @@ for that history.
|
|
|
74
108
|
into one `.png` part. The fallback now gets the same placeholder PNG that
|
|
75
109
|
pptxgenjs 3.12 wrote.
|
|
76
110
|
|
|
77
|
-
[Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.
|
|
111
|
+
[Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.2.0...HEAD
|
|
112
|
+
[0.2.0]: https://github.com/DaBorsten/pptx-templates/compare/v0.1.3...v0.2.0
|
|
78
113
|
[0.1.3]: https://github.com/DaBorsten/pptx-templates/compare/v0.1.2...v0.1.3
|
|
79
114
|
[0.1.2]: https://github.com/DaBorsten/pptx-templates/compare/v0.1.1...v0.1.2
|
|
80
115
|
[0.1.1]: https://github.com/DaBorsten/pptx-templates/compare/v0.1.0...v0.1.1
|
package/README.md
CHANGED
|
@@ -34,6 +34,8 @@ or
|
|
|
34
34
|
$ npm install pptx-templates
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
If `npm audit` reports `image-size`, see [Getting started](https://daborsten.github.io/pptx-templates/getting-started): the advisory is not reachable and an `overrides` entry silences it.
|
|
38
|
+
|
|
37
39
|
To explore the library from a clone instead, see [Getting started](https://daborsten.github.io/pptx-templates/getting-started).
|
|
38
40
|
|
|
39
41
|
## Example
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.runCli = void 0;
|
|
14
|
+
/**
|
|
15
|
+
* `npx pptx-templates <command>` (the package's `bin`). Fork extension.
|
|
16
|
+
*/
|
|
17
|
+
const cli_1 = require("../template-lint/cli");
|
|
18
|
+
const USAGE = `Usage: pptx-templates <command>
|
|
19
|
+
|
|
20
|
+
Commands:
|
|
21
|
+
lint <file.pptx>... Check the {{…}} tags of templates
|
|
22
|
+
|
|
23
|
+
${cli_1.LINT_USAGE}`;
|
|
24
|
+
const runCli = (args, io) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
const [command, ...rest] = args;
|
|
26
|
+
if (command === 'lint')
|
|
27
|
+
return (0, cli_1.runLintCommand)(rest, io);
|
|
28
|
+
if (command === '-h' || command === '--help') {
|
|
29
|
+
io.stdout(`${USAGE}\n`);
|
|
30
|
+
return 0;
|
|
31
|
+
}
|
|
32
|
+
if (!command) {
|
|
33
|
+
io.stderr(`No command given.\n\n${USAGE}\n`);
|
|
34
|
+
return 2;
|
|
35
|
+
}
|
|
36
|
+
io.stderr(`Unknown command "${command}".\n\n${USAGE}\n`);
|
|
37
|
+
return 2;
|
|
38
|
+
});
|
|
39
|
+
exports.runCli = runCli;
|
|
40
|
+
if (require.main === module) {
|
|
41
|
+
(0, exports.runCli)(process.argv.slice(2), {
|
|
42
|
+
stdout: (text) => process.stdout.write(text),
|
|
43
|
+
stderr: (text) => process.stderr.write(text),
|
|
44
|
+
color: (0, cli_1.supportsColor)(),
|
|
45
|
+
}).then((code) => (process.exitCode = code), (error) => {
|
|
46
|
+
var _a;
|
|
47
|
+
process.stderr.write(`${(_a = error === null || error === void 0 ? void 0 : error.stack) !== null && _a !== void 0 ? _a : error}\n`);
|
|
48
|
+
process.exitCode = 2;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ext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,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"}
|
|
@@ -5,4 +5,6 @@ export declare const extensionModifiers: {
|
|
|
5
5
|
setCornerRadius: (radius: import("./shape-geometry").CornerRadius, shape?: import("./shape-geometry").RoundedShapePreset) => (element: import("..").XmlElement) => void;
|
|
6
6
|
};
|
|
7
7
|
export * from './template-logic';
|
|
8
|
-
export
|
|
8
|
+
export * from './template-lint';
|
|
9
|
+
export { ShapePresets } from './shape-geometry';
|
|
10
|
+
export type { ShapePreset, RoundedShapePreset, CornerRadius, ShapeAdjustments, ImageBorder, } from './shape-geometry';
|
package/dist/extensions/index.js
CHANGED
|
@@ -31,6 +31,7 @@ exports.extensionModifiers = {
|
|
|
31
31
|
setCornerRadius: shape_geometry_1.setCornerRadius,
|
|
32
32
|
};
|
|
33
33
|
__exportStar(require("./template-logic"), exports);
|
|
34
|
+
__exportStar(require("./template-lint"), exports);
|
|
34
35
|
var shape_geometry_2 = require("./shape-geometry");
|
|
35
36
|
Object.defineProperty(exports, "ShapePresets", { enumerable: true, get: function () { return shape_geometry_2.ShapePresets; } });
|
|
36
37
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;GAMG;AACH,qDAAkD;AAClD,qDAAgE;AAEhE,iEAAiE;AACpD,QAAA,kBAAkB,GAAG;IAChC,cAAc,EAAd,+BAAc;IACd,WAAW,EAAX,4BAAW;IACX,eAAe,EAAf,gCAAe;CAChB,CAAC;AAEF,mDAAiC;AACjC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;GAMG;AACH,qDAAkD;AAClD,qDAAgE;AAEhE,iEAAiE;AACpD,QAAA,kBAAkB,GAAG;IAChC,cAAc,EAAd,+BAAc;IACd,WAAW,EAAX,4BAAW;IACX,eAAe,EAAf,gCAAe;CAChB,CAAC;AAEF,mDAAiC;AACjC,kDAAgC;AAChC,mDAAgD;AAAvC,8GAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TemplateLintIssue } from './types';
|
|
2
|
+
export type CliIO = {
|
|
3
|
+
stdout: (text: string) => void;
|
|
4
|
+
stderr: (text: string) => void;
|
|
5
|
+
/** Colored output; default off (the bin sets it from the terminal). */
|
|
6
|
+
color?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const LINT_USAGE = "Usage: pptx-templates lint <file.pptx>... [options]\n\nChecks the {{\u2026}} tags of PowerPoint templates before rendering.\n\nOptions:\n --data <file.json> Example data: report names and properties that\n are not in it\n --schema <file.json> JSON Schema of the data (alternative to --data)\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 --max-warnings <n> Fail when there are more than n warnings\n --json Print the issues as JSON\n --color / --no-color Force colors on or off (default: on in a terminal;\n NO_COLOR and FORCE_COLOR are respected)\n -h, --help Show this help\n\nExit code: 0 no errors, 1 errors (or too many warnings), 2 invalid call.";
|
|
9
|
+
/** Where in the deck an issue is, for humans: "slide 2 › Title". */
|
|
10
|
+
export declare const issueLocation: (issue: TemplateLintIssue) => string;
|
|
11
|
+
/** Color on for a real terminal, off for pipes, `NO_COLOR` and `--no-color`. */
|
|
12
|
+
export declare const supportsColor: (env?: NodeJS.ProcessEnv, isTTY?: boolean) => boolean;
|
|
13
|
+
export declare const formatIssues: (file: string, issues: TemplateLintIssue[], color?: boolean) => string;
|
|
14
|
+
/** `pptx-templates lint …`; resolves to the exit code. */
|
|
15
|
+
export declare const runLintCommand: (args: string[], io: CliIO) => Promise<number>;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.runLintCommand = exports.formatIssues = exports.supportsColor = exports.issueLocation = exports.LINT_USAGE = void 0;
|
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
|
17
|
+
const lint_1 = require("./lint");
|
|
18
|
+
exports.LINT_USAGE = `Usage: pptx-templates lint <file.pptx>... [options]
|
|
19
|
+
|
|
20
|
+
Checks the {{…}} tags of PowerPoint templates before rendering.
|
|
21
|
+
|
|
22
|
+
Options:
|
|
23
|
+
--data <file.json> Example data: report names and properties that
|
|
24
|
+
are not in it
|
|
25
|
+
--schema <file.json> JSON Schema of the data (alternative to --data)
|
|
26
|
+
--opening-tag <text> Tag start (default: {{)
|
|
27
|
+
--closing-tag <text> Tag end (default: }})
|
|
28
|
+
--fix-smart-quotes Accept typographic quotes, like renderTemplate's
|
|
29
|
+
fixSmartQuotes option
|
|
30
|
+
--max-warnings <n> Fail when there are more than n warnings
|
|
31
|
+
--json Print the issues as JSON
|
|
32
|
+
--color / --no-color Force colors on or off (default: on in a terminal;
|
|
33
|
+
NO_COLOR and FORCE_COLOR are respected)
|
|
34
|
+
-h, --help Show this help
|
|
35
|
+
|
|
36
|
+
Exit code: 0 no errors, 1 errors (or too many warnings), 2 invalid call.`;
|
|
37
|
+
const readJson = (file, what) => {
|
|
38
|
+
try {
|
|
39
|
+
return JSON.parse(fs_1.default.readFileSync(file, 'utf8'));
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
throw new Error(`Cannot read ${what} ${file}: ${error.message}`, {
|
|
43
|
+
cause: error,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
/** Where in the deck an issue is, for humans: "slide 2 › Title". */
|
|
48
|
+
const issueLocation = (issue) => {
|
|
49
|
+
const parts = [];
|
|
50
|
+
let m;
|
|
51
|
+
if ((m = /slides\/slide(\d+)\.xml$/.exec(issue.part)))
|
|
52
|
+
parts.push(`slide ${m[1]}`);
|
|
53
|
+
else if ((m = /slideLayout(\d+)\.xml$/.exec(issue.part)))
|
|
54
|
+
parts.push(`layout ${m[1]}`);
|
|
55
|
+
else if ((m = /slideMaster(\d+)\.xml$/.exec(issue.part)))
|
|
56
|
+
parts.push(`master ${m[1]}`);
|
|
57
|
+
else if (/notesSlide\d+\.xml$/.test(issue.part)) {
|
|
58
|
+
parts.push(issue.slide ? `notes of slide ${issue.slide}` : 'notes');
|
|
59
|
+
}
|
|
60
|
+
else if ((m = /chart(\d+)\.xml$/.exec(issue.part))) {
|
|
61
|
+
parts.push(`chart ${m[1]}` + (issue.slide ? ` on slide ${issue.slide}` : ''));
|
|
62
|
+
}
|
|
63
|
+
else if ((m = /diagrams\/data(\d+)\.xml$/.exec(issue.part))) {
|
|
64
|
+
parts.push(`SmartArt ${m[1]}` + (issue.slide ? ` on slide ${issue.slide}` : ''));
|
|
65
|
+
}
|
|
66
|
+
else
|
|
67
|
+
parts.push(issue.part);
|
|
68
|
+
if (issue.shape)
|
|
69
|
+
parts.push(`"${issue.shape}"`);
|
|
70
|
+
return parts.join(' › ');
|
|
71
|
+
};
|
|
72
|
+
exports.issueLocation = issueLocation;
|
|
73
|
+
const ansi = (open, close) => (text) => `\u001b[${open}m${text}\u001b[${close}m`;
|
|
74
|
+
const style = {
|
|
75
|
+
bold: ansi(1, 22),
|
|
76
|
+
dim: ansi(2, 22),
|
|
77
|
+
underline: ansi(4, 24),
|
|
78
|
+
red: ansi(31, 39),
|
|
79
|
+
yellow: ansi(33, 39),
|
|
80
|
+
cyan: ansi(36, 39),
|
|
81
|
+
};
|
|
82
|
+
/** Color on for a real terminal, off for pipes, `NO_COLOR` and `--no-color`. */
|
|
83
|
+
const supportsColor = (env = process.env, isTTY = !!process.stdout.isTTY) => {
|
|
84
|
+
if (env.NO_COLOR !== undefined && env.NO_COLOR !== '')
|
|
85
|
+
return false;
|
|
86
|
+
if (env.FORCE_COLOR !== undefined && env.FORCE_COLOR !== '0')
|
|
87
|
+
return true;
|
|
88
|
+
return isTTY && env.TERM !== 'dumb';
|
|
89
|
+
};
|
|
90
|
+
exports.supportsColor = supportsColor;
|
|
91
|
+
const formatIssues = (file, issues, color = false) => {
|
|
92
|
+
if (!issues.length)
|
|
93
|
+
return '';
|
|
94
|
+
const paint = (fn, text) => color ? fn(text) : text;
|
|
95
|
+
const lines = [paint(style.underline, file)];
|
|
96
|
+
issues.forEach((issue) => {
|
|
97
|
+
const tone = issue.severity === 'error' ? style.red : style.yellow;
|
|
98
|
+
lines.push(` ${paint(style.cyan, (0, exports.issueLocation)(issue))}`);
|
|
99
|
+
lines.push(` ${paint((t) => style.bold(tone(t)), issue.severity)} ${issue.message} ${paint(style.dim, `(${issue.rule})`)}`);
|
|
100
|
+
if (issue.tag) {
|
|
101
|
+
// Tabs would shift the marker line
|
|
102
|
+
lines.push(` ${paint(style.dim, 'tag:')} ${issue.tag.replace(/\t/g, ' ')}`);
|
|
103
|
+
if (issue.range) {
|
|
104
|
+
const { start, end } = issue.range;
|
|
105
|
+
lines.push(` ${' '.repeat(start)}${paint(tone, '~'.repeat(Math.max(1, end - start)))}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (issue.hint)
|
|
109
|
+
lines.push(` ${paint(style.dim, 'hint:')} ${issue.hint}`);
|
|
110
|
+
});
|
|
111
|
+
return lines.join('\n') + '\n';
|
|
112
|
+
};
|
|
113
|
+
exports.formatIssues = formatIssues;
|
|
114
|
+
const parseArgs = (args) => {
|
|
115
|
+
const parsed = {
|
|
116
|
+
files: [],
|
|
117
|
+
options: {},
|
|
118
|
+
json: false,
|
|
119
|
+
help: false,
|
|
120
|
+
};
|
|
121
|
+
for (let i = 0; i < args.length; i++) {
|
|
122
|
+
const arg = args[i];
|
|
123
|
+
const value = () => {
|
|
124
|
+
const next = args[++i];
|
|
125
|
+
if (next === undefined)
|
|
126
|
+
throw new Error(`${arg} needs a value`);
|
|
127
|
+
return next;
|
|
128
|
+
};
|
|
129
|
+
switch (arg) {
|
|
130
|
+
case '-h':
|
|
131
|
+
case '--help':
|
|
132
|
+
parsed.help = true;
|
|
133
|
+
break;
|
|
134
|
+
case '--json':
|
|
135
|
+
parsed.json = true;
|
|
136
|
+
break;
|
|
137
|
+
case '--color':
|
|
138
|
+
parsed.color = true;
|
|
139
|
+
break;
|
|
140
|
+
case '--no-color':
|
|
141
|
+
parsed.color = false;
|
|
142
|
+
break;
|
|
143
|
+
case '--fix-smart-quotes':
|
|
144
|
+
parsed.options.fixSmartQuotes = true;
|
|
145
|
+
break;
|
|
146
|
+
case '--data':
|
|
147
|
+
parsed.options.data = readJson(value(), 'data');
|
|
148
|
+
break;
|
|
149
|
+
case '--schema':
|
|
150
|
+
parsed.options.schema = readJson(value(), 'schema');
|
|
151
|
+
break;
|
|
152
|
+
case '--opening-tag':
|
|
153
|
+
parsed.options.openingTag = value();
|
|
154
|
+
break;
|
|
155
|
+
case '--closing-tag':
|
|
156
|
+
parsed.options.closingTag = value();
|
|
157
|
+
break;
|
|
158
|
+
case '--max-warnings': {
|
|
159
|
+
const n = Number(value());
|
|
160
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
161
|
+
throw new Error('--max-warnings needs a whole number');
|
|
162
|
+
}
|
|
163
|
+
parsed.maxWarnings = n;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
default:
|
|
167
|
+
if (arg.startsWith('-'))
|
|
168
|
+
throw new Error(`Unknown option ${arg}`);
|
|
169
|
+
parsed.files.push(arg);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return parsed;
|
|
173
|
+
};
|
|
174
|
+
/** `pptx-templates lint …`; resolves to the exit code. */
|
|
175
|
+
const runLintCommand = (args, io) => __awaiter(void 0, void 0, void 0, function* () {
|
|
176
|
+
var _a, _b;
|
|
177
|
+
let parsed;
|
|
178
|
+
try {
|
|
179
|
+
parsed = parseArgs(args);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
io.stderr(`${error.message}\n\n${exports.LINT_USAGE}\n`);
|
|
183
|
+
return 2;
|
|
184
|
+
}
|
|
185
|
+
if (parsed.help) {
|
|
186
|
+
io.stdout(`${exports.LINT_USAGE}\n`);
|
|
187
|
+
return 0;
|
|
188
|
+
}
|
|
189
|
+
if (!parsed.files.length) {
|
|
190
|
+
io.stderr(`No .pptx file given.\n\n${exports.LINT_USAGE}\n`);
|
|
191
|
+
return 2;
|
|
192
|
+
}
|
|
193
|
+
const color = (_b = (_a = parsed.color) !== null && _a !== void 0 ? _a : io.color) !== null && _b !== void 0 ? _b : false;
|
|
194
|
+
let errors = 0;
|
|
195
|
+
let warnings = 0;
|
|
196
|
+
const report = {};
|
|
197
|
+
for (const file of parsed.files) {
|
|
198
|
+
let issues;
|
|
199
|
+
try {
|
|
200
|
+
({ issues } = yield (0, lint_1.lintTemplate)(file, parsed.options));
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
io.stderr(`Cannot read ${file}: ${error.message}\n`);
|
|
204
|
+
return 2;
|
|
205
|
+
}
|
|
206
|
+
report[file] = issues;
|
|
207
|
+
errors += issues.filter((i) => i.severity === 'error').length;
|
|
208
|
+
warnings += issues.filter((i) => i.severity === 'warning').length;
|
|
209
|
+
if (!parsed.json)
|
|
210
|
+
io.stdout((0, exports.formatIssues)(file, issues, color));
|
|
211
|
+
}
|
|
212
|
+
if (parsed.json) {
|
|
213
|
+
io.stdout(JSON.stringify(report, null, 2) + '\n');
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
const total = errors + warnings;
|
|
217
|
+
const paint = (fn, text) => color ? fn(text) : text;
|
|
218
|
+
io.stdout(total
|
|
219
|
+
? `\n${paint((t) => style.bold(errors ? style.red(t) : style.yellow(t)), `${total} problem(s): ${errors} error(s), ${warnings} warning(s)`)}\n`
|
|
220
|
+
: `${paint((t) => style.bold(ansi(32, 39)(t)), `No problems found in ${parsed.files.length} file(s)`)}\n`);
|
|
221
|
+
}
|
|
222
|
+
const tooManyWarnings = parsed.maxWarnings !== undefined && warnings > parsed.maxWarnings;
|
|
223
|
+
return errors || tooManyWarnings ? 1 : 0;
|
|
224
|
+
});
|
|
225
|
+
exports.runLintCommand = runLintCommand;
|
|
226
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/extensions/template-lint/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,iCAAsC;AAUzB,QAAA,UAAU,GAAG;;;;;;;;;;;;;;;;;;yEAkB+C,CAAC;AAE1E,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,IAAY,EAA2B,EAAE;IACvE,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IAC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AyB,EAAE,IAAY,EAAE,EAAE,CACxD,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC1B,EAAE,CAAC,MAAM,CACP,KAAK;YACH,CAAC,CAAC,KAAK,KAAK,CACR,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAC1D,GAAG,KAAK,gBAAgB,MAAM,cAAc,QAAQ,aAAa,CAClE,IAAI;YACP,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,wBAAwB,MAAM,CAAC,KAAK,CAAC,MAAM,UAAU,CAAC,IAAI,CAC5G,CAAC;IACJ,CAAC;IAED,MAAM,eAAe,GACnB,MAAM,CAAC,WAAW,KAAK,SAAS,IAAI,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC;IACpE,OAAO,MAAM,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3C,CAAC,CAAA,CAAC;AAzDW,QAAA,cAAc,kBAyDzB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { JsonSchema } from './types';
|
|
2
|
+
/** What the linter knows about a value: nothing, an example, or a schema. */
|
|
3
|
+
export type Known = {
|
|
4
|
+
kind: 'any';
|
|
5
|
+
} | {
|
|
6
|
+
kind: 'value';
|
|
7
|
+
value: unknown;
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'schema';
|
|
10
|
+
schema: JsonSchema;
|
|
11
|
+
};
|
|
12
|
+
/** A lookup that found nothing; `candidates` feed "did you mean". */
|
|
13
|
+
export type Missing = {
|
|
14
|
+
kind: 'missing';
|
|
15
|
+
candidates: string[];
|
|
16
|
+
owner: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Answers "does `user.name` exist?" against example data and/or a JSON
|
|
20
|
+
* Schema. Whatever cannot be decided (null in the example, an open schema,
|
|
21
|
+
* a computed value) counts as existing: the linter only reports what is
|
|
22
|
+
* certainly missing.
|
|
23
|
+
*/
|
|
24
|
+
export declare class DataModel {
|
|
25
|
+
private readonly data?;
|
|
26
|
+
private readonly schema?;
|
|
27
|
+
private readonly extra;
|
|
28
|
+
constructor(data?: Record<string, unknown>, schema?: JsonSchema, extra?: Record<string, unknown>);
|
|
29
|
+
/** Whether names can be checked at all (data or schema given). */
|
|
30
|
+
get enabled(): boolean;
|
|
31
|
+
root(name: string): Known | Missing;
|
|
32
|
+
member(known: Known, key: string): Known | Missing;
|
|
33
|
+
/** The type of a FOR loop's entries; `undefined`: not a list. */
|
|
34
|
+
element(known: Known): Known | undefined;
|
|
35
|
+
private valueMember;
|
|
36
|
+
private schemaMember;
|
|
37
|
+
private ownSchemaMember;
|
|
38
|
+
private schemaElement;
|
|
39
|
+
/** Follows local `$ref`s (`#/$defs/…`, `#/definitions/…`, `#`). */
|
|
40
|
+
private resolve;
|
|
41
|
+
}
|
|
42
|
+
/** Closest candidate within a small edit distance, for "did you mean". */
|
|
43
|
+
export declare const suggest: (name: string, candidates: string[]) => string | undefined;
|