Skip to content

Commit 1e6dfd5

Browse files
committed
feat(text): use html code for (nested) multi-text content
1 parent 2d8a587 commit 1e6dfd5

File tree

7 files changed

+878
-180
lines changed

7 files changed

+878
-180
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import Automizer, { modify } from '../src/index';
2+
3+
test('create presentation, replace multi text from HTML string.', async () => {
4+
const automizer = new Automizer({
5+
templateDir: `${__dirname}/pptx-templates`,
6+
outputDir: `${__dirname}/pptx-output`,
7+
});
8+
9+
const pres = automizer.loadRoot(`RootTemplate.pptx`).load(`TextReplace.pptx`);
10+
11+
const html =
12+
'<html><body>\n' +
13+
'<p><span style="font-size: 24px;">Testing layouts and exporting them.</span></p>\n' +
14+
'<ul>\n' +
15+
'<li>level 1 - 1</li>\n' +
16+
'<li>level 1 - 2</li>\n' +
17+
'<ul>\n' +
18+
'<li>level 1-2-1 <em>italics</em></li>\n' +
19+
'</ul>\n' +
20+
'<li>level 1 - 3</li>\n' +
21+
'<ul>\n' +
22+
'<li>level 1 - 3 - 1</li>\n' +
23+
'</ul>\n' +
24+
'</ul>\n' +
25+
'<p>Testing testing testing</p>\n' +
26+
'<p><strong>bold text</strong></p>\n' +
27+
'</body></html>\n';
28+
29+
await pres
30+
.addSlide('TextReplace.pptx', 1, (slide) => {
31+
slide.modifyElement('setText', modify.htmlToMultiText(html));
32+
})
33+
.write(`modify-multi-text-html.test.pptx`);
34+
35+
// expect(result.tables).toBe(2); // TODO: fixture for pptx-output
36+
});
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import Automizer, { modify } from '../src/index';
2+
3+
4+
test('create presentation, replace multi text.', async () => {
5+
const automizer = new Automizer({
6+
templateDir: `${__dirname}/pptx-templates`,
7+
outputDir: `${__dirname}/pptx-output`,
8+
});
9+
10+
const pres = automizer.loadRoot(`RootTemplate.pptx`).load(`TextReplace.pptx`);
11+
12+
await pres
13+
.addSlide('TextReplace.pptx', 1, (slide) => {
14+
slide.modifyElement('setText', modify.setMultiText([
15+
{
16+
paragraph: {
17+
bullet: true,
18+
level: 0,
19+
marginLeft: 41338,
20+
indent: -87325,
21+
alignment: 'left'
22+
},
23+
textRuns: [
24+
{
25+
text: 'test 0',
26+
style: {
27+
color: {
28+
type: 'srgbClr',
29+
value: 'CCCCCC'
30+
}
31+
}
32+
},
33+
]
34+
},
35+
{
36+
paragraph: {
37+
bullet: true,
38+
level: 1,
39+
marginLeft: 541338,
40+
indent: -187325,
41+
alignment: 'left'
42+
},
43+
textRuns: [
44+
{
45+
text: 'test ',
46+
style: {
47+
color: {
48+
type: 'srgbClr',
49+
value: 'CCCCCC'
50+
}
51+
}
52+
},
53+
{
54+
text: 'test 2',
55+
style: {
56+
size: 700,
57+
color: {
58+
type: 'srgbClr',
59+
value: 'FF0000'
60+
}
61+
}
62+
},
63+
{
64+
text: 'test 3',
65+
style: {
66+
size: 1200,
67+
color: {
68+
type: 'srgbClr',
69+
value: '00FF00'
70+
}
71+
}
72+
}
73+
]
74+
},
75+
{
76+
paragraph: {
77+
alignment: 'right'
78+
},
79+
textRuns: [
80+
{
81+
text: 'aligned Center',
82+
style: {
83+
color: {
84+
type: 'srgbClr',
85+
value: '00FF00'
86+
}
87+
}
88+
},
89+
]
90+
},
91+
]));
92+
})
93+
.write(`modify-multi-text.test.pptx`);
94+
95+
// expect(result.tables).toBe(2); // TODO: fixture for pptx-output
96+
});

src/dev.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,31 @@ const run = async () => {
1818

1919
const pres = automizer.loadRoot(`RootTemplate.pptx`).load(`TextReplace.pptx`);
2020

21+
const html =
22+
'<p><span style="font-size: 24px;">Testing layouts and exporting them.</span></p>\n' +
23+
'<ul>\n' +
24+
'<li>level 1 - 1</li>\n' +
25+
'<li>level 1 - 2</li>\n' +
26+
'<ul>\n' +
27+
'<li>level 1-2-1 <em>italics</em></li>\n' +
28+
'</ul>\n' +
29+
'<li>level 1 - 3</li>\n' +
30+
'<ul>\n' +
31+
'<li>level 1 - 3 - 1</li>\n' +
32+
'</ul>\n' +
33+
'</ul>\n' +
34+
'<p>Testing testing testing</p>\n' +
35+
'<p><strong>bold text</strong></p>\n';
36+
2137
await pres
2238
.addSlide('TextReplace.pptx', 1, (slide) => {
2339
slide.modifyElement('setText', modify.setMultiText([
2440
{
2541
paragraph: {
2642
bullet: true,
2743
level: 1,
28-
marginLeft: -187325,
29-
indent: 541338,
44+
marginLeft: 541338,
45+
indent: -187325,
3046
alignment: 'left'
3147
},
3248
textRuns: [

0 commit comments

Comments
 (0)