Trying to write a function that pulls text between <>
brackets in a document, writes to html and allows the user to replace the bracketed text with a user input field (via the find and replace function). Having trouble getting the actual bracketed text from the google doc. The closest I have gotten is returning the paragraph the bracketed text is in, but that does not work because then the entire paragraph gets replaced instead of only the bracketed text.
This is the most recent error:
TypeError: Cannot find function getStartOffset in object Text. (line 11, file "Code", project "Find and Replace Script")
function doGet() {
var docURL = DocumentApp.openByUrl('XXXX')
var body = docURL.getBody();
var fel0 = body.findText('<*>')
var el0 = fel0.getElement();
var startOffset = el0.getStartOffset();
var endOffset = el0.getEndOffsetInclusive();
var text = el0.asText().getText()
if (elements[0].isPartial())
text = el0.substring(startOffset,endOffset+1);
var template = HtmlService.createTemplateFromFile('urlinput.html');
template.el0 = el0;
return template.evaluate();
}
function findreplace(form){
var docURL = DocumentApp.openByUrl('XXXX')
var body = docURL.getBody();
body.replaceText(body.findText('<*>',fel0).getElement().asText().getText())
}
How do I get the actual found text from that body.findText('<*>')
object? A big part that makes this difficult is the *
wildcard between the <>
brackets.