Insert Callout Template #922
Replies: 12 comments 6 replies
-
Simple and functional ! Great !! |
Beta Was this translation helpful? Give feedback.
-
thanks |
Beta Was this translation helpful? Give feedback.
-
Love this, thanks! |
Beta Was this translation helpful? Give feedback.
-
I made a cleaner version with some emojis indicating the color and icon of the callout: <%*
const callouts = {
note: '🔵 ✏ Note',
info: '🔵 ℹ Info',
todo: '🔵 🔳 Todo',
tip: '🌐 🔥 Tip / Hint / Important',
abstract: '🌐 📋 Abstract / Summary / TLDR',
question: '🟡 ❓ Question / Help / FAQ',
quote: '🔘 💬 Quote / Cite',
example: '🟣 📑 Example',
success: '🟢 ✔ Success / Check / Done',
warning: '🟠 ⚠ Warning / Caution / Attention',
failure: '🔴 ❌ Failure / Fail / Missing',
danger: '🔴 ⚡ Danger / Error',
bug: '🔴 🐞 Bug',
};
const type = await tp.system.suggester(Object.values(callouts), Object.keys(callouts), true, 'Select callout type.');
const fold = await tp.system.suggester(['None', 'Expanded', 'Collapsed'], ['', '+', '-'], true, 'Select callout fold option.');
const title = await tp.system.prompt('Title:', '', true);
let content = await tp.system.prompt('Content (New line -> Shift + Enter):', '', true, true);
content = content.split('\n').map(line => `> ${line}`).join('\n')
const calloutHead = `> [!${type}]${fold} ${title}\n`;
tR += calloutHead + content
-%> |
Beta Was this translation helpful? Give feedback.
-
Really like your version, much cleaner than my original version. 👍 |
Beta Was this translation helpful? Give feedback.
-
Not mine, found on the internet <%*
//get selection
noteContent = await tp.file.selection();
// Check if the selected text has one or two strings
let numberOfStrings = noteContent.split('\n').length;
let titre;
let corps;
if (numberOfStrings === 1) {
// Ingest titre only
titre = noteContent.match(/.*/g)[0];
corps = "";
} else if (numberOfStrings > 1) {
// Ingest titre and corps
titre = noteContent.match(/.*(?=\n.*)/g)[0];
corps = noteContent.match(/(?<=.*\n)(.|\n)*/g).join('\n');
}
console.log(corps);
// list callouts
const callouts = {
note: '🔵 ✏️ Note',
info: '🟢 ℹ️ Info',
todo: '🟢 ✔️ Todo',
asidecleanright: '⚪️ 💬commentaire',
tip: '🌐 🔥 Tip / Hint / Important',
abstract: '🌐 📋 Abstract / Summary / TLDR',
question: '🟡 ❓ Question / Help / FAQ',
quote: '🔘 💬 Quote / Cite',
example: '🟣 📑 Example',
success: '🟢 ✔️ Success / Check / Done',
warning: '🟠 ⚠️ Warning / Caution / Attention',
failure: '🔴 ❌ Failure / Fail / Missing',
danger: '🔴 ⚡️ Danger / Error',
resources: 'resources',
code: 'code',
code2: 'code version 2',
proof: 'transparent callout'
};
// return callout
const type = await tp.system.suggester(Object.values(callouts), Object.keys(callouts), true, 'Select callout type.');
//return fold
const fold = await tp.system.suggester(['None', 'Expanded', 'Collapsed'], ['', '+', '-'], true, 'Select callout fold option.');
//return titler
const title = await tp.system.prompt('Title:', titre , true);
//get array of lines
lines = corps.split('\n');
//make a new string with > prepended to each line
let newContent = "";
lines.forEach(l => {
newContent += '> ' + l + "\n";
})
//remove the last newline character
newContent = newContent.replace(/\n$/, "");
//define callout header
header = "> [!"+type+"]"+fold + " " + title +"\n";
// Return the complete callout block
return header + newContent;
%> |
Beta Was this translation helpful? Give feedback.
-
So im kinda new to useing this type of template what is the diff betwee <%* or <%_* or <%-* I have also see <%+* on other scripts, I tried searching but I dont know what terms to search for. Is there any documenation you can point me at? |
Beta Was this translation helpful? Give feedback.
-
Nice, I'm seeing that this leaves quite a few possibilities. |
Beta Was this translation helpful? Give feedback.
-
Here's a slightly modified version.
To add content to the callout, press RETURN and continue typing. Otherwise, leave the callout as-is to get a title-only callout. <%*
const callouts = {
// Colors: 🟥🟧🟨🟩🟦🟪⬛️⬜️🟫
"bug": "🟥 Bug",
"danger": "🟥 Danger | Error",
"fail": "🟥 Fail | Failure | Missing",
"warning": "🟧 Warning | Attention | Caution",
"help": "🟧 Help | FAQ | Question",
"success": "🟩 Success | Done | Check",
"abstract": "🟦 Abstract | Summary | TLDR",
"example": "🟦 Example",
"hint": "🟦 Hint | Important | Tip",
"info": "🟦 Info",
"note": "🟦 Note",
"todo": "🟦 Todo",
"cite": "⬜️ Cite | Quote",
// Custom types (via Callout Manager)
"link": "🟨 Link",
"presentation": "🟨 Presentation",
"money": "🟨 Money",
"chart": "🟦 Line Chart",
"visual": "🟪 Styled Quote | Visual Quote",
"visual-img": "🟪 Styled Image | Visual Image",
"image": "🟪 Image",
"brain": "🟪 Brain | AI",
};
const typeNames = [];
const typeLabels = [];
Object.keys(callouts)
.sort() // Remove this line to use predefined order.
.forEach(key =>
typeNames.push(key) && typeLabels.push(callouts[key])
);
let calloutType = await tp.system.suggester(
typeLabels,
typeNames,
false,
"Select callout type."
);
// Stop here when the prompt was cancelled (ESC).
if (!calloutType) {
return;
}
let foldState = await tp.system.suggester(
["Static", "Expanded", "Collapsed"],
["", "+", "-"],
false,
"Select callout folding option."
);
let title = await tp.file.selection();
if (!title) {
title = await tp.system.prompt("Title Text", "");
}
_%>
> [!<% calloutType %>]<% foldState %> <% title %><%* tp.file.cursor() %> |
Beta Was this translation helpful? Give feedback.
-
I modified the version of @stracker-phil so that the selected text is put into the callout content rather than the title. Summary:
<%*
const callouts = {
// Colors: 🟥🟧🟨🟩🟦🟪⬛️⬜️🟫
"bug": "🟥 Bug",
"danger": "🟥 Danger | Error",
"fail": "🟥 Fail | Failure | Missing",
"warning": "🟧 Warning | Attention | Caution",
"help": "🟧 Help | FAQ | Question",
"success": "🟩 Success | Done | Check",
"abstract": "🟦 Abstract | Summary | TLDR",
"example": "🟦 Example",
"hint": "🟦 Hint | Important | Tip",
"info": "🟦 Info",
"note": "🟦 Note",
"todo": "🟦 Todo",
"cite": "⬜️ Cite | Quote",
// Custom types (via Callout Manager)
};
const typeNames = [];
const typeLabels = [];
Object.keys(callouts)
.sort() // Remove this line to use predefined order.
.forEach(key =>
typeNames.push(key) && typeLabels.push(callouts[key])
);
let calloutType = await tp.system.suggester(
typeLabels,
typeNames,
false,
"Select callout type."
);
let title = await tp.system.prompt("Callout Header:")
// Stop here when the prompt was cancelled (ESC).
if (!calloutType) {
return;
}
let foldState = await tp.system.suggester(
["Static", "Expanded", "Collapsed"],
["", "+", "-"],
false,
"Select callout folding option."
);
let content = await tp.file.selection();
// Format each line of content to be part of the callout
const formattedContent = content.split('\n').map(line => `> ${line}`).join('\n');
_%>
> [!<% calloutType %>]<% foldState %> <% title %>
<% formattedContent %> <%* tp.file.cursor() %> |
Beta Was this translation helpful? Give feedback.
-
Hi SilentVoid13, really great snippet. I haven't seen one but do you think you might be able to incorporate the multi-column callout to this. I think it would be a great addition. Thanks |
Beta Was this translation helpful? Give feedback.
-
Thank you all for this. I've just gotten started with Obsidian and I am obsessed. ;-) Love the callout features and I've been wanting a fast way to create them. I took a little of what each of you did and added my own tweaks - you know, to each their own. Aside from organizing the declaration of the callouts in a way that helped me and a few other code changes the main enhancements that I made were to:
I hope this is a help to the community! Happy Coding! Primary ChangesFile: insert-callout-template-pnx.md <%*
const callouts = {
// Callout name | Prompt Name | UI Icon Description
// Red - Critical/Error group
"bug": "🟥 🪳 Bug", // Bug icon
"danger": "🟥 ⚡️ Danger", // Lightning Bolt icon
"error": "🟥 ⚡️ Error", // Lightning Bolt icon
"fail": "🟥 ❌ Fail", // 'X' mark icon
"failure": "🟥 ❌ Failure", // 'X' mark icon
"missing": "🟥 ❌ Missing", // 'X' mark icon
// Orange - Warning group
"attention": "🟧 ⚠️ Attention", // Exclamation Sign icon
"caution": "🟧 ⚠️ Caution", // Exclamation Sign icon
"warning": "🟧 ⚠️ Warning", // Exclamation Sign icon
"help": "🟧 ❓ Help", // Question Mark in Circle icon
"faq": "🟧 ❓ FAQ", // Question Mark in Circle icon
"question": "🟧 ❓ Question", // Question Mark in Circle icon
// Green - Success group
"done": "🟩 ✅ Done", // Green Checkmark icon
"check": "🟩 ✅ Check", // Green Checkmark icon
"success": "🟩 ✅ Success", // Green Checkmark icon
// Blue - Information group
"info": "🟦 ⓘ Info", // 'i' in Circle icon
"note": "🟦 ✏️ Note", // Pencil icon
"abstract": "🟦 📋 Abstract", // Clipboard icon
"summary": "🟦 📋 Summary", // Clipboard icon
"tldr": "🟦 📋 TL;DR;", // Clipboard icon
"example": "🟦 📑 Example", // Outline icon (ish so a folder?)
"hint": "🟦 🔥 Hint", // Flame icon
"important": "🟦 🔥 Important", // Flame icon
"tip": "🟦 🔥 Tip", // Flame icon
"todo": "🟦 ✅ Todo", // Checkmark in Circle icon
// White - Quotes
"cite": "⬜️ ⍘ Cite", // Quotation Mark icon
"quote": "⬜️ ⍘ Quote", // Quotation Mark icon
// Custom types (via Callout Manager)
};
const typeNames = [];
const typeLabels = [];
Object.keys(callouts)
// Uncomment the line below to sort the callouts order alphabetically
//.sort()
.forEach((key, index) => {
typeNames.push(key);
// Add number prefix to each option for keyboard selection
typeLabels.push(`${index+1}. ${callouts[key]}`);
});
let calloutType = await tp.system.suggester(
typeLabels,
typeNames,
false,
"Select callout type (use numbers 1-" + typeLabels.length + " to select)"
);
// Stop here when the prompt was cancelled (ESC).
if (!calloutType) {
return;
}
// Extract the main name from the label to pre-fill the header
let defaultTitle = callouts[calloutType].split(' ').pop();
let title = await tp.system.prompt("Callout Header:", defaultTitle);
let foldState = await tp.system.suggester(
["1. Static", "2. Expanded", "3. Collapsed"],
["", "+", "-"],
false,
"Select callout folding option (use numbers 1-3 to select)"
);
let content = await tp.file.selection();
// Format each line of content to be part of the callout
const formattedContent = content.split('\n').map(line => `> ${line}`).join('\n');
_%>
> [!<% calloutType %>]<% foldState %> <% title %>
<% formattedContent %> <%* tp.file.cursor() %> Icon Only VersionFile: insert-callout-template-icons-pnx.md <%*
const callouts = {
// Callout name | Icon | UI Icon Description
// Red - Critical/Error group
"bug": " 🟥 🪳", // Bug icon
"danger": " 🟥 ⚡️", // Lightning Bolt icon
"fail": " 🟥 ❌", // 'X' mark icon
// Orange - Warning group
"attention": " 🟧 ⚠️", // Exclamation Sign icon
"help": " 🟧 ❓", // Question Mark in Circle icon
// Green - Success group
"done": " 🟩 ✅", // Green Checkmark icon
// Blue - Information group
"info": " 🟦 ⓘ", // 'i' in Circle icon
"note": " 🟦 ✏️", // Pencil icon
"abstract": " 🟦 📋", // Clipboard icon
"example": "🟦 📑", // Outline icon (ish so a folder?)
"hint": "🟦 🔥", // Flame icon
"todo": "🟦 ✅", // Checkmark in Circle icon
// White - Quotes
"cite": "⬜️ ⍘", // Quotation Mark icon
// Custom types (via Callout Manager)
};
const typeNames = [];
const typeLabels = [];
Object.keys(callouts)
// Uncomment the line below to sort the callouts order alphabetically
//.sort()
.forEach((key, index) => { typeNames.push(key);
// Add number prefix to each option for keyboard selection
typeLabels.push(`${index+1}. ${callouts[key]} ${key}`);
});
let calloutType = await tp.system.suggester(
typeLabels,
typeNames,
false,
"Select callout type (use numbers 1-" + typeLabels.length + " to select)"
);
// Stop here when the prompt was cancelled (ESC).
if (!calloutType) {
return;
}
let title = await tp.system.prompt("Callout Header:");
let foldState = await tp.system.suggester(
["1. Static", "2. Expanded", "3. Collapsed"],
["", "+", "-"],
false,
"Select callout folding option (use numbers 1-3 to select)"
);
let content = await tp.file.selection();
// Format each line of content to be part of the callout
const formattedContent = content.split('\n').map(line => `> ${line}`).join('\n');
_%>
> [!<% calloutType %>]<% foldState %> <% title %>
<% formattedContent %> <%* tp.file.cursor() %> |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I wanted a template to insert a callout that prompts with valid callout types and this is what I came up with.
To use, insert the template in your note and run it with Templater. It will give you the following prompts...
Hope you find this useful.
Tip: You can use QuickAdd plugin to create a macro to insert this template & replace with Templater. This will let you insert a callout with only a couple of keystrokes, or even just one if you assign a hotkey to the macro.
Beta Was this translation helpful? Give feedback.
All reactions