Skip to content

Instantly share code, notes, and snippets.

@Kungsgeten
Last active June 21, 2019 09:53
Show Gist options
  • Save Kungsgeten/9e2f429ad9a4649360242a88f25b2a87 to your computer and use it in GitHub Desktop.
Save Kungsgeten/9e2f429ad9a4649360242a88f25b2a87 to your computer and use it in GitHub Desktop.
Colored suit symbols in Google Docs
function replaceStringAndSetColor(body, str, replacement, color) {
var foundElement = body.findText(str);
while (foundElement != null) {
var foundText = foundElement.getElement().asText();
var start = foundElement.getStartOffset();
var end = foundElement.getEndOffsetInclusive();
foundText.setForegroundColor(start, end, color);
foundElement = body.findText(str, foundElement);
}
body.replaceText(str, replacement);
}
function suitSymbols() {
var body = DocumentApp.getActiveDocument().getBody();
replaceStringAndSetColor(body, "!c", "♣", "#0000ff");
replaceStringAndSetColor(body, "!d", "♦", "#ffa500");
replaceStringAndSetColor(body, "!h", "♥", "#ff0000");
replaceStringAndSetColor(body, "!s", "♠", "#000000");
}
@Kungsgeten
Copy link
Author

When this script is run it will replace !c !d !h and !s with colored suit symbols.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment