Last active
December 6, 2022 16:43
-
-
Save StefanoChiodino/4c4450bf8ccf5851b83a740c217490a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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