Last active
May 20, 2024 21:37
-
-
Save greenido/7cf699f6e88ea214127ba97256b4cf35 to your computer and use it in GitHub Desktop.
convert raw output of GPT to a better google doc format - mainly for trip planning
This file contains 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
// | |
// Change the main headlines (###) to Headline #2 | |
// | |
function changeLinesToHeading2() { | |
// Get the active document | |
var doc = DocumentApp.getActiveDocument(); | |
// Get the body of the document | |
var body = doc.getBody(); | |
// Iterate through all paragraphs in the document | |
var paragraphs = body.getParagraphs(); | |
for (var i = 0; i < paragraphs.length; i++) { | |
var paragraph = paragraphs[i]; | |
var text = paragraph.getText(); | |
// If a paragraph starts with ### | |
if (text.startsWith('###')) { | |
// Set the paragraph to Heading 2 | |
paragraph.setHeading(DocumentApp.ParagraphHeading.HEADING2); | |
} | |
} | |
} | |
// | |
// Change the main parts of the day to be *BOLD* | |
// | |
function blodMorningAfternoonEvening() { | |
boldWords("morning"); | |
boldWords("Afternoon"); | |
boldWords("Evening"); | |
} | |
// | |
// Search for a keyword in the doc and make it bold | |
// | |
function boldWords(keyword) { | |
// Get the active document | |
var doc = DocumentApp.getActiveDocument(); | |
// Get the body of the document | |
var body = doc.getBody(); | |
// Find all instances of the word "keyword" | |
var searchResult = body.findText(keyword); | |
while (searchResult) { | |
// Get the found element | |
var element = searchResult.getElement(); | |
// Get the start and end offsets of the found text | |
var start = searchResult.getStartOffset(); | |
var end = searchResult.getEndOffsetInclusive(); | |
// Set the text to bold | |
element.asText().setBold(start, end, true); | |
// Find the next occurrence of keyword | |
searchResult = body.findText(keyword, searchResult); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment