Skip to content

Instantly share code, notes, and snippets.

@YaoYYoung
Last active December 13, 2024 09:45
Show Gist options
  • Save YaoYYoung/926e9152ac93857fda874050a9d9ee6e to your computer and use it in GitHub Desktop.
Save YaoYYoung/926e9152ac93857fda874050a9d9ee6e to your computer and use it in GitHub Desktop.
[
// Owing to my existing `callout-diy.css` in the `.obsidian/snippet` folder,
// which looks all similar to the codes below,
// I haven't delete related callouts codes in `c` `1` `2` `3` `4` `5` `6` `g` snippets,
// .callout[data-callout="important"] {
// --callout-color: 251, 70, 76;
// --callout-icon: lucide-star
// }
// 👉👉 Highlight & Callout
// c -> purple <-> critical
// 1 -> red <-> important
// 2 -> orange <-> siginificant
// 3 -> yellow <-> notable
// 4 -> blue <-> minor
// 5 -> green <-> trivial
// 6 = g -> grey <-> nothing
// c 🟢
{trigger: "c", replacement: (sel) => {
if (sel = sel.replaceAll(/\$(\d.*?)\$/g, "\${{ $1 }}\$$")) ; // sensitive_math
let count = 0;
const regex_highlight = /<mark style="background: #[0-9a-fA-F]{6,8};">(.*?)<\/mark>/g;
const highlights = [
"#aa88ffaa", // c = 0 = purple
"#ff6666aa", // 1 = red
"#ee9944aa", // 2 = orange
"#ffcc33aa", // 3 = yellow
"#66aaddaa", // 4 = blue
"#88cc66aa", // 5 = green
"#ccccccaa", // 6 = grey
];
if (sel.match(regex_highlight)) {
sel = sel.replaceAll(highlights[1], highlights[0]); // 1 -> c
sel = sel.replaceAll(highlights[2], highlights[1]); // 2 -> 1
sel = sel.replaceAll(highlights[3], highlights[2]); // 3 -> 2
sel = sel.replaceAll(highlights[4], highlights[3]); // 4 -> 3
sel = sel.replaceAll(highlights[5], highlights[4]); // 5 -> 4
sel = sel.replaceAll(highlights[6], highlights[5]); // 6 -> 5
count++;
}
const regex_callouts_title = /> \[!(?:.*?)\](\+|\-)/g;
const callouts = [
"[!critical]", // c = 0
"[!important]", // 1
"[!significant]", // 2
"[!notable]", // 3
"[!minor]", // 4
"[!trivial]", // 5
"[!negligible]", // 6
];
if (sel.match(regex_callouts_title)) {
sel = sel.replaceAll(callouts[1], callouts[0]); // 1 -> c
sel = sel.replaceAll(callouts[2], callouts[1]); // 2 -> 1
sel = sel.replaceAll(callouts[3], callouts[2]); // 3 -> 2
sel = sel.replaceAll(callouts[4], callouts[3]); // 4 -> 3
sel = sel.replaceAll(callouts[5], callouts[4]); // 5 -> 4
sel = sel.replaceAll(callouts[6], callouts[5]); // 6 -> 5
count++;
}
if (!count) {
sel = "<mark style=\"background: " + highlights[0] + ";\">" + sel + "</mark>"; // + highlight
// sel = "> " + callouts[0] + "+ " + sel; // + callout
}
return sel;
}, options: "vtA"},
// 1 🟢
{trigger: "1", replacement: (sel) => {
if (sel = sel.replaceAll(/\$(\d.*?)\$/g, "\${{ $1 }}\$$")) ; // sensitive_math
let count = 0;
const regex_highlight = /<mark style="background: #[0-9a-fA-F]{6,8};">(.*?)<\/mark>/g;
const highlights = [
"#aa88ffaa", // c = 0 = purple
"#ff6666aa", // 1 = red
"#ee9944aa", // 2 = orange
"#ffcc33aa", // 3 = yellow
"#66aaddaa", // 4 = blue
"#88cc66aa", // 5 = green
"#ccccccaa", // 6 = grey
];
if (sel.match(regex_highlight)) {
sel = sel.replaceAll(highlights[0], highlights[1]); // c -> 1
sel = sel.replaceAll(highlights[2], highlights[1]); // 2 -> 1
sel = sel.replaceAll(highlights[3], highlights[2]); // 3 -> 2
sel = sel.replaceAll(highlights[4], highlights[3]); // 4 -> 3
sel = sel.replaceAll(highlights[5], highlights[4]); // 5 -> 4
sel = sel.replaceAll(highlights[6], highlights[5]); // 6 -> 5
count++;
}
const regex_callouts_title = /> \[!(?:.*?)\](\+|\-)/g;
const callouts = [
"[!critical]", // c = 0
"[!important]", // 1
"[!significant]", // 2
"[!notable]", // 3
"[!minor]", // 4
"[!trivial]", // 5
"[!negligible]", // 6
];
if (sel.match(regex_callouts_title)) {
sel = sel.replaceAll(callouts[0], callouts[1]); // c -> 1
sel = sel.replaceAll(callouts[2], callouts[1]); // 2 -> 1
sel = sel.replaceAll(callouts[3], callouts[2]); // 3 -> 2
sel = sel.replaceAll(callouts[4], callouts[3]); // 4 -> 3
sel = sel.replaceAll(callouts[5], callouts[4]); // 5 -> 4
sel = sel.replaceAll(callouts[6], callouts[5]); // 6 -> 5
count++;
}
if (!count) {
sel = "<mark style=\"background: " + highlights[1] + ";\">" + sel + "</mark>"; // + highlight
// sel = "> " + callouts[1] + "+ " + sel; // + callout
}
return sel;
}, options: "vtA"},
// 2 🟢
{trigger: "2", replacement: (sel) => {
if (sel = sel.replaceAll(/\$(\d.*?)\$/g, "\${{ $1 }}\$$")) ; // sensitive_math
let count = 0;
const regex_highlight = /<mark style="background: #[0-9a-fA-F]{6,8};">(.*?)<\/mark>/g;
const highlights = [
"#aa88ffaa", // c = 0 = purple
"#ff6666aa", // 1 = red
"#ee9944aa", // 2 = orange
"#ffcc33aa", // 3 = yellow
"#66aaddaa", // 4 = blue
"#88cc66aa", // 5 = green
"#ccccccaa", // 6 = grey
];
if (sel.match(regex_highlight)) {
sel = sel.replaceAll(highlights[1], highlights[2]); // 1 -> 2
sel = sel.replaceAll(highlights[0], highlights[1]); // c -> 1
sel = sel.replaceAll(highlights[3], highlights[2]); // 3 -> 2
sel = sel.replaceAll(highlights[4], highlights[3]); // 4 -> 3
sel = sel.replaceAll(highlights[5], highlights[4]); // 5 -> 4
sel = sel.replaceAll(highlights[6], highlights[5]); // 6 -> 5
count++;
}
const regex_callouts_title = /> \[!(?:.*?)\](\+|\-)/g;
const callouts = [
"[!critical]", // c = 0
"[!important]", // 1
"[!significant]", // 2
"[!notable]", // 3
"[!minor]", // 4
"[!trivial]", // 5
"[!negligible]", // 6
];
if (sel.match(regex_callouts_title)) {
sel = sel.replaceAll(callouts[1], callouts[2]); // 1 -> 2
sel = sel.replaceAll(callouts[0], callouts[1]); // c -> 1
sel = sel.replaceAll(callouts[3], callouts[2]); // 3 -> 2
sel = sel.replaceAll(callouts[4], callouts[3]); // 4 -> 3
sel = sel.replaceAll(callouts[5], callouts[4]); // 5 -> 4
sel = sel.replaceAll(callouts[6], callouts[5]); // 6 -> 5
count++;
}
if (!count) {
sel = "<mark style=\"background: " + highlights[2] + ";\">" + sel + "</mark>"; // + highlight
// sel = "> " + callouts[2] + "+ " + sel; // + callout
}
return sel;
}, options: "vtA"},
// 3 🟢
{trigger: "3", replacement: (sel) => {
if (sel = sel.replaceAll(/\$(\d.*?)\$/g, "\${{ $1 }}\$$")) ; // sensitive_math
let count = 0;
const regex_highlight = /<mark style="background: #[0-9a-fA-F]{6,8};">(.*?)<\/mark>/g;
const highlights = [
"#aa88ffaa", // c = 0 = purple
"#ff6666aa", // 1 = red
"#ee9944aa", // 2 = orange
"#ffcc33aa", // 3 = yellow
"#66aaddaa", // 4 = blue
"#88cc66aa", // 5 = green
"#ccccccaa", // 6 = grey
];
if (sel.match(regex_highlight)) {
sel = sel.replaceAll(highlights[2], highlights[3]); // 2 -> 3
sel = sel.replaceAll(highlights[1], highlights[2]); // 1 -> 2
sel = sel.replaceAll(highlights[0], highlights[1]); // c -> 1
sel = sel.replaceAll(highlights[4], highlights[3]); // 4 -> 3
sel = sel.replaceAll(highlights[5], highlights[4]); // 5 -> 4
sel = sel.replaceAll(highlights[6], highlights[5]); // 6 -> 5
count++;
}
const regex_callouts_title = /> \[!(?:.*?)\](\+|\-)/g;
const callouts = [
"[!critical]", // c = 0
"[!important]", // 1
"[!significant]", // 2
"[!notable]", // 3
"[!minor]", // 4
"[!trivial]", // 5
"[!negligible]", // 6
];
if (sel.match(regex_callouts_title)) {
sel = sel.replaceAll(callouts[2], callouts[3]); // 2 -> 3
sel = sel.replaceAll(callouts[1], callouts[2]); // 1 -> 2
sel = sel.replaceAll(callouts[0], callouts[1]); // c -> 1
sel = sel.replaceAll(callouts[4], callouts[3]); // 4 -> 3
sel = sel.replaceAll(callouts[5], callouts[4]); // 5 -> 4
sel = sel.replaceAll(callouts[6], callouts[5]); // 6 -> 5
count++;
}
if (!count) {
sel = "<mark style=\"background: " + highlights[3] + ";\">" + sel + "</mark>"; // + highlight
// sel = "> " + callouts[3] + "+ " + sel; // + callout
}
return sel;
}, options: "vtA"},
// 4 🟢
{trigger: "4", replacement: (sel) => {
if (sel = sel.replaceAll(/\$(\d.*?)\$/g, "\${{ $1 }}\$$")) ; // sensitive_math
let count = 0;
const regex_highlight = /<mark style="background: #[0-9a-fA-F]{6,8};">(.*?)<\/mark>/g;
const highlights = [
"#aa88ffaa", // c = 0 = purple
"#ff6666aa", // 1 = red
"#ee9944aa", // 2 = orange
"#ffcc33aa", // 3 = yellow
"#66aaddaa", // 4 = blue
"#88cc66aa", // 5 = green
"#ccccccaa", // 6 = grey
];
if (sel.match(regex_highlight)) {
sel = sel.replaceAll(highlights[3], highlights[4]); // 3 -> 4
sel = sel.replaceAll(highlights[2], highlights[3]); // 2 -> 3
sel = sel.replaceAll(highlights[1], highlights[2]); // 1 -> 2
sel = sel.replaceAll(highlights[0], highlights[1]); // c -> 1
sel = sel.replaceAll(highlights[5], highlights[4]); // 5 -> 4
sel = sel.replaceAll(highlights[6], highlights[5]); // 6 -> 5
count++;
}
const regex_callouts_title = /> \[!(?:.*?)\](\+|\-)/g;
const callouts = [
"[!critical]", // c = 0
"[!important]", // 1
"[!significant]", // 2
"[!notable]", // 3
"[!minor]", // 4
"[!trivial]", // 5
"[!negligible]", // 6
];
if (sel.match(regex_callouts_title)) {
sel = sel.replaceAll(callouts[3], callouts[4]); // 3 -> 4
sel = sel.replaceAll(callouts[2], callouts[3]); // 2 -> 3
sel = sel.replaceAll(callouts[1], callouts[2]); // 1 -> 2
sel = sel.replaceAll(callouts[0], callouts[1]); // c -> 1
sel = sel.replaceAll(callouts[5], callouts[4]); // 5 -> 4
sel = sel.replaceAll(callouts[6], callouts[5]); // 6 -> 5
count++;
}
if (!count) {
sel = "<mark style=\"background: " + highlights[4] + ";\">" + sel + "</mark>"; // + highlight
// sel = "> " + callouts[4] + "+ " + sel; // + callout
}
return sel;
}, options: "vtA"},
// 5 🟢
{trigger: "5", replacement: (sel) => {
if (sel = sel.replaceAll(/\$(\d.*?)\$/g, "\${{ $1 }}\$$")) ; // sensitive_math
let count = 0;
const regex_highlight = /<mark style="background: #[0-9a-fA-F]{6,8};">(.*?)<\/mark>/g;
const highlights = [
"#aa88ffaa", // c = 0 = purple
"#ff6666aa", // 1 = red
"#ee9944aa", // 2 = orange
"#ffcc33aa", // 3 = yellow
"#66aaddaa", // 4 = blue
"#88cc66aa", // 5 = green
"#ccccccaa", // 6 = grey
];
if (sel.match(regex_highlight)) {
sel = sel.replaceAll(highlights[4], highlights[5]); // 4 -> 5
sel = sel.replaceAll(highlights[3], highlights[4]); // 3 -> 4
sel = sel.replaceAll(highlights[2], highlights[3]); // 2 -> 3
sel = sel.replaceAll(highlights[1], highlights[2]); // 1 -> 2
sel = sel.replaceAll(highlights[0], highlights[1]); // c -> 1
sel = sel.replaceAll(highlights[6], highlights[5]); // 6 -> 5
count++;
}
const regex_callouts_title = /> \[!(?:.*?)\](\+|\-)/g;
const callouts = [
"[!critical]", // c = 0
"[!important]", // 1
"[!significant]", // 2
"[!notable]", // 3
"[!minor]", // 4
"[!trivial]", // 5
"[!negligible]", // 6
];
if (sel.match(regex_callouts_title)) {
sel = sel.replaceAll(callouts[4], callouts[5]); // 4 -> 5
sel = sel.replaceAll(callouts[3], callouts[4]); // 3 -> 4
sel = sel.replaceAll(callouts[2], callouts[3]); // 2 -> 3
sel = sel.replaceAll(callouts[1], callouts[2]); // 1 -> 2
sel = sel.replaceAll(callouts[0], callouts[1]); // c -> 1
sel = sel.replaceAll(callouts[6], callouts[5]); // 6 -> 5
count++;
}
if (!count) {
sel = "<mark style=\"background: " + highlights[5] + ";\">" + sel + "</mark>"; // + highlight
// sel = "> " + callouts[5] + "+ " + sel; // + callout
}
return sel;
}, options: "vtA"},
// 6 🟢
{trigger: "6", replacement: (sel) => {
if (sel = sel.replaceAll(/\$(\d.*?)\$/g, "\${{ $1 }}\$$")) ; // sensitive_math
let count = 0;
const regex_highlight = /<mark style="background: #[0-9a-fA-F]{6,8};">(.*?)<\/mark>/g;
const highlights = [
"#aa88ffaa", // c = 0 = purple
"#ff6666aa", // 1 = red
"#ee9944aa", // 2 = orange
"#ffcc33aa", // 3 = yellow
"#66aaddaa", // 4 = blue
"#88cc66aa", // 5 = green
"#ccccccaa", // 6 = grey
];
if (sel.match(regex_highlight)) {
sel = sel.replaceAll(highlights[5], highlights[6]); // 5 -> 6
sel = sel.replaceAll(highlights[4], highlights[5]); // 4 -> 5
sel = sel.replaceAll(highlights[3], highlights[4]); // 3 -> 4
sel = sel.replaceAll(highlights[2], highlights[3]); // 2 -> 3
sel = sel.replaceAll(highlights[1], highlights[2]); // 1 -> 2
sel = sel.replaceAll(highlights[0], highlights[1]); // c -> 1
count++;
}
const regex_callouts_title = /> \[!(?:.*?)\](\+|\-)/g;
const callouts = [
"[!critical]", // c = 0
"[!important]", // 1
"[!significant]", // 2
"[!notable]", // 3
"[!minor]", // 4
"[!trivial]", // 5
"[!negligible]", // 6
];
if (sel.match(regex_callouts_title)) {
sel = sel.replaceAll(callouts[5], callouts[6]); // 5 -> 6
sel = sel.replaceAll(callouts[4], callouts[5]); // 4 -> 5
sel = sel.replaceAll(callouts[3], callouts[4]); // 3 -> 4
sel = sel.replaceAll(callouts[2], callouts[3]); // 2 -> 3
sel = sel.replaceAll(callouts[1], callouts[2]); // 1 -> 2
sel = sel.replaceAll(callouts[0], callouts[1]); // c -> 1
count++;
}
if (!count) {
sel = "<mark style=\"background: " + highlights[6] + ";\">" + sel + "</mark>"; // + highlight
// sel = "> " + callouts[6] + "+ " + sel; // + callout
}
return sel;
}, options: "vtA"},
// g = 6 🟢
{trigger: "g", replacement: (sel) => {
if (sel = sel.replaceAll(/\$(\d.*?)\$/g, "\${{ $1 }}\$$")) ; // sensitive_math
let count = 0;
const regex_highlight = /<mark style="background: #[0-9a-fA-F]{6,8};">(.*?)<\/mark>/g;
const highlights = [
"#aa88ffaa", // c = 0 = purple
"#ff6666aa", // 1 = red
"#ee9944aa", // 2 = orange
"#ffcc33aa", // 3 = yellow
"#66aaddaa", // 4 = blue
"#88cc66aa", // 5 = green
"#ccccccaa", // 6 = grey
];
if (sel.match(regex_highlight)) {
sel = sel.replaceAll(highlights[5], highlights[6]); // 5 -> 6
sel = sel.replaceAll(highlights[4], highlights[5]); // 4 -> 5
sel = sel.replaceAll(highlights[3], highlights[4]); // 3 -> 4
sel = sel.replaceAll(highlights[2], highlights[3]); // 2 -> 3
sel = sel.replaceAll(highlights[1], highlights[2]); // 1 -> 2
sel = sel.replaceAll(highlights[0], highlights[1]); // c -> 1
count++;
}
const regex_callouts_title = /> \[!(?:.*?)\](\+|\-)/g;
const callouts = [
"[!critical]", // c = 0
"[!important]", // 1
"[!significant]", // 2
"[!notable]", // 3
"[!minor]", // 4
"[!trivial]", // 5
"[!negligible]", // 6
];
if (sel.match(regex_callouts_title)) {
sel = sel.replaceAll(callouts[5], callouts[6]); // 5 -> 6
sel = sel.replaceAll(callouts[4], callouts[5]); // 4 -> 5
sel = sel.replaceAll(callouts[3], callouts[4]); // 3 -> 4
sel = sel.replaceAll(callouts[2], callouts[3]); // 2 -> 3
sel = sel.replaceAll(callouts[1], callouts[2]); // 1 -> 2
sel = sel.replaceAll(callouts[0], callouts[1]); // c -> 1
count++;
}
if (!count) {
sel = "<mark style=\"background: " + highlights[6] + ";\">" + sel + "</mark>"; // + highlight
// sel = "> " + callouts[6] + "+ " + sel; // + callout
}
return sel;
}, options: "vtA"},
// ✨✨ emoji-snippets
// d -> delete highlights | emojis | links | formats
// f -> 🌸 🌺 🍁
// n -> ✏️ ✍️ ✒️
// q -> ❔ ❓ 🌀
// r -> ✨ 🔥 💥
// s -> "👉🌟"
// x -> (✅) (⛔)
// d = delete -> highlights | emojis | links | formats
{trigger: "d", replacement: (sel) => {
if (sel = sel.replaceAll(/\$(\d.*?)\$/g, "\${{ $1 }}\$$")) ; // sensitive_math
let count = 0;
// highlights
const prefix_highlight = /<mark style="background: #[0-9a-fA-F]{6,8};">(.*?)/g;
const suffix_highlight = /(.*?)<\/mark>/g;
if (sel.match(prefix_highlight)) { sel = sel.replaceAll(prefix_highlight, "$1"); count ++; }
if (sel.match(suffix_highlight)) { sel = sel.replaceAll(suffix_highlight, "$1"); count ++; }
// emojis
// s q f r n x color else
const regex_emoji = /(👉|🌟|🌞|😎|❔|❓|🌀|🌸|🌺|🍁|✨|🔥|💥|✏️|✍️|✒️|((✅|⛔))|🔴|🟠|🟡|🟢|🔵|🟣|🤔|🤗|😇|🥰|🍂|🍃)+/g;
if (sel.match(regex_emoji)) { sel = sel.replaceAll(regex_emoji, ""); count ++; }
// links
const outlink = /\[([^\]]*?)\]\(([^\)]*?)\)/g;
const inlink_1 = /\[\[([^\]]*?)\|([^\]]*?)\]\]/g;
const inlink_2 = /\[\[([^\]]*?)\]\]/g;
if (sel.match(outlink)) { sel = sel.replaceAll(outlink, "$1"); count ++; } // []()
if (sel.match(inlink_1)) { sel = sel.replaceAll(inlink_1, "$2"); count ++; } // [[|]]
if (sel.match(inlink_2)) { sel = sel.replaceAll(inlink_2, "$1"); count ++; } // [[]]
// formats
const format_b = /\*\*(.*?)\*\*/g;
const format_h = /==(.*?)==/g;
const format_i = /\*(.*?)\*/g;
if (sel.match(format_b)) { sel = sel.replaceAll(format_b, "$1"); count ++; } // **bold**
if (sel.match(format_h)) { sel = sel.replaceAll(format_h, "$1"); count ++; } // ==highlight==
if (sel.match(format_i)) { sel = sel.replaceAll(format_i, "$1"); count ++; } // *italic*
if (!count) return false;
return sel;
}, options: "vctA"},
// f = 🌸 🌺 🍁
{trigger: "f", replacement: (sel) => {
sel = sel.replaceAll(/\$(\d.*?)\$/g, "\${{ $1 }}\$$"); // sensitive_math
// 递增 emoji
if (sel.match(/(🍁){6}/g)) return sel.replaceAll(/(🍁){6}/g, "");
if (sel.match(/(🍁){5}/g)) return sel.replaceAll(/(🍁){5}/g, "🍁🍁🍁🍁🍁🍁");
if (sel.match(/(🌺){4}/g)) return sel.replaceAll(/(🌺){4}/g, "🍁🍁🍁🍁🍁");
if (sel.match(/(🌺){3}/g)) return sel.replaceAll(/(🌺){3}/g, "🌺🌺🌺🌺");
if (sel.match(/(🌸){2}/g)) return sel.replaceAll(/(🌸){2}/g, "🌺🌺🌺");
if (sel.match(/(🌸){1}/g)) return sel.replaceAll(/(🌸){1}/g, "🌸🌸");
// 尝试匹配所有 prefix
let true_false = `(((✅|⛔)))`;
let math_arrow = `(\\s*\\$((\\\\[x]*cancel{\\s*(\\\\[Ll]ong(?:leftright|right|left)arrow)\\s*\\})|(\\\\[Ll]ong(?:leftright|right|left)arrow))\\$\\s*)`;
let callout = `(\\[!(?:.*)\][\\+\\-\\s]\\s*)`;
let quote_list = `(?<!<[^>]*)> ((\\d{1,}\\.|-|\\/\\/|\\%\\%|\\#) )?(\\[[x ]\\] )?`;
let list = `(?<!> )((\\d{1,}\\.|-|\\/\\/|\\%\\%|\\#) )(\\[[x ]\\] )?`;
let startswith_callout = new RegExp(`(` + `${callout}` + `${true_false}?` + `${math_arrow}?` + `)`,"g");
let startswith_quote_list = new RegExp(`(` + `${quote_list}` + `${true_false}?` + `${math_arrow}?` + `)`,"g");
let startswith_list = new RegExp(`(` + `${list}` + `${true_false}?` + `${math_arrow}?` + `)`,"g");
if (sel.match(startswith_callout)) return sel.replaceAll(startswith_callout, "$1🌸");
if (sel.match(startswith_quote_list)) return sel.replaceAll(startswith_quote_list, "$1🌸");
if (sel.match(startswith_list)) return sel.replaceAll(startswith_list, "$1🌸");
if (sel.match(true_false)) return sel.replaceAll(true_false, "$1🌸");
if (sel.match(math_arrow)) return sel.replaceAll(math_arrow, "$1🌸");
// 若无匹配,则在开头添加 emoji
return "🌸" + sel;
}, options: "vctA"},
// n = ✏️ ✍️ ✒️
{trigger: "n", replacement: (sel) => {
sel = sel.replaceAll(/\$(\d.*?)\$/g, "\${{ $1 }}\$$"); // sensitive_math
// 递增 emoji
if (sel.match(/(✒️){6}/g)) return sel.replaceAll(/(✒️){6}/g, "");
if (sel.match(/(✒️){5}/g)) return sel.replaceAll(/(✒️){5}/g, "✒️✒️✒️✒️✒️✒️");
if (sel.match(/(✍️){4}/g)) return sel.replaceAll(/(✍️){4}/g, "✒️✒️✒️✒️✒️");
if (sel.match(/(✍️){3}/g)) return sel.replaceAll(/(✍️){3}/g, "✍️✍️✍️✍️");
if (sel.match(/(✏️){2}/g)) return sel.replaceAll(/(✏️){2}/g, "✍️✍️✍️");
if (sel.match(/(✏️){1}/g)) return sel.replaceAll(/(✏️){1}/g, "✏️✏️");
// 尝试匹配所有 prefix
let true_false = `(((✅|⛔)))`;
let math_arrow = `(\\s*\\$((\\\\[x]*cancel{\\s*(\\\\[Ll]ong(?:leftright|right|left)arrow)\\s*\\})|(\\\\[Ll]ong(?:leftright|right|left)arrow))\\$\\s*)`;
let callout = `(\\[!(?:.*)\][\\+\\-\\s]\\s*)`;
let quote_list = `(?<!<[^>]*)> ((\\d{1,}\\.|-|\\/\\/|\\%\\%|\\#) )?(\\[[x ]\\] )?`;
let list = `(?<!> )((\\d{1,}\\.|-|\\/\\/|\\%\\%|\\#) )(\\[[x ]\\] )?`;
let startswith_callout = new RegExp(`(` + `${callout}` + `${true_false}?` + `${math_arrow}?` + `)`,"g");
let startswith_quote_list = new RegExp(`(` + `${quote_list}` + `${true_false}?` + `${math_arrow}?` + `)`,"g");
let startswith_list = new RegExp(`(` + `${list}` + `${true_false}?` + `${math_arrow}?` + `)`,"g");
if (sel.match(startswith_callout)) return sel.replaceAll(startswith_callout, "$1✏️");
if (sel.match(startswith_quote_list)) return sel.replaceAll(startswith_quote_list, "$1✏️");
if (sel.match(startswith_list)) return sel.replaceAll(startswith_list, "$1✏️");
if (sel.match(true_false)) return sel.replaceAll(true_false, "$1✏️");
if (sel.match(math_arrow)) return sel.replaceAll(math_arrow, "$1✏️");
// 若无匹配,则在开头添加 emoji
return "✏️" + sel;
}, options: "vctA"},
// q = ❔ ❓ 🌀
{trigger: "q", replacement: (sel) => {
sel = sel.replaceAll(/\$(\d.*?)\$/g, "\${{ $1 }}\$$"); // sensitive_math
// 🔴🔴首先处理 callout 折叠与否
// 👉👉最朴素的方式,仅仅排除长难句这一个 callout style
const regex_plus = /(\[!(?!长难句).+\])\+/g;
// 👉👉下面这个同理,但会更精确,同时也没这个必要
// const regex_plus = /(\[!(?!长难句\])(?!长难句\])[^\]]+\])\+/g;
// 👉👉不过如果只是想匹配特定的几个 callout 类型 可用如下正则
// const regex_plus = /(\[!(critical|important|significant|notable|minor|trivial|translation)\])\+/g;
const regex_minus = /(\[!(?!长难句).+\])\-/g;
const regex_none = /(\[!(?!长难句).+\])/g;
if (sel.match(regex_minus)) return sel.replaceAll(regex_minus, "$1+"); // ]- --> ]+
else if (sel.match(regex_plus)) return sel.replaceAll(regex_plus, "$1-"); // ]+ --> ]-
else if (sel.match(regex_none)) return sel.replaceAll(regex_none, "$1-"); // ] --> ]-
// 递增 emoji
if (sel.match(/(🌀){6}/g)) return sel.replaceAll(/(🌀){6}/g, "");
if (sel.match(/(🌀){5}/g)) return sel.replaceAll(/(🌀){5}/g, "🌀🌀🌀🌀🌀🌀");
if (sel.match(/(❓){4}/g)) return sel.replaceAll(/(❓){4}/g, "🌀🌀🌀🌀🌀");
if (sel.match(/(❓){3}/g)) return sel.replaceAll(/(❓){3}/g, "❓❓❓❓");
if (sel.match(/(❔){2}/g)) return sel.replaceAll(/(❔){2}/g, "❓❓❓");
if (sel.match(/(❔){1}/g)) return sel.replaceAll(/(❔){1}/g, "❔❔");
// 尝试匹配所有 prefix
let true_false = `(((✅|⛔)))`;
let math_arrow = `(\\s*\\$((\\\\[x]*cancel{\\s*(\\\\[Ll]ong(?:leftright|right|left)arrow)\\s*\\})|(\\\\[Ll]ong(?:leftright|right|left)arrow))\\$\\s*)`;
let callout = `(\\[!(?:.*)\][\\+\\-\\s]\\s*)`;
let quote_list = `(?<!<[^>]*)> ((\\d{1,}\\.|-|\\/\\/|\\%\\%|\\#) )?(\\[[x ]\\] )?`;
let list = `(?<!> )((\\d{1,}\\.|-|\\/\\/|\\%\\%|\\#) )(\\[[x ]\\] )?`;
let startswith_callout = new RegExp(`(` + `${callout}` + `${true_false}?` + `${math_arrow}?` + `)`,"g");
let startswith_quote_list = new RegExp(`(` + `${quote_list}` + `${true_false}?` + `${math_arrow}?` + `)`,"g");
let startswith_list = new RegExp(`(` + `${list}` + `${true_false}?` + `${math_arrow}?` + `)`,"g");
if (sel.match(startswith_callout)) return sel.replaceAll(startswith_callout, "$1❔");
if (sel.match(startswith_quote_list)) return sel.replaceAll(startswith_quote_list, "$1❔");
if (sel.match(startswith_list)) return sel.replaceAll(startswith_list, "$1❔");
if (sel.match(true_false)) return sel.replaceAll(true_false, "$1❔");
if (sel.match(math_arrow)) return sel.replaceAll(math_arrow, "$1❔");
// 若无匹配,则在开头添加 emoji
return "❔" + sel;
}, options: "vctA"},
// r = ✨ 🔥 💥
{trigger: "r", replacement: (sel) => {
sel = sel.replaceAll(/\$(\d.*?)\$/g, "\${{ $1 }}\$$"); // sensitive_math
// 递增 emoji
if (sel.match(/(💥){6}/g)) return sel.replaceAll(/(💥){6}/g, "");
if (sel.match(/(💥){5}/g)) return sel.replaceAll(/(💥){5}/g, "💥💥💥💥💥💥");
if (sel.match(/(🔥){4}/g)) return sel.replaceAll(/(🔥){4}/g, "💥💥💥💥💥");
if (sel.match(/(🔥){3}/g)) return sel.replaceAll(/(🔥){3}/g, "🔥🔥🔥🔥");
if (sel.match(/(✨){2}/g)) return sel.replaceAll(/(✨){2}/g, "🔥🔥🔥");
if (sel.match(/(✨){1}/g)) return sel.replaceAll(/(✨){1}/g, "✨✨");
// 尝试匹配所有 prefix
let true_false = `(((✅|⛔)))`;
let math_arrow = `(\\s*\\$((\\\\[x]*cancel{\\s*(\\\\[Ll]ong(?:leftright|right|left)arrow)\\s*\\})|(\\\\[Ll]ong(?:leftright|right|left)arrow))\\$\\s*)`;
let callout = `(\\[!(?:.*)\][\\+\\-\\s]\\s*)`;
let quote_list = `(?<!<[^>]*)> ((\\d{1,}\\.|-|\\/\\/|\\%\\%|\\#) )?(\\[[x ]\\] )?`;
let list = `(?<!> )((\\d{1,}\\.|-|\\/\\/|\\%\\%|\\#) )(\\[[x ]\\] )?`;
let startswith_callout = new RegExp(`(` + `${callout}` + `${true_false}?` + `${math_arrow}?` + `)`,"g");
let startswith_quote_list = new RegExp(`(` + `${quote_list}` + `${true_false}?` + `${math_arrow}?` + `)`,"g");
let startswith_list = new RegExp(`(` + `${list}` + `${true_false}?` + `${math_arrow}?` + `)`,"g");
if (sel.match(startswith_callout)) return sel.replaceAll(startswith_callout, "$1✨");
if (sel.match(startswith_quote_list)) return sel.replaceAll(startswith_quote_list, "$1✨");
if (sel.match(startswith_list)) return sel.replaceAll(startswith_list, "$1✨");
if (sel.match(true_false)) return sel.replaceAll(true_false, "$1✨");
if (sel.match(math_arrow)) return sel.replaceAll(math_arrow, "$1✨");
// 若无匹配,则在开头添加 emoji
return "✨" + sel;
}, options: "vctA"},
// s = "👉🌟"
{trigger: "s", replacement: (sel) => {
sel = sel.replaceAll(/\$(\d.*?)\$/g, "\${{ $1 }}\$$"); // sensitive_math
// 递增 emoji
if (sel.match(/(😎){8}/g)) return sel.replaceAll(/(😎){8}/g, "");
if (sel.match(/(😎){7}/g)) return sel.replaceAll(/(😎){7}/g, "😎😎😎😎😎😎😎😎");
if (sel.match(/(🌞){6}/g)) return sel.replaceAll(/(🌞){6}/g, "😎😎😎😎😎😎😎");
if (sel.match(/(🌞){5}/g)) return sel.replaceAll(/(🌞){5}/g, "🌞🌞🌞🌞🌞🌞");
if (sel.match(/(🌟){4}/g)) return sel.replaceAll(/(🌟){4}/g, "🌞🌞🌞🌞🌞");
if (sel.match(/(🌟){3}/g)) return sel.replaceAll(/(🌟){3}/g, "🌟🌟🌟🌟");
if (sel.match(/(👉){2}/g)) return sel.replaceAll(/(👉){2}/g, "🌟🌟🌟");
if (sel.match(/(👉){1}/g)) return sel.replaceAll(/(👉){1}/g, "👉👉");
// 尝试匹配所有 prefix
let true_false = `(((✅|⛔)))`;
let math_arrow = `(\\s*\\$((\\\\[x]*cancel{\\s*(\\\\[Ll]ong(?:leftright|right|left)arrow)\\s*\\})|(\\\\[Ll]ong(?:leftright|right|left)arrow))\\$\\s*)`;
let callout = `(\\[!(?:.*)\][\\+\\-\\s]\\s*)`;
let quote_list = `(?<!<[^>]*)> ((\\d{1,}\\.|-|\\/\\/|\\%\\%|\\#) )?(\\[[x ]\\] )?`;
let list = `(?<!> )((\\d{1,}\\.|-|\\/\\/|\\%\\%|\\#) )(\\[[x ]\\] )?`;
let startswith_callout = new RegExp(`(` + `${callout}` + `${true_false}?` + `${math_arrow}?` + `)`,"g");
let startswith_quote_list = new RegExp(`(` + `${quote_list}` + `${true_false}?` + `${math_arrow}?` + `)`,"g");
let startswith_list = new RegExp(`(` + `${list}` + `${true_false}?` + `${math_arrow}?` + `)`,"g");
if (sel.match(startswith_callout)) return sel.replaceAll(startswith_callout, "$1👉");
if (sel.match(startswith_quote_list)) return sel.replaceAll(startswith_quote_list, "$1👉");
if (sel.match(startswith_list)) return sel.replaceAll(startswith_list, "$1👉");
if (sel.match(true_false)) return sel.replaceAll(true_false, "$1👉");
if (sel.match(math_arrow)) return sel.replaceAll(math_arrow, "$1👉");
// 若无匹配,则在开头添加 emoji
return "👉" + sel;
}, options: "vctA"},
// x = (✅) (⛔)
{trigger: "x", replacement: (sel) => {
sel = sel.replaceAll(/\$(\d.*?)\$/g, "\${{ $1 }}\$$"); // sensitive_math
// 若已有 emoji
if (sel.match("(✅)")) return sel.replaceAll("(✅)", "(⛔)");
if (sel.match("(⛔)")) return sel.replaceAll("(⛔)", "");
if (sel.match("✅")) return sel.replaceAll("✅", "⛔");
if (sel.match("⛔")) return sel.replaceAll("⛔", "✅");
// 若没有 emoji,则尝试匹配所有 prefix
let callout = `(\\[!(?:.*)\][\\+\\-\\s]\\s*)`;
let quote_list = `(?<!<[^>]*)> ((\\d{1,}\\.|-|\\/\\/|\\%\\%|\\#) )?(\\[[x ]\\] )?`;
let list = `(?<!> )((\\d{1,}\\.|-|\\/\\/|\\%\\%|\\#) )(\\[[x ]\\] )?`;
let startswith_callout = new RegExp(`(` + `${callout}` + `)`,"g");
let startswith_quote_list = new RegExp(`(` + `${quote_list}` + `)`,"g");
let startswith_list = new RegExp(`(` + `${list}` + `)`,"g");
if (sel.match(startswith_callout)) return sel.replaceAll(startswith_callout, "$1(✅)");
if (sel.match(startswith_quote_list)) return sel.replaceAll(startswith_quote_list, "$1(✅)");
if (sel.match(startswith_list)) return sel.replaceAll(startswith_list, "$1(✅)");
// 若无匹配,则在开头添加 emoji
return "(✅)" + sel;
}, options: "vctA"},
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment