Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chendy/5f28e8455319427af86a8665a58a32c0 to your computer and use it in GitHub Desktop.
Save chendy/5f28e8455319427af86a8665a58a32c0 to your computer and use it in GitHub Desktop.
function printWordsBetweenAngleBrackets(){
let doc = DocumentApp.getActiveDocument();
let body = doc.getBody();
let text = body.editAsText();
// all the documents text as a long string AFAIK
let textString = text.getText();
let startToken = false;
let tokens = [];
let token = "";
for (let i=0; i<textString.length;i++){
let c = textString[i];
if (c == "<"){
//Logger.log(i, "<");
startToken = true;
continue;
}
if (c == ">"){
tokens.push(token);
token = "";
startToken = false;
continue;
}
if (startToken){
token += c;
}
}
tokens = new Set(tokens);
tokens = Array.from(tokens)
//Logger.log(tokens);
tokens = tokens.sort();
Logger.log(tokens);
//Append a paragraph and a page break to the document body section directly.
//body.appendParagraph("A paragraph.");
//body.appendPageBreak();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment