How to resolve ids from getStructTree
?
#18508
Unanswered
edoardocavazza
asked this question in
Q&A
Replies: 1 comment
-
I think you can use the result of const textContent = await page.getTextContent({ includeMarkedContent: true }).then(x => x.items);
const findText = (id: string) => {
let nodes = [];
let depth = 0;
let collecting = false;
for (let node of textContent) {
if ("id" in node && node.id === id) collecting = true;
if (collecting) {
nodes.push(node);
if ("type" in node) {
if (node.type.startsWith("begin")) depth++;
if (node.type.startsWith("end")) depth--;
if (depth == 0) break;
}
}
}
return nodes.map(x => ("str" in x) ? x.str : "").join("");
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! I am trying to create a text layer with proper HTML tags usage using the
page.getStructTree()
method, but I cannot find a way to resolve ids to actual content.Beta Was this translation helpful? Give feedback.
All reactions