Obsidian Callouts #497
-
|
Hey there, I tried repurposing the existing syntax of callouts from To this: But am really struggling. Does anyone have pointers on what to do? I tried making a custom script and then removing the old one but I was failing. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Is that meant to be done as a pre-processing step, or during the build process? function convertCallouts(md, lineEnding = '\n') {
const types = ['note', 'info', 'todo']; // Add other callout types if necessary
const pattern = `:::(${types.join('|')})\\n([\\s\\S]*?)\\n:::`;
const regex = new RegExp(pattern, 'g');
const normalized = md.replace(/\r\n|\r/g, '\n');
const replaced = normalized.replace(
regex,
(_, type, content) => {
const identifier = type.charAt(0).toUpperCase() + type.slice(1);
const lines = content.split('\n').map(line => `> ${line}`).join('\n');
return `> [!${identifier}]\n${lines}`;
}
);
return lineEnding === '\n' ? replaced : replaced.replace(/\n/g, lineEnding);
}Example: const markdown = `
Some paragraph here.
:::note
Split keyboards are not for everyone.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
:::
Another paragraph.
`;
console.log(convertCallouts(markdown));Output: |
Beta Was this translation helpful? Give feedback.
-
|
Alright I actually did get it to work, here's what I did: |
Beta Was this translation helpful? Give feedback.
Alright I actually did get it to work, here's what I did: