Work on multiple slides

This commit is contained in:
Thomas Forgione 2023-03-01 18:16:17 +01:00
parent c447c11bc2
commit 87b0111915
1 changed files with 76 additions and 51 deletions

View File

@ -231,16 +231,17 @@ async function main() {
await page.setViewport(size);
await page.goto('file://' + path);
// Only consider the first slide (#\\331 === #1, which is the id of the first slide)
// We don't take into account the other slides because it will mess up with our screenshot varification
let root = await page.$('#\\31');
let output = [];
// 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) {
error('not a marp HTML file');
process.exit(1);
break;
}
info("analysing slide " + pageIndex);
// Hide slides controls
await page.evaluate(() => {
for (let elt of document.getElementsByClassName('bespoke-marp-osc')) {
@ -285,11 +286,35 @@ async function main() {
let analyse = await analyseElement(root, page, outputDir, threshold);
info("analysis done");
// Append the current slide to the output
if (flatten) {
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) {
console.log(json);
} else {