This commit is contained in:
parent
6439559017
commit
7aa1fd2372
31 changed files with 1939 additions and 12 deletions
|
|
@ -6,6 +6,14 @@ const CALLOUT_LABELS = new Map([
|
|||
["warning", "Warning"],
|
||||
]);
|
||||
|
||||
const CALLOUT_MARKERS = new Map([
|
||||
["📝", "Note"],
|
||||
["💡", "Tip"],
|
||||
["⚡", "Tip"],
|
||||
["⚠️", "Warning"],
|
||||
["⚠", "Warning"],
|
||||
]);
|
||||
|
||||
function textFromInline(node) {
|
||||
if (!node) return "";
|
||||
if (typeof node.value === "string") return node.value;
|
||||
|
|
@ -30,6 +38,13 @@ function paragraphCalloutLabel(paragraph) {
|
|||
if (match) {
|
||||
return CALLOUT_LABELS.get(normalizeLabel(match[1]));
|
||||
}
|
||||
|
||||
const trimmed = first.value.trimStart();
|
||||
for (const [marker, label] of CALLOUT_MARKERS) {
|
||||
if (trimmed.startsWith(marker)) {
|
||||
return label;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (first?.type !== "strong") return null;
|
||||
|
|
@ -46,6 +61,10 @@ function removeLeadingLabel(paragraph, label) {
|
|||
const first = paragraph.children?.[0];
|
||||
if (first?.type === "text") {
|
||||
first.value = first.value.replace(/^\s*\[!(aside|caution|note|tip|warning)\]\s*/i, "");
|
||||
for (const marker of CALLOUT_MARKERS.keys()) {
|
||||
const escapedMarker = marker.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
first.value = first.value.replace(new RegExp(`^\\s*${escapedMarker}\\s*`, "u"), "");
|
||||
}
|
||||
if (!first.value) paragraph.children.shift();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue