Work on multiple slides
This commit is contained in:
parent
c447c11bc2
commit
87b0111915
39
index.js
39
index.js
|
@ -231,16 +231,17 @@ async function main() {
|
||||||
await page.setViewport(size);
|
await page.setViewport(size);
|
||||||
await page.goto('file://' + path);
|
await page.goto('file://' + path);
|
||||||
|
|
||||||
// Only consider the first slide (#\\331 === #1, which is the id of the first slide)
|
let output = [];
|
||||||
// We don't take into account the other slides because it will mess up with our screenshot varification
|
|
||||||
let root = await page.$('#\\31');
|
|
||||||
|
|
||||||
// If there is no slide, try to run on HTML body
|
for (let pageIndex = 1;; pageIndex++) {
|
||||||
|
|
||||||
|
let root = await page.$('#\\3' + pageIndex);
|
||||||
if (root === null) {
|
if (root === null) {
|
||||||
error('not a marp HTML file');
|
break;
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info("analysing slide " + pageIndex);
|
||||||
|
|
||||||
// Hide slides controls
|
// Hide slides controls
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
for (let elt of document.getElementsByClassName('bespoke-marp-osc')) {
|
for (let elt of document.getElementsByClassName('bespoke-marp-osc')) {
|
||||||
|
@ -285,11 +286,35 @@ async function main() {
|
||||||
let analyse = await analyseElement(root, page, outputDir, threshold);
|
let analyse = await analyseElement(root, page, outputDir, threshold);
|
||||||
info("analysis done");
|
info("analysis done");
|
||||||
|
|
||||||
|
// Append the current slide to the output
|
||||||
if (flatten) {
|
if (flatten) {
|
||||||
|
|
||||||
analyse = flattenTree(analyse);
|
analyse = flattenTree(analyse);
|
||||||
|
for (let elt of anaylse) {
|
||||||
|
output.push(elt);
|
||||||
}
|
}
|
||||||
|
|
||||||
let json = JSON.stringify(analyse, undefined, 4);
|
} else {
|
||||||
|
|
||||||
|
output.push(analyse);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Go to the next page
|
||||||
|
await page.evaluate(el => {
|
||||||
|
let buttons = document.getElementsByTagName('button');
|
||||||
|
for (let button of buttons) {
|
||||||
|
if (button.title === "Next slide") {
|
||||||
|
button.click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
eprintln();
|
||||||
|
}
|
||||||
|
|
||||||
|
info("saving output");
|
||||||
|
let json = JSON.stringify(output, undefined, 4);
|
||||||
if (outputDir === null) {
|
if (outputDir === null) {
|
||||||
console.log(json);
|
console.log(json);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue