function docReplace() {
var regExp = "^#.*";
var body = DocumentApp.getActiveDocument().getBody();
body.replaceText('^"', '>');
body.replaceText('"$', '');
boldfaceText("^[Bb]y.*");
colorText("^>.*");
linkTex("^http.*");
GreyTex("^#.*");
}
function boldfaceText(findMe) {
// put to boldface the argument
var body = DocumentApp.getActiveDocument().getBody();
var foundElement = body.findText(findMe);
while (foundElement != null) {
// Get the text object from the element
var foundText = foundElement.getElement().asText();
// Where in the Element is the found text?
var start = foundElement.getStartOffset();
var end = foundElement.getEndOffsetInclusive();
// Bolden
foundText.setBold(start, end, true);
//foundText.setForegroundColor(start, end, '#B4ADAD')
// Find the next match
foundElement = body.findText(findMe, foundElement);
}
}
function colorText(findMe) {
// put to boldface the argument
var body = DocumentApp.getActiveDocument().getBody();
var foundElement = body.findText(findMe);
while (foundElement != null) {
// Get the text object from the element
var foundText = foundElement.getElement().asText();
// Where in the Element is the found text?
var start = foundElement.getStartOffset();
var end = foundElement.getEndOffsetInclusive();
// Change the foreground color to red
foundText.setForegroundColor(start, end, '#C80B0B')
// Find the next match
foundElement = body.findText(findMe, foundElement);
}
}
function linkTex(findMe) {
// put to boldface the argument
var body = DocumentApp.getActiveDocument().getBody();
var foundElement = body.findText(findMe);
while (foundElement != null) {
// Get the text object from the element
var foundText = foundElement.getElement().asText();
// Where in the Element is the found text?
var start = foundElement.getStartOffset();
var end = foundElement.getEndOffsetInclusive();
var TXT = foundText.getText();
// Change the foreground color to red
foundText.setLinkUrl(start, end, TXT)
// Find the next match
foundElement = body.findText(findMe, foundElement);
}
}
function GreyTex(findMe) {
// put to boldface the argument
var body = DocumentApp.getActiveDocument().getBody();
var foundElement = body.findText(findMe);
while (foundElement != null) {
// Get the text object from the element
var foundText = foundElement.getElement().asText();
// Where in the Element is the found text?
var start = foundElement.getStartOffset();
var end = foundElement.getEndOffsetInclusive();
// Change the foreground color to grey
foundText.setForegroundColor(start, end, '#B4ADAD')
// Find the next match
foundElement = body.findText(findMe, foundElement);
}
}
Comments
0 B
|0 👍
/0 👎