docs: improve admonition styles (#1880)
This commit is contained in:
@@ -16,6 +16,8 @@ import { mangle } from "$marked-mangle";
|
||||
|
||||
Marked.marked.use(mangle());
|
||||
|
||||
const ADMISSION_REG = /^<p>\[(info|warn|tip)\]:\s/;
|
||||
|
||||
class DefaultRenderer extends Marked.Renderer {
|
||||
text(text: string): string {
|
||||
// Smartypants typography enhancement
|
||||
@@ -97,6 +99,25 @@ class DefaultRenderer extends Marked.Renderer {
|
||||
out += `</div>`;
|
||||
return out;
|
||||
}
|
||||
|
||||
blockquote(quote: string): string {
|
||||
const match = quote.match(ADMISSION_REG);
|
||||
console.log(match, quote);
|
||||
if (match) {
|
||||
const label: Record<string, string> = {
|
||||
tip: "Tip",
|
||||
warn: "Warning",
|
||||
info: "Info",
|
||||
};
|
||||
const type = match[1];
|
||||
quote = quote.slice(match[0].length);
|
||||
const icon = `<svg class="icon"><use href="/icons.svg#${type}" /></svg>`;
|
||||
return `<blockquote class="admonition ${type}">\n<span class="admonition-header">${icon}${
|
||||
label[type]
|
||||
}</span>${quote}</blockquote>\n`;
|
||||
}
|
||||
return `<blockquote>\n${quote}</blockquote>\n`;
|
||||
}
|
||||
}
|
||||
|
||||
export interface MarkdownOptions {
|
||||
|
||||
Reference in New Issue
Block a user