Skip to content

Instantly share code, notes, and snippets.

@StefanoChiodino
Last active December 6, 2022 16:43
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 StefanoChiodino/4c4450bf8ccf5851b83a740c217490a2 to your computer and use it in GitHub Desktop.
Save StefanoChiodino/4c4450bf8ccf5851b83a740c217490a2 to your computer and use it in GitHub Desktop.
python_regex = "((\\w{2,}\\.){2,}(\\w{2,}))";
path_regex = "(\\w+\\/){2,}(\\w+\\.\\w+)(:\\d+)?";
code_style = {}
code_style[DocumentApp.Attribute.FONT_FAMILY] = 'Courier New';
function styleMatches(regex) {
doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
match = null;
while (true) {
if (match)
match = body.findText(regex, match);
else
match = body.findText(regex);
if (match == null)
break;
var start = match.getStartOffset();
var end = match.getEndOffsetInclusive();
// Hack to avoid styling URLs.
if (match.getElement().getText()[start - 1] == "/" || match.getElement().getText()[end + 1] == "/")
continue
console.log("styling " + match.getElement().getText().slice(start, end + 1));
match.getElement().setAttributes(start, end, code_style);
}
}
function monocaser() {
styleMatches(python_regex);
styleMatches(path_regex);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment