Template for insert callout

This template is so much fun. Thanks!

I wanted to use a Template Hotkey (similar to the core Insert callout command) for one specific callout that I was using a lot and skip the prompts. Select the text, type the hotkey, done.

Here are two versions: one that asks for the folded state, and the barebones one that that simply wraps the text you’ve selected. Change the !tbox bit at the bottom to whatever callout you want to use.

Fold or not? → wrap →

<%*
//get selection
noteContent = tp.file.selection();
//return fold
const fold = await tp.system.suggester(['None', 'Expanded', 'Collapsed'], ['', '+', '-'], true, 'Select callout fold option.');
//get array of lines
lines = noteContent.split('\n')
//make a new string with > prepended to each line
let newContent = "";
lines.forEach(l => {
	newContent += '> ' + l + "\n";
})
//remove the last newline character
//inset your desired callout after the !
newContent = newContent.replace(/\n$/, "");
//define callout header
header = ">[!tbox]"+fold + "\n"
// Return the complete callout block
return header + newContent;
%>

Wrap only →

<%*
//get selection
noteContent = tp.file.selection();
//get array of lines
lines = noteContent.split('\n')
//make a new string with > prepended to each line
let newContent = "";
lines.forEach(l => {
	newContent += '> ' + l + "\n";
})
//remove the last newline character
//inset your desired callout after the !
newContent = newContent.replace(/\n$/, "");
//define callout header
header = ">[!tbox]"+ "\n"
// Return the complete callout block
return header + newContent;
%>
1 Like