Azuhmier icon

GoogleDocFormater

Azuhmier | PRO | 12/24/20 12:01:36 AM UTC (Edited) | 0 ⭐ | 1078 👁️ | Never ⏰ | []
JavaScript |

2.87 KB

|

None

|

0 👍

/

0 👎

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

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎