pptx-templates 0.3.5 → 0.3.6
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 +129 -2
- package/CHANGELOG.md +24 -1
- package/README.md +1 -0
- package/dist/extensions/hide-slide/index.d.ts +44 -0
- package/dist/extensions/hide-slide/index.js +244 -0
- package/dist/extensions/hide-slide/index.js.map +1 -0
- package/dist/extensions/index.d.ts +3 -1
- package/dist/extensions/index.js +4 -1
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/template-lint/lint.js +53 -1
- package/dist/extensions/template-lint/lint.js.map +1 -1
- package/dist/extensions/template-logic/commands.js +5 -0
- package/dist/extensions/template-logic/commands.js.map +1 -1
- package/dist/extensions/template-logic/renderer.d.ts +3 -0
- package/dist/extensions/template-logic/renderer.js +20 -0
- package/dist/extensions/template-logic/renderer.js.map +1 -1
- package/dist/extensions/template-logic/types.d.ts +10 -2
- package/dist/extensions/template-render/index.d.ts +6 -0
- package/dist/extensions/template-render/index.js +46 -5
- package/dist/extensions/template-render/index.js.map +1 -1
- package/dist/extensions/text-flow/flow.d.ts +25 -0
- package/dist/extensions/text-flow/flow.js +82 -3
- package/dist/extensions/text-flow/flow.js.map +1 -1
- package/dist/extensions/text-flow/index.d.ts +1 -1
- package/dist/extensions/text-flow/index.js +3 -1
- package/dist/extensions/text-flow/index.js.map +1 -1
- package/package.json +1 -1
package/AI-INSTRUCTOR.md
CHANGED
|
@@ -713,6 +713,7 @@ pres.addSlide('TextReplace.pptx', 1, (slide) => {
|
|
|
713
713
|
| `{{HTML expr}}` | Insert HTML as formatted paragraphs (bold, italic, lists, links, …) through the [HTML converter](https://daborsten.github.io/pptx-templates/text.md) |
|
|
714
714
|
| `{{LINK expr}}` | Insert a hyperlink. `expr` is a URL or `({ url, label })`. A number as `url` links to that slide of the output |
|
|
715
715
|
| `{{IMAGE expr}}` | Place a picture where the shape is (see [Images](#images)). Needs `slide.modify` |
|
|
716
|
+
| `{{HIDE-SLIDE expr}}` | In the speaker notes: `renderDeck` leaves the slide out when `expr` is true (see [Hide Slides](https://daborsten.github.io/pptx-templates/hide-slide.md)). Anywhere else it is removed and does nothing |
|
|
716
717
|
|
|
717
718
|
Keywords are case-insensitive. A block can sit inside one paragraph
|
|
718
719
|
(`Status: {{IF ok}}fine{{ELSE}}broken{{END-IF}}`) or span paragraphs. A
|
|
@@ -1228,6 +1229,41 @@ pres.addSlide('Columns.pptx', 1, (slide) => {
|
|
|
1228
1229
|
});
|
|
1229
1230
|
```
|
|
1230
1231
|
|
|
1232
|
+
### Continuing on another slide
|
|
1233
|
+
|
|
1234
|
+
`flowContinue(list)` is `list` without the entries that `flow()` shows on
|
|
1235
|
+
the slides before it in the output of `renderDeck`. A first slide can show
|
|
1236
|
+
as many projects as fit into one text box, and a second slide the rest, one
|
|
1237
|
+
per column:
|
|
1238
|
+
|
|
1239
|
+
```text
|
|
1240
|
+
{{FOR p IN flow(projects)}}
|
|
1241
|
+
{{p.name}}
|
|
1242
|
+
{{END-FOR}}
|
|
1243
|
+
```
|
|
1244
|
+
|
|
1245
|
+
```text
|
|
1246
|
+
{{FOR p IN flow(flowContinue(projects), 1)}}
|
|
1247
|
+
{{p.name}}
|
|
1248
|
+
{{END-FOR}}
|
|
1249
|
+
```
|
|
1250
|
+
|
|
1251
|
+
Without more, the first slide would repeat until every project is on it.
|
|
1252
|
+
`{{HIDE-SLIDE flowPage > 1}}` in its speaker notes keeps only its first
|
|
1253
|
+
copy (see [Hide Slides](https://daborsten.github.io/pptx-templates/hide-slide.md)); entries of hidden copies count
|
|
1254
|
+
as not shown. The second slide repeats as usual while projects are left.
|
|
1255
|
+
|
|
1256
|
+
- Objects are compared with `===`: the objects of your data count as shown
|
|
1257
|
+
wherever `flow()` showed them. Strings and numbers count only for the
|
|
1258
|
+
same list, `projects` itself or a `flowContinue(projects)`; of equal ones,
|
|
1259
|
+
as many are skipped as were shown. A list built anew in the template
|
|
1260
|
+
(`projects.map(…)`, `filter(…)`) is a different list.
|
|
1261
|
+
- With the `flowPage` option, each slide shows that part of its lists, and
|
|
1262
|
+
`flowContinue()` goes on after it.
|
|
1263
|
+
- `{{HIDE-SLIDE !flowContinue(projects).length}}` leaves the second slide
|
|
1264
|
+
out when the first one shows every project.
|
|
1265
|
+
- Outside `renderDeck`, `flowContinue(list)` is the whole list.
|
|
1266
|
+
|
|
1231
1267
|
### Rules for the template
|
|
1232
1268
|
|
|
1233
1269
|
- `{{FOR … IN flow(…)}}` and `{{END-FOR}}` each need a paragraph of their own,
|
|
@@ -1254,11 +1290,102 @@ pres.addSlide('Columns.pptx', 1, (slide) => {
|
|
|
1254
1290
|
matters.
|
|
1255
1291
|
- Hyphenation, kerning and right-to-left or East Asian line breaking rules
|
|
1256
1292
|
are not taken into account.
|
|
1257
|
-
- `flow`, `flowRest`, `flowPage` and `flowPages` are built in. The same name
|
|
1293
|
+
- `flow`, `flowRest`, `flowContinue`, `flowPage` and `flowPages` are built in. The same name
|
|
1258
1294
|
in your data or in `additionalJsContext` takes precedence.
|
|
1259
1295
|
- To count the slides, `renderDeck` and `countFlowPages` render the slide
|
|
1260
1296
|
once more. Functions in your data are called again then.
|
|
1261
1297
|
|
|
1298
|
+
## Hide Slides
|
|
1299
|
+
|
|
1300
|
+
Some slides only make sense with the right data: a slide for further
|
|
1301
|
+
projects when there are more than two, a discount slide for VIP customers.
|
|
1302
|
+
Write `{{HIDE-SLIDE condition}}` into the **speaker notes** of the slide,
|
|
1303
|
+
and `renderDeck` leaves the slide out when the condition is true:
|
|
1304
|
+
|
|
1305
|
+
```text
|
|
1306
|
+
{{HIDE-SLIDE projects.length <= 2}}
|
|
1307
|
+
```
|
|
1308
|
+
|
|
1309
|
+
```ts
|
|
1310
|
+
import fs from 'fs';
|
|
1311
|
+
import { renderDeck } from 'pptx-templates';
|
|
1312
|
+
|
|
1313
|
+
const projects = [{ name: 'Portal' }, { name: 'App' }];
|
|
1314
|
+
|
|
1315
|
+
// The slide with the tag in its notes is not in the output
|
|
1316
|
+
fs.writeFileSync(
|
|
1317
|
+
'output/Projects.pptx',
|
|
1318
|
+
await renderDeck('templates/Projects.pptx', { projects }),
|
|
1319
|
+
);
|
|
1320
|
+
```
|
|
1321
|
+
|
|
1322
|
+
The condition is an [expression](https://daborsten.github.io/pptx-templates/template-logic.md#expressions) like the
|
|
1323
|
+
one of `{{IF …}}`, with the data, `additionalJsContext` and the options of
|
|
1324
|
+
the render (`strict`, `fixSmartQuotes`, other delimiters, `errorHandler`).
|
|
1325
|
+
`pptx-templates render` on the command line does the same.
|
|
1326
|
+
|
|
1327
|
+
- `{{HIDE-SLIDE}}` without a condition always hides the slide, for example
|
|
1328
|
+
a slide that is still being worked on.
|
|
1329
|
+
- With several tags in the notes, the slide is left out as soon as one of
|
|
1330
|
+
them is true.
|
|
1331
|
+
- The tags are removed from the notes of the output; the rest of the notes
|
|
1332
|
+
stays. A paragraph that held nothing but the tag goes as well.
|
|
1333
|
+
- When every slide is hidden, the output has no slides.
|
|
1334
|
+
|
|
1335
|
+
### Why the speaker notes
|
|
1336
|
+
|
|
1337
|
+
The tag decides about the whole slide, not about a piece of text, so it
|
|
1338
|
+
belongs to the slide once. The notes exist once per slide and are not part
|
|
1339
|
+
of the design. On the slide itself, in a text box or a table,
|
|
1340
|
+
`{{HIDE-SLIDE …}}` is removed with a warning and does nothing; the
|
|
1341
|
+
[linter](https://daborsten.github.io/pptx-templates/template-lint.md) reports it there as `unsupported-location`.
|
|
1342
|
+
Other tags in the notes are not rendered and stay as they are.
|
|
1343
|
+
|
|
1344
|
+
### Copies of a flow() slide
|
|
1345
|
+
|
|
1346
|
+
A slide whose [`flow()`](https://daborsten.github.io/pptx-templates/text-flow.md) list needs more than one slide is
|
|
1347
|
+
repeated by `renderDeck`. The condition is evaluated for each copy, with
|
|
1348
|
+
`flowPage` (1, 2, …) and `flowPages`:
|
|
1349
|
+
|
|
1350
|
+
```text
|
|
1351
|
+
{{HIDE-SLIDE flowPage > 3}}
|
|
1352
|
+
```
|
|
1353
|
+
|
|
1354
|
+
keeps the first three copies of the slide and leaves out the rest.
|
|
1355
|
+
|
|
1356
|
+
### With addSlide
|
|
1357
|
+
|
|
1358
|
+
`renderTemplate` renders one slide and cannot take it out of the deck.
|
|
1359
|
+
With your own `addSlide` calls, ask `isSlideHidden` first and skip the
|
|
1360
|
+
slide:
|
|
1361
|
+
|
|
1362
|
+
```ts
|
|
1363
|
+
import { isSlideHidden, modify } from 'pptx-templates';
|
|
1364
|
+
|
|
1365
|
+
const data = { projects: [{ name: 'Portal' }] };
|
|
1366
|
+
|
|
1367
|
+
if (!(await isSlideHidden('templates/Projects.pptx', 2, data))) {
|
|
1368
|
+
pres.addSlide('Projects.pptx', 2, (slide) => {
|
|
1369
|
+
slide.modify(modify.renderTemplate(data));
|
|
1370
|
+
});
|
|
1371
|
+
}
|
|
1372
|
+
```
|
|
1373
|
+
|
|
1374
|
+
It takes the options of `renderTemplate`, plus `flowPage` (0-based) and
|
|
1375
|
+
`flowPages` for a condition that depends on them. `addSlide` copies the
|
|
1376
|
+
notes as they are, tag included.
|
|
1377
|
+
|
|
1378
|
+
### Good to know
|
|
1379
|
+
|
|
1380
|
+
- An error in the condition rejects `renderDeck` with a
|
|
1381
|
+
`TemplateRenderError` that starts with the slide number
|
|
1382
|
+
(`slide 2: {{HIDE-SLIDE check()}}: …`), unless `errorHandler` returns a
|
|
1383
|
+
value for it.
|
|
1384
|
+
- The tag must be in one paragraph of the notes. PowerPoint may split it
|
|
1385
|
+
into several runs (spell check); that is fine.
|
|
1386
|
+
- `flow()` and `flowRest()` in the condition do not distribute anything:
|
|
1387
|
+
`flow(list)` is the whole list there.
|
|
1388
|
+
|
|
1262
1389
|
## Shape Geometry
|
|
1263
1390
|
|
|
1264
1391
|
Every shape and picture in PowerPoint has a geometry: a rectangle, an
|
|
@@ -1485,7 +1612,7 @@ npx pptx-templates lint --config other.json
|
|
|
1485
1612
|
| `unmatched-tag` | error | `END-IF`, `END-FOR`, `ELSE`, `ELSE-IF` without an opening tag, or an `ELSE` after `ELSE` |
|
|
1486
1613
|
| `unknown-alias` | error | `{{*name}}` without `{{ALIAS name …}}` on the slide |
|
|
1487
1614
|
| `unsupported-location` | error | `IMAGE` in a table cell, `IMAGE` in a placeholder that inherits its position from the layout, `ELSE` that spans table rows |
|
|
1488
|
-
| `unsupported-location` | warning | Tags in slide layouts, masters, speaker notes, charts and SmartArt. `renderTemplate` does not render them, so they stay as they are |
|
|
1615
|
+
| `unsupported-location` | warning | Tags in slide layouts, masters, speaker notes, charts and SmartArt. `renderTemplate` does not render them, so they stay as they are. `{{HIDE-SLIDE …}}` belongs into the speaker notes (checked there like any expression) and is reported everywhere else |
|
|
1489
1616
|
| `unknown-variable` | warning | A name that is not in `data`/`schema`/`additionalJsContext` and not defined by `FOR`, `EXEC` or an arrow function |
|
|
1490
1617
|
| `unknown-property` | warning | A property path that does not exist, including methods: `user.name.lenght` on a string |
|
|
1491
1618
|
| `not-a-list` | warning | `FOR` over a value that is not a list in the data |
|
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,28 @@ semver, with the pre-1.0 convention that **breaking changes bump the minor**.
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.3.6] - 2026-11-17
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `{{HIDE-SLIDE condition}}` in the speaker notes of a slide: `renderDeck`
|
|
14
|
+
(and `pptx-templates render`) leaves the slide out when the condition is
|
|
15
|
+
true. Without a condition the slide is always left out; with several tags,
|
|
16
|
+
one true condition is enough. For the copies of a `flow()` slide the
|
|
17
|
+
condition is evaluated per copy, with `flowPage` and `flowPages`. The tag
|
|
18
|
+
is removed from the notes of the output. On the slide itself the tag is
|
|
19
|
+
removed with a warning and does nothing.
|
|
20
|
+
- `isSlideHidden(pptx, slide, data, options)` tells `addSlide` users
|
|
21
|
+
whether to skip a slide.
|
|
22
|
+
- `flowContinue(list)`: the entries of `list` that `flow()` does not show on
|
|
23
|
+
the slides before it in `renderDeck`, hidden copies not counted. A slide
|
|
24
|
+
with `flow(flowContinue(projects), 1)` goes on where an earlier slide's
|
|
25
|
+
`flow(projects)` stopped.
|
|
26
|
+
- The linter checks `{{HIDE-SLIDE …}}` in the speaker notes like any
|
|
27
|
+
expression (syntax, unknown names) and reports it as
|
|
28
|
+
`unsupported-location` anywhere else. `listTemplateCommands` lists it
|
|
29
|
+
with the type `HIDE-SLIDE`.
|
|
30
|
+
|
|
9
31
|
## [0.3.5] - 2026-11-16
|
|
10
32
|
|
|
11
33
|
### Added
|
|
@@ -292,7 +314,8 @@ for that history.
|
|
|
292
314
|
into one `.png` part. The fallback now gets the same placeholder PNG that
|
|
293
315
|
pptxgenjs 3.12 wrote.
|
|
294
316
|
|
|
295
|
-
[Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.
|
|
317
|
+
[Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.6...HEAD
|
|
318
|
+
[0.3.6]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.5...v0.3.6
|
|
296
319
|
[0.3.5]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.4...v0.3.5
|
|
297
320
|
[0.3.4]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.3...v0.3.4
|
|
298
321
|
[0.3.3]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.2...v0.3.3
|
package/README.md
CHANGED
|
@@ -139,6 +139,7 @@ third.
|
|
|
139
139
|
| `{{HTML expr}}` | Insert HTML as formatted text: bold, italic, lists, links |
|
|
140
140
|
| `{{LINK expr}}` | Insert a hyperlink, to a URL or to a slide of the output |
|
|
141
141
|
| `{{IMAGE expr}}` | Place a picture where the text box is, optionally cropped to a shape with a border |
|
|
142
|
+
| `{{HIDE-SLIDE expr}}` | In the speaker notes: leave the slide out of the deck when `expr` is true |
|
|
142
143
|
|
|
143
144
|
Expressions are JavaScript without the dangerous parts: property paths,
|
|
144
145
|
comparisons, `&&`, `||`, `??`, `? :`, arrow functions
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import JSZip from 'jszip';
|
|
2
|
+
import { XmlDocument } from '../../types/xml-types';
|
|
3
|
+
import type { RenderTemplateOptions, TemplateData } from '../template-logic/types';
|
|
4
|
+
/** One `{{HIDE-SLIDE …}}` of a slide's notes. */
|
|
5
|
+
export type HideSlideCondition = {
|
|
6
|
+
/** The tag as written, e.g. `{{HIDE-SLIDE !projects.length}}`. */
|
|
7
|
+
tag: string;
|
|
8
|
+
/** The condition; empty: always hide. */
|
|
9
|
+
code: string;
|
|
10
|
+
};
|
|
11
|
+
export type IsSlideHiddenOptions = RenderTemplateOptions & {
|
|
12
|
+
/**
|
|
13
|
+
* How many slides the `flow()` lists of the slide need, for `flowPages`
|
|
14
|
+
* in the condition (`countFlowPages`). Default: 1
|
|
15
|
+
*/
|
|
16
|
+
flowPages?: number;
|
|
17
|
+
};
|
|
18
|
+
/** Path of the notes part of `ppt/slides/slide<n>.xml`, if it has notes. */
|
|
19
|
+
export declare const notesPartOf: (zip: JSZip, slide: number) => Promise<string | undefined>;
|
|
20
|
+
/** The `{{HIDE-SLIDE …}}` tags in the speaker notes of a slide. */
|
|
21
|
+
export declare const hideSlideConditions: (zip: JSZip, slide: number, options?: RenderTemplateOptions) => Promise<HideSlideCondition[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Whether one of the conditions is true. `page` is 0-based, as the
|
|
24
|
+
* `flowPage` option; the condition sees it 1-based, as in the slide.
|
|
25
|
+
*/
|
|
26
|
+
export declare const evaluateHideConditions: (conditions: HideSlideCondition[], data: TemplateData, options: RenderTemplateOptions, page: number, pages: number) => Promise<boolean>;
|
|
27
|
+
/** A TemplateRenderError of a condition, its message led by the slide. */
|
|
28
|
+
export declare const withSlideNumber: (error: unknown, slide: number) => unknown;
|
|
29
|
+
/**
|
|
30
|
+
* Whether `renderDeck` leaves a slide out: one of the `{{HIDE-SLIDE …}}`
|
|
31
|
+
* tags in its speaker notes is true with this data. For slides added with
|
|
32
|
+
* `addSlide`: skip the `addSlide` call when it returns true.
|
|
33
|
+
*
|
|
34
|
+
* @param pptx Path to a .pptx file or its contents.
|
|
35
|
+
* @param slide 1-based number of the slide in the template.
|
|
36
|
+
*/
|
|
37
|
+
export declare const isSlideHidden: (pptx: string | Buffer | Uint8Array | ArrayBuffer, slide: number, data: TemplateData, options?: IsSlideHiddenOptions) => Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Removes the `{{HIDE-SLIDE …}}` tags from a notes part; a paragraph that
|
|
40
|
+
* held nothing else goes as well. Returns whether anything changed.
|
|
41
|
+
*/
|
|
42
|
+
export declare const stripHideSlideTags: (doc: XmlDocument, options?: RenderTemplateOptions) => boolean;
|
|
43
|
+
/** stripHideSlideTags for every notes part of a deck. */
|
|
44
|
+
export declare const stripHideSlideTagsInDeck: (zip: JSZip, options?: RenderTemplateOptions) => Promise<void>;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.stripHideSlideTagsInDeck = exports.stripHideSlideTags = exports.isSlideHidden = exports.withSlideNumber = exports.evaluateHideConditions = exports.hideSlideConditions = exports.notesPartOf = void 0;
|
|
49
|
+
/**
|
|
50
|
+
* `{{HIDE-SLIDE condition}}` in the speaker notes of a slide: `renderDeck`
|
|
51
|
+
* leaves the slide out when the condition is true. See docs/hide-slide.md.
|
|
52
|
+
*/
|
|
53
|
+
const fs_1 = __importDefault(require("fs"));
|
|
54
|
+
const jszip_1 = __importDefault(require("jszip"));
|
|
55
|
+
const xmldom_1 = require("@xmldom/xmldom");
|
|
56
|
+
const ppt_paths_1 = require("../../helper/ppt-paths");
|
|
57
|
+
const commands_1 = require("../template-logic/commands");
|
|
58
|
+
const expression_1 = require("../template-logic/expression");
|
|
59
|
+
const flow_1 = require("../text-flow/flow");
|
|
60
|
+
const NOTES_REL = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide';
|
|
61
|
+
const parseXml = (xml) => new xmldom_1.DOMParser().parseFromString(xml, 'application/xml');
|
|
62
|
+
const elements = (parent, tagName) => Array.from(parent.getElementsByTagName(tagName));
|
|
63
|
+
/** The text of a paragraph, runs joined (a tag can be split across runs). */
|
|
64
|
+
const paragraphText = (paragraph) => elements(paragraph, 'a:t')
|
|
65
|
+
.map((t) => t.textContent)
|
|
66
|
+
.join('');
|
|
67
|
+
/** The HIDE-SLIDE tags in `text`; other tags and invalid ones are skipped. */
|
|
68
|
+
const hideTagsIn = (text, syntax, options) => Array.from(text.matchAll(syntax.pattern)).flatMap((m) => {
|
|
69
|
+
if ((0, commands_1.isTableMarker)(m[1]))
|
|
70
|
+
return [];
|
|
71
|
+
const inner = options.fixSmartQuotes ? (0, commands_1.fixSmartQuotes)(m[1]) : m[1];
|
|
72
|
+
try {
|
|
73
|
+
const command = (0, commands_1.parseCommand)(inner, m[0]);
|
|
74
|
+
return command.type === 'HIDE-SLIDE'
|
|
75
|
+
? [{ tag: m[0], code: command.code }]
|
|
76
|
+
: [];
|
|
77
|
+
}
|
|
78
|
+
catch (_a) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
/** Path of the notes part of `ppt/slides/slide<n>.xml`, if it has notes. */
|
|
83
|
+
const notesPartOf = (zip, slide) => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
const rels = yield ((_a = zip.file(ppt_paths_1.PptPaths.slideRels(slide))) === null || _a === void 0 ? void 0 : _a.async('string'));
|
|
86
|
+
if (!rels)
|
|
87
|
+
return undefined;
|
|
88
|
+
const rel = elements(parseXml(rels), 'Relationship').find((r) => r.getAttribute('Type') === NOTES_REL);
|
|
89
|
+
const target = rel === null || rel === void 0 ? void 0 : rel.getAttribute('Target');
|
|
90
|
+
if (!target)
|
|
91
|
+
return undefined;
|
|
92
|
+
if (target.startsWith('/'))
|
|
93
|
+
return target.slice(1);
|
|
94
|
+
const n = (_b = /notesSlide(\d+)\.xml$/.exec(target)) === null || _b === void 0 ? void 0 : _b[1];
|
|
95
|
+
return n ? ppt_paths_1.PptPaths.notesSlide(Number(n)) : undefined;
|
|
96
|
+
});
|
|
97
|
+
exports.notesPartOf = notesPartOf;
|
|
98
|
+
/** The `{{HIDE-SLIDE …}}` tags in the speaker notes of a slide. */
|
|
99
|
+
const hideSlideConditions = (zip_1, slide_1, ...args_1) => __awaiter(void 0, [zip_1, slide_1, ...args_1], void 0, function* (zip, slide, options = {}) {
|
|
100
|
+
var _a;
|
|
101
|
+
const part = yield (0, exports.notesPartOf)(zip, slide);
|
|
102
|
+
const xml = part && (yield ((_a = zip.file(part)) === null || _a === void 0 ? void 0 : _a.async('string')));
|
|
103
|
+
if (!xml)
|
|
104
|
+
return [];
|
|
105
|
+
const syntax = (0, commands_1.tagSyntax)(options);
|
|
106
|
+
return elements(parseXml(xml), 'a:p').flatMap((p) => hideTagsIn(paragraphText(p), syntax, options));
|
|
107
|
+
});
|
|
108
|
+
exports.hideSlideConditions = hideSlideConditions;
|
|
109
|
+
/** A read-only scope: data, then additionalJsContext, then the built-ins. */
|
|
110
|
+
const scopeOf = (layers) => ({
|
|
111
|
+
lookup(name) {
|
|
112
|
+
for (const vars of layers) {
|
|
113
|
+
if (vars && Object.prototype.hasOwnProperty.call(vars, name)) {
|
|
114
|
+
return { found: true, value: vars[name] };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return { found: false };
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
/**
|
|
121
|
+
* Whether one of the conditions is true. `page` is 0-based, as the
|
|
122
|
+
* `flowPage` option; the condition sees it 1-based, as in the slide.
|
|
123
|
+
*/
|
|
124
|
+
const evaluateHideConditions = (conditions, data, options, page, pages) => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
+
var _a, _b, _c;
|
|
126
|
+
if (!conditions.length)
|
|
127
|
+
return false;
|
|
128
|
+
const scope = scopeOf([
|
|
129
|
+
data !== null && data !== void 0 ? data : {},
|
|
130
|
+
(_a = options.additionalJsContext) !== null && _a !== void 0 ? _a : {},
|
|
131
|
+
{
|
|
132
|
+
flowPage: page + 1,
|
|
133
|
+
flowPages: pages,
|
|
134
|
+
// The lists are not distributed here: flow() is the list itself
|
|
135
|
+
flow: (list) => list,
|
|
136
|
+
flowRest: () => [],
|
|
137
|
+
flowContinue: (list) => { var _a; return ((_a = options.flowShown) !== null && _a !== void 0 ? _a : new flow_1.FlowShown()).continue(list); },
|
|
138
|
+
},
|
|
139
|
+
]);
|
|
140
|
+
const evaluation = {
|
|
141
|
+
strict: (_b = options.strict) !== null && _b !== void 0 ? _b : false,
|
|
142
|
+
allowStringPatterns: (_c = options.allowStringPatterns) !== null && _c !== void 0 ? _c : false,
|
|
143
|
+
};
|
|
144
|
+
for (const { tag, code } of conditions) {
|
|
145
|
+
if (!code)
|
|
146
|
+
return true;
|
|
147
|
+
let value;
|
|
148
|
+
try {
|
|
149
|
+
value = yield new expression_1.TemplateExpression(code).evaluate(scope, evaluation);
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
if (!options.errorHandler) {
|
|
153
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
154
|
+
// Loaded here: the renderer imports src/index.ts (import cycle)
|
|
155
|
+
const { TemplateRenderError } = yield Promise.resolve().then(() => __importStar(require('../template-logic/renderer')));
|
|
156
|
+
throw new TemplateRenderError(`${tag}: ${message}`);
|
|
157
|
+
}
|
|
158
|
+
value = yield options.errorHandler(error, code);
|
|
159
|
+
}
|
|
160
|
+
if (value)
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
});
|
|
165
|
+
exports.evaluateHideConditions = evaluateHideConditions;
|
|
166
|
+
/** A TemplateRenderError of a condition, its message led by the slide. */
|
|
167
|
+
const withSlideNumber = (error, slide) => {
|
|
168
|
+
if (error instanceof Error && error.name === 'TemplateRenderError') {
|
|
169
|
+
error.message = `slide ${slide}: ${error.message}`;
|
|
170
|
+
}
|
|
171
|
+
return error;
|
|
172
|
+
};
|
|
173
|
+
exports.withSlideNumber = withSlideNumber;
|
|
174
|
+
/**
|
|
175
|
+
* Whether `renderDeck` leaves a slide out: one of the `{{HIDE-SLIDE …}}`
|
|
176
|
+
* tags in its speaker notes is true with this data. For slides added with
|
|
177
|
+
* `addSlide`: skip the `addSlide` call when it returns true.
|
|
178
|
+
*
|
|
179
|
+
* @param pptx Path to a .pptx file or its contents.
|
|
180
|
+
* @param slide 1-based number of the slide in the template.
|
|
181
|
+
*/
|
|
182
|
+
const isSlideHidden = (pptx_1, slide_1, data_1, ...args_1) => __awaiter(void 0, [pptx_1, slide_1, data_1, ...args_1], void 0, function* (pptx, slide, data, options = {}) {
|
|
183
|
+
var _a, _b;
|
|
184
|
+
const content = typeof pptx === 'string' ? yield fs_1.default.promises.readFile(pptx) : pptx;
|
|
185
|
+
const zip = yield jszip_1.default.loadAsync(content);
|
|
186
|
+
const conditions = yield (0, exports.hideSlideConditions)(zip, slide, options);
|
|
187
|
+
try {
|
|
188
|
+
return yield (0, exports.evaluateHideConditions)(conditions, data, options, (_a = options.flowPage) !== null && _a !== void 0 ? _a : 0, (_b = options.flowPages) !== null && _b !== void 0 ? _b : 1);
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
throw (0, exports.withSlideNumber)(error, slide);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
exports.isSlideHidden = isSlideHidden;
|
|
195
|
+
/**
|
|
196
|
+
* Removes the `{{HIDE-SLIDE …}}` tags from a notes part; a paragraph that
|
|
197
|
+
* held nothing else goes as well. Returns whether anything changed.
|
|
198
|
+
*/
|
|
199
|
+
const stripHideSlideTags = (doc, options = {}) => {
|
|
200
|
+
const syntax = (0, commands_1.tagSyntax)(options);
|
|
201
|
+
const strip = (text) => text.replace(syntax.pattern, (raw) => hideTagsIn(raw, syntax, options).length ? '' : raw);
|
|
202
|
+
let changed = false;
|
|
203
|
+
elements(doc, 'a:p').forEach((paragraph) => {
|
|
204
|
+
const before = paragraphText(paragraph);
|
|
205
|
+
if (!hideTagsIn(before, syntax, options).length)
|
|
206
|
+
return;
|
|
207
|
+
changed = true;
|
|
208
|
+
const texts = elements(paragraph, 'a:t');
|
|
209
|
+
// Tags within one run: removed there, the formatting stays
|
|
210
|
+
texts.forEach((t) => {
|
|
211
|
+
t.textContent = strip(t.textContent);
|
|
212
|
+
});
|
|
213
|
+
// Tags split across runs: the paragraph's text goes into its first run
|
|
214
|
+
const joined = paragraphText(paragraph);
|
|
215
|
+
if (hideTagsIn(joined, syntax, options).length) {
|
|
216
|
+
texts.forEach((t, i) => {
|
|
217
|
+
t.textContent = i === 0 ? strip(joined) : '';
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
const body = paragraph.parentNode;
|
|
221
|
+
const isOnly = elements(body, 'a:p').length === 1;
|
|
222
|
+
if (paragraphText(paragraph).trim() === '' && !isOnly) {
|
|
223
|
+
body.removeChild(paragraph);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
return changed;
|
|
227
|
+
};
|
|
228
|
+
exports.stripHideSlideTags = stripHideSlideTags;
|
|
229
|
+
/** stripHideSlideTags for every notes part of a deck. */
|
|
230
|
+
const stripHideSlideTagsInDeck = (zip_1, ...args_1) => __awaiter(void 0, [zip_1, ...args_1], void 0, function* (zip, options = {}) {
|
|
231
|
+
const parts = Object.keys(zip.files).filter((name) => /^ppt\/notesSlides\/notesSlide\d+\.xml$/.test(name));
|
|
232
|
+
for (const part of parts) {
|
|
233
|
+
const xml = yield zip.file(part).async('string');
|
|
234
|
+
// Cheap pre-check; the keyword is case-insensitive
|
|
235
|
+
if (!/hide/i.test(xml))
|
|
236
|
+
continue;
|
|
237
|
+
const doc = parseXml(xml);
|
|
238
|
+
if ((0, exports.stripHideSlideTags)(doc, options)) {
|
|
239
|
+
zip.file(part, new xmldom_1.XMLSerializer().serializeToString(doc));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
exports.stripHideSlideTagsInDeck = stripHideSlideTagsInDeck;
|
|
244
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/hide-slide/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;GAGG;AACH,4CAAoB;AACpB,kDAA0B;AAC1B,2CAA0D;AAE1D,sDAAkD;AAClD,yDAKoC;AACpC,6DAGsC;AAKtC,4CAA8C;AAkB9C,MAAM,SAAS,GACb,gFAAgF,CAAC;AAEnF,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAe,EAAE,CAC5C,IAAI,kBAAS,EAAE,CAAC,eAAe,CAC7B,GAAG,EACH,iBAAiB,CACQ,CAAC;AAE9B,MAAM,QAAQ,GAAG,CACf,MAAgC,EAChC,OAAe,EACD,EAAE,CAChB,KAAK,CAAC,IAAI,CACR,MAAM,CAAC,oBAAoB,CAAC,OAAO,CAAqC,CACzE,CAAC;AAEJ,6EAA6E;AAC7E,MAAM,aAAa,GAAG,CAAC,SAAqB,EAAU,EAAE,CACtD,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC;KACvB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CA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C,CAAC;QAC9B,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAlCW,QAAA,kBAAkB,sBAkC7B;AAEF,yDAAyD;AAClD,MAAM,wBAAwB,GAAG,mBAGvB,EAAE,0DAFjB,GAAU,EACV,UAAiC,EAAE;IAEnC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CACnD,wCAAwC,CAAC,IAAI,CAAC,IAAI,CAAC,CACpD,CAAC;IACF,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACjD,mDAAmD;QACnD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;YAAE,SAAS;QACjC,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,IAAA,0BAAkB,EAAC,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC;YACrC,GAAG,CAAC,IAAI,CACN,IAAI,EACJ,IAAI,sBAAa,EAAE,CAAC,iBAAiB,CACnC,GAAmE,CACpE,CACF,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC,CAAA,CAAC;AArBW,QAAA,wBAAwB,4BAqBnC"}
|
|
@@ -8,6 +8,8 @@ export * from './template-logic';
|
|
|
8
8
|
export * from './template-lint';
|
|
9
9
|
export { renderDeck, countFlowPages } from './template-render';
|
|
10
10
|
export type { RenderDeckOptions } from './template-render';
|
|
11
|
-
export { FlowCache } from './text-flow';
|
|
11
|
+
export { FlowCache, FlowShown } from './text-flow';
|
|
12
|
+
export { isSlideHidden } from './hide-slide';
|
|
13
|
+
export type { IsSlideHiddenOptions } from './hide-slide';
|
|
12
14
|
export { ShapePresets } from './shape-geometry';
|
|
13
15
|
export type { ShapePreset, RoundedShapePreset, CornerRadius, ShapeAdjustments, ImageBorder, } from './shape-geometry';
|
package/dist/extensions/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.ShapePresets = exports.FlowCache = exports.countFlowPages = exports.renderDeck = exports.extensionModifiers = void 0;
|
|
17
|
+
exports.ShapePresets = exports.isSlideHidden = exports.FlowShown = exports.FlowCache = exports.countFlowPages = exports.renderDeck = exports.extensionModifiers = void 0;
|
|
18
18
|
/**
|
|
19
19
|
* Fork extensions (not part of upstream singerla/pptx-automizer).
|
|
20
20
|
*
|
|
@@ -37,6 +37,9 @@ Object.defineProperty(exports, "renderDeck", { enumerable: true, get: function (
|
|
|
37
37
|
Object.defineProperty(exports, "countFlowPages", { enumerable: true, get: function () { return template_render_1.countFlowPages; } });
|
|
38
38
|
var text_flow_1 = require("./text-flow");
|
|
39
39
|
Object.defineProperty(exports, "FlowCache", { enumerable: true, get: function () { return text_flow_1.FlowCache; } });
|
|
40
|
+
Object.defineProperty(exports, "FlowShown", { enumerable: true, get: function () { return text_flow_1.FlowShown; } });
|
|
41
|
+
var hide_slide_1 = require("./hide-slide");
|
|
42
|
+
Object.defineProperty(exports, "isSlideHidden", { enumerable: true, get: function () { return hide_slide_1.isSlideHidden; } });
|
|
40
43
|
var shape_geometry_2 = require("./shape-geometry");
|
|
41
44
|
Object.defineProperty(exports, "ShapePresets", { enumerable: true, get: function () { return shape_geometry_2.ShapePresets; } });
|
|
42
45
|
//# 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,kDAAgC;AAChC,qDAA+D;AAAtD,6GAAA,UAAU,OAAA;AAAE,iHAAA,cAAc,OAAA;AAEnC,
|
|
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,qDAA+D;AAAtD,6GAAA,UAAU,OAAA;AAAE,iHAAA,cAAc,OAAA;AAEnC,yCAAmD;AAA1C,sGAAA,SAAS,OAAA;AAAE,sGAAA,SAAS,OAAA;AAC7B,2CAA6C;AAApC,2GAAA,aAAa,OAAA;AAEtB,mDAAgD;AAAvC,8GAAA,YAAY,OAAA"}
|
|
@@ -26,6 +26,7 @@ const skeleton_1 = require("./skeleton");
|
|
|
26
26
|
const BUILTIN_HELPERS = {
|
|
27
27
|
flow: (list) => list,
|
|
28
28
|
flowRest: () => [],
|
|
29
|
+
flowContinue: (list) => list,
|
|
29
30
|
flowPage: 1,
|
|
30
31
|
flowPages: 1,
|
|
31
32
|
};
|
|
@@ -132,7 +133,8 @@ const OTHER_PARTS = [
|
|
|
132
133
|
{
|
|
133
134
|
pattern: /^ppt\/notesSlides\/notesSlide(\d+)\.xml$/,
|
|
134
135
|
describe: () => 'speaker notes',
|
|
135
|
-
hint: 'renderTemplate does not render speaker notes.'
|
|
136
|
+
hint: 'renderTemplate does not render speaker notes. Only {{HIDE-SLIDE …}} ' +
|
|
137
|
+
'works there.',
|
|
136
138
|
},
|
|
137
139
|
{
|
|
138
140
|
pattern: /^ppt\/charts\/chart(\d+)\.xml$/,
|
|
@@ -391,6 +393,14 @@ class TemplateLinter {
|
|
|
391
393
|
}
|
|
392
394
|
case 'ALIAS':
|
|
393
395
|
break;
|
|
396
|
+
case 'HIDE-SLIDE':
|
|
397
|
+
tagReport({
|
|
398
|
+
severity: 'warning',
|
|
399
|
+
rule: 'unsupported-location',
|
|
400
|
+
message: `${raw} is ignored here: HIDE-SLIDE works only in the speaker notes`,
|
|
401
|
+
hint: 'Move the tag into the speaker notes of the slide. renderTemplate removes it from the slide text.',
|
|
402
|
+
});
|
|
403
|
+
break;
|
|
394
404
|
case 'IMAGE': {
|
|
395
405
|
const expr = check(command.code);
|
|
396
406
|
for (const ref of (_c = expr === null || expr === void 0 ? void 0 : expr.imageSources()) !== null && _c !== void 0 ? _c : []) {
|
|
@@ -601,6 +611,44 @@ class TemplateLinter {
|
|
|
601
611
|
}
|
|
602
612
|
return known.kind === 'missing' ? ANY : this.model.element(known);
|
|
603
613
|
}
|
|
614
|
+
/**
|
|
615
|
+
* Speaker notes: `{{HIDE-SLIDE …}}` is checked like an expression; any
|
|
616
|
+
* other tag is reported as not rendered (lintOtherPart).
|
|
617
|
+
*/
|
|
618
|
+
lintNotes(part, slide, doc) {
|
|
619
|
+
const others = [];
|
|
620
|
+
descendants(doc, 'a:p').forEach((paragraph) => {
|
|
621
|
+
const text = descendants(paragraph, 'a:t')
|
|
622
|
+
.map((t) => t.textContent)
|
|
623
|
+
.join('');
|
|
624
|
+
const rest = text.replace(this.syntax.pattern, (raw, inner) => {
|
|
625
|
+
let command;
|
|
626
|
+
try {
|
|
627
|
+
command = this.parse(inner, new Map(), raw);
|
|
628
|
+
}
|
|
629
|
+
catch (_a) {
|
|
630
|
+
return raw;
|
|
631
|
+
}
|
|
632
|
+
if (command.type !== 'HIDE-SLIDE')
|
|
633
|
+
return raw;
|
|
634
|
+
this.enterTag(raw);
|
|
635
|
+
this.enterCode(command.code);
|
|
636
|
+
this.location = Object.assign({ part }, (slide !== undefined && { slide }));
|
|
637
|
+
const report = (issue) => {
|
|
638
|
+
var _a;
|
|
639
|
+
return this.report(part, slide, Object.assign(Object.assign({}, issue), { tag: raw, range: (_a = issue.range) !== null && _a !== void 0 ? _a : { start: 0, end: raw.length } }));
|
|
640
|
+
};
|
|
641
|
+
if (command.code) {
|
|
642
|
+
const expr = this.checkExpression(command.code, new Map(), new Set(), report);
|
|
643
|
+
if (expr)
|
|
644
|
+
this.recordUsage(expr, new Map(), false);
|
|
645
|
+
}
|
|
646
|
+
return '';
|
|
647
|
+
});
|
|
648
|
+
others.push(rest);
|
|
649
|
+
});
|
|
650
|
+
this.lintOtherPart(part, slide, others);
|
|
651
|
+
}
|
|
604
652
|
lintOtherPart(part, slide, texts) {
|
|
605
653
|
const kind = OTHER_PARTS.find((p) => p.pattern.test(part));
|
|
606
654
|
if (!kind)
|
|
@@ -714,6 +762,10 @@ const runLinter = (pptx, options, usage) => __awaiter(void 0, void 0, void 0, fu
|
|
|
714
762
|
.sort((a, b) => a.localeCompare(b, 'en', { numeric: true }));
|
|
715
763
|
for (const name of others) {
|
|
716
764
|
const doc = parseXml(yield zip.file(name).async('string'));
|
|
765
|
+
if (/^ppt\/notesSlides\//.test(name)) {
|
|
766
|
+
linter.lintNotes(name, slideOfPart.get(name), doc);
|
|
767
|
+
continue;
|
|
768
|
+
}
|
|
717
769
|
const texts = [...descendants(doc, 'a:t'), ...descendants(doc, 'c:v')].map((t) => t.textContent);
|
|
718
770
|
linter.lintOtherPart(name, slideOfPart.get(name), texts);
|
|
719
771
|
}
|