fix: Remove legacy title format

This commit is contained in:
Leni Aniva 2024-09-17 15:14:50 -05:00
parent 1b91453f8f
commit 2caddbc8fd
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
1 changed files with 3 additions and 4 deletions

View File

@ -3,7 +3,6 @@ Remark and rehype functions
*/ */
import { visit } from 'unist-util-visit'; import { visit } from 'unist-util-visit';
const alertRegex = /^:>(NOTE|TIP|IMPORTANT|WARNING|CAUTION)/i; const alertRegex = /^:>(NOTE|TIP|IMPORTANT|WARNING|CAUTION)/i;
const alertLegacyRegex = /^:>(NOTE|TIP|IMPORTANT|WARNING|CAUTION)(\/.*)?/i;
/** /**
* Alerts are a Markdown extension based on the blockquote syntax that you can use to emphasize critical information. * Alerts are a Markdown extension based on the blockquote syntax that you can use to emphasize critical information.
* On GitHub, they are displayed with distinctive colors and icons to indicate the significance of the content. * On GitHub, they are displayed with distinctive colors and icons to indicate the significance of the content.
@ -11,7 +10,7 @@ const alertLegacyRegex = /^:>(NOTE|TIP|IMPORTANT|WARNING|CAUTION)(\/.*)?/i;
* *
* This is adapted from `remark-github-blockquote-alert` * This is adapted from `remark-github-blockquote-alert`
*/ */
function remarkAlert/*: Plugin<[Option?], Root> = */({ legacyTitle = false } = {}) /*=>*/ { function remarkAlert/*: Plugin<[Option?], Root> = */() /*=>*/ {
return (tree) => { return (tree) => {
visit(tree, "blockquote", (node, index, parent) => { visit(tree, "blockquote", (node, index, parent) => {
let alertType = ''; let alertType = '';
@ -21,12 +20,12 @@ function remarkAlert/*: Plugin<[Option?], Root> = */({ legacyTitle = false } = {
if (isNext && item.type === "paragraph") { if (isNext && item.type === "paragraph") {
const firstNode = item.children[0]; const firstNode = item.children[0];
const text = firstNode.type === 'text' ? firstNode.value : ''; const text = firstNode.type === 'text' ? firstNode.value : '';
const reg = legacyTitle ? alertLegacyRegex : alertRegex; const reg = alertRegex;
const match = text.match(reg); const match = text.match(reg);
if (match) { if (match) {
isNext = false; isNext = false;
alertType = match[1].toLocaleLowerCase(); alertType = match[1].toLocaleLowerCase();
title = legacyTitle ? match[2] || alertType.toLocaleUpperCase() : alertType.toLocaleUpperCase(); title = alertType.toLocaleUpperCase();
if (text.includes('\n')) { if (text.includes('\n')) {
item.children[0] = { item.children[0] = {
type: 'text', type: 'text',