Advertisement
Azuhmier

formater.gs

Dec 31st, 2020
1,580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function docReplace() {
  2.   var regExp = "^#.*";
  3.   var body = DocumentApp.getActiveDocument().getBody();
  4.   body.replaceText('^"', '>');
  5.   body.replaceText('"$', '');
  6.  
  7.   boldfaceText("^[Bb]y.*");
  8.   colorText("^>.*");
  9.   linkTex("^http.*");
  10.   GreyTex("^#.*");
  11.                
  12. }
  13.  
  14. function boldfaceText(findMe) {
  15.   // put to boldface the argument
  16.   var body = DocumentApp.getActiveDocument().getBody();
  17.   var foundElement = body.findText(findMe);
  18.  
  19.   while (foundElement != null) {
  20.     // Get the text object from the element
  21.     var foundText = foundElement.getElement().asText();
  22.  
  23.     // Where in the Element is the found text?
  24.     var start = foundElement.getStartOffset();
  25.     var end = foundElement.getEndOffsetInclusive();
  26.  
  27.     // Bolden
  28.     foundText.setBold(start, end, true);
  29.     //foundText.setForegroundColor(start, end, '#B4ADAD')
  30.  
  31.     // Find the next match
  32.     foundElement = body.findText(findMe, foundElement);
  33.   }
  34. }
  35.  
  36. function colorText(findMe) {
  37.   // put to boldface the argument
  38.   var body = DocumentApp.getActiveDocument().getBody();
  39.   var foundElement = body.findText(findMe);
  40.  
  41.   while (foundElement != null) {
  42.     // Get the text object from the element
  43.     var foundText = foundElement.getElement().asText();
  44.  
  45.     // Where in the Element is the found text?
  46.     var start = foundElement.getStartOffset();
  47.     var end = foundElement.getEndOffsetInclusive();
  48.  
  49.     // Change the foreground color to red
  50.     foundText.setForegroundColor(start, end, '#C80B0B')
  51.  
  52.     // Find the next match
  53.     foundElement = body.findText(findMe, foundElement);
  54.   }
  55. }
  56. function linkTex(findMe) {
  57.   // put to boldface the argument
  58.   var body = DocumentApp.getActiveDocument().getBody();
  59.   var foundElement = body.findText(findMe);
  60.  
  61.   while (foundElement != null) {
  62.     // Get the text object from the element
  63.     var foundText = foundElement.getElement().asText();
  64.  
  65.     // Where in the Element is the found text?
  66.     var start = foundElement.getStartOffset();
  67.     var end = foundElement.getEndOffsetInclusive();
  68.     var TXT = foundText.getText();
  69.     // Change the foreground color to red
  70.     foundText.setLinkUrl(start, end, TXT)
  71.  
  72.     // Find the next match
  73.     foundElement = body.findText(findMe, foundElement);
  74.   }
  75. }
  76. function GreyTex(findMe) {
  77.   // put to boldface the argument
  78.   var body = DocumentApp.getActiveDocument().getBody();
  79.   var foundElement = body.findText(findMe);
  80.  
  81.   while (foundElement != null) {
  82.     // Get the text object from the element
  83.     var foundText = foundElement.getElement().asText();
  84.  
  85.     // Where in the Element is the found text?
  86.     var start = foundElement.getStartOffset();
  87.     var end = foundElement.getEndOffsetInclusive();
  88.     // Change the foreground color to grey
  89.     foundText.setForegroundColor(start, end, '#B4ADAD')
  90.  
  91.     // Find the next match
  92.     foundElement = body.findText(findMe, foundElement);
  93.   }
  94. }
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement