mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
add support for vitepress blocks
This commit is contained in:
parent
528facf88d
commit
469bdcef2f
@ -146,9 +146,22 @@ const readSyncedUTF8file = (filename: string): string => {
|
||||
return readFileSync(filename, 'utf8');
|
||||
};
|
||||
|
||||
const transformToBlockQuote = (content: string, type: string) => {
|
||||
const title = type === 'warning' ? 'Warning' : 'Note';
|
||||
return `> **${title}** \n> ${content.replace(/\n/g, '\n> ')}`;
|
||||
const blockIcons: Record<string, string> = {
|
||||
tip: '💡 ',
|
||||
danger: '‼️ ',
|
||||
};
|
||||
|
||||
const capitalize = (word: string) => word[0].toUpperCase() + word.slice(1);
|
||||
|
||||
const transformToBlockQuote = (content: string, type: string, customTitle?: string | null) => {
|
||||
if (vitepress) {
|
||||
const vitepressType = type === 'note' ? 'info' : type;
|
||||
return `::: ${vitepressType} ${customTitle || ''}\n${content}\n:::`;
|
||||
} else {
|
||||
const icon = blockIcons[type] || '';
|
||||
const title = `${icon}${customTitle || capitalize(type)}`;
|
||||
return `> **${title}** \n> ${content.replace(/\n/g, '\n> ')}`;
|
||||
}
|
||||
};
|
||||
|
||||
const injectPlaceholders = (text: string): string =>
|
||||
@ -194,8 +207,8 @@ const transformMarkdown = (file: string) => {
|
||||
}
|
||||
|
||||
// Transform codeblocks into block quotes.
|
||||
if (['note', 'tip', 'warning'].includes(c.lang)) {
|
||||
return [remark.parse(transformToBlockQuote(c.value, c.lang))];
|
||||
if (['note', 'tip', 'warning', 'danger'].includes(c.lang)) {
|
||||
return [remark.parse(transformToBlockQuote(c.value, c.lang, c.meta))];
|
||||
}
|
||||
|
||||
return [c];
|
||||
|
Loading…
x
Reference in New Issue
Block a user