Capitalize first letter of sentences in pasted document, even when the sentence starts with a single quotation mark

@Yurcee Thank you so much for your help! I took your code to Chat GPT and modified it slightly to not change the initial punctuation (because I actually need the single quotation marks to be in it). After a few edit rounds, I got something to work perfectly! I’m going to include it here in case anyone else has the same question. I was new to Templater, but it looks like you have to use the command “Open insert template modal” to actually get the script to run.

Here’s the script:

<%*
// Get the current file
const currentFile = app.workspace.getActiveFile();
if (!currentFile) return;

// Read the file content
let fileContent = await app.vault.read(currentFile);

// Separate YAML front matter from the rest of the content
const yamlRegex = /^---\n[\s\S]*?\n---\n/gm;
const yamlMatch = fileContent.match(yamlRegex);
const yamlBlock = yamlMatch ? yamlMatch[0] : '';
let content = fileContent.replace(yamlRegex, '');

// Capitalize the first letter of each sentence, including those starting with a single quotation mark
// This includes handling sentences after newlines and those after sentence-ending punctuation
content = content.replace(/(^|\n|\.\s+|\?\s+|\!\s+|\n['"]\s*)\s*([a-z])/gm, (match, p1, p2) => p1 + p2.toUpperCase());

// Recombine the YAML block with the updated content
const updatedContent = yamlBlock + content;

// Write back the changes
await app.vault.modify(currentFile, updatedContent);
%>