Throw an error when the {{body}} insert point is missing
This commit is contained in:
parent
1dcb7f16fe
commit
5e1948421b
28
Code.ts
28
Code.ts
@ -56,21 +56,21 @@ function test() {
|
|||||||
|
|
||||||
const insert_point = out_doc
|
const insert_point = out_doc
|
||||||
.getBody()
|
.getBody()
|
||||||
.findText('{{test}}')
|
.findText('{{body}}')
|
||||||
?.getElement();
|
?.getElement();
|
||||||
|
|
||||||
if (insert_point) {
|
if (!insert_point) {
|
||||||
// find the parent element that is a direct descendant of the body
|
throw new Error("Could not find insert point '{{body}}'");
|
||||||
let parent = insert_point;
|
|
||||||
while (
|
|
||||||
parent.getParent().getType() != DocumentApp.ElementType.BODY_SECTION
|
|
||||||
) {
|
|
||||||
parent = parent.getParent();
|
|
||||||
}
|
|
||||||
const idx = out_doc.getBody().getChildIndex(parent);
|
|
||||||
|
|
||||||
// insert with index 0 is an append, for some reason
|
|
||||||
copyBody(source_doc.getBody(), out_doc.getBody(), idx + 1);
|
|
||||||
out_doc.getBody().removeChild(parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// find the parent element that is a direct descendant of the body
|
||||||
|
let parent = insert_point;
|
||||||
|
while (parent.getParent().getType() != DocumentApp.ElementType.BODY_SECTION) {
|
||||||
|
parent = parent.getParent();
|
||||||
|
}
|
||||||
|
const index = out_doc.getBody().getChildIndex(parent);
|
||||||
|
|
||||||
|
// insert with index 0 is an append, for some reason
|
||||||
|
copyBody(source_doc.getBody(), out_doc.getBody(), index + 1);
|
||||||
|
out_doc.getBody().removeChild(parent);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user