From 4bf4ceb771651d200ea3efd045dbeca1ca5bdfd8 Mon Sep 17 00:00:00 2001 From: Akibur Rahman <54747148+akib1689@users.noreply.github.com> Date: Sat, 30 Aug 2025 16:11:51 +0000 Subject: [PATCH] refactor: remove support for custom titles in GitHub-style alerts plugin and update related logic Main justification behind this is github currently don't support custom title inside the callouts. If needed we will address this later. --- .vscode/settings.json | 2 +- client/components/editor/editor-markdown.vue | 2 +- client/libs/markdown-it-github-alerts/index.js | 15 +++------------ .../markdown-github-alerts/definition.yml | 8 -------- .../rendering/markdown-github-alerts/renderer.js | 16 +++------------- 5 files changed, 8 insertions(+), 35 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index dc1a054c..75e3a447 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,7 +8,7 @@ "vue" ], "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": "explicit" }, "i18n-ally.localesPaths": [ "server/locales" diff --git a/client/components/editor/editor-markdown.vue b/client/components/editor/editor-markdown.vue index b3b227d8..b02b351e 100644 --- a/client/components/editor/editor-markdown.vue +++ b/client/components/editor/editor-markdown.vue @@ -267,7 +267,7 @@ const md = new MarkdownIt({ }) .use(mdDecorate) .use(underline) - .use(githubAlerts, { customTitle: false }) + .use(githubAlerts) .use(mdEmoji) .use(mdTaskLists, { label: false, labelAfter: false }) .use(mdExpandTabs) diff --git a/client/libs/markdown-it-github-alerts/index.js b/client/libs/markdown-it-github-alerts/index.js index f838c7c4..18009592 100644 --- a/client/libs/markdown-it-github-alerts/index.js +++ b/client/libs/markdown-it-github-alerts/index.js @@ -30,27 +30,18 @@ function githubAlertsPlugin(md, options = {}) { if (firstChild && firstChild.type === 'text') { const content = firstChild.content - const alertMatch = content.match(/^\[!(NOTE|INFO|TIP|WARNING|IMPORTANT|CAUTION)\](?:\s+(.+?))?$/i) + const alertMatch = content.match(/^\[!(NOTE|INFO|TIP|WARNING|IMPORTANT|CAUTION)\]/i) if (alertMatch) { const alertType = alertMatch[1].toLowerCase() - const customTitle = alertMatch[2] ? alertMatch[2].trim() : null const alertConfig = alertTypes[alertType] if (alertConfig) { // Add CSS class to blockquote tokens[idx].attrJoin('class', alertConfig.class) - // Handle custom title or remove alert tag - if (customTitle && options.customTitle !== false) { - firstChild.content = `${customTitle}` - } else if (customTitle && options.customTitle === false) { - // Custom titles disabled but title provided - remove the entire alert line - firstChild.content = '' - } else { - // No custom title - remove the alert tag - firstChild.content = '' - } + // Remove the alert tag + firstChild.content = firstChild.content.replace(/^\[!(NOTE|INFO|TIP|WARNING|IMPORTANT|CAUTION)\]\s*/i, '') // If we emptied the first text node, remove it if (firstChild.content === '') { diff --git a/server/modules/rendering/markdown-github-alerts/definition.yml b/server/modules/rendering/markdown-github-alerts/definition.yml index 987be42b..0c334d1b 100644 --- a/server/modules/rendering/markdown-github-alerts/definition.yml +++ b/server/modules/rendering/markdown-github-alerts/definition.yml @@ -5,11 +5,3 @@ author: requarks.io icon: mdi-alert-box-outline enabledDefault: true dependsOn: markdownCore -props: - customTitle: - type: Boolean - default: true - title: Support custom titles - hint: Allow custom titles like > [!NOTE] Custom Title - order: 1 - public: true diff --git a/server/modules/rendering/markdown-github-alerts/renderer.js b/server/modules/rendering/markdown-github-alerts/renderer.js index 6f8b8ad3..743c368c 100644 --- a/server/modules/rendering/markdown-github-alerts/renderer.js +++ b/server/modules/rendering/markdown-github-alerts/renderer.js @@ -37,28 +37,18 @@ function githubAlertsPlugin(md, options = {}) { if (firstChild && firstChild.type === 'text') { const content = firstChild.content - const alertMatch = content.match(/^\[!(NOTE|INFO|TIP|WARNING|IMPORTANT|CAUTION)\](?:\s+(.+?))?$/i) + const alertMatch = content.match(/^\[!(NOTE|INFO|TIP|WARNING|IMPORTANT|CAUTION)\]/i) if (alertMatch) { const alertType = alertMatch[1].toLowerCase() - const customTitle = alertMatch[2] ? alertMatch[2].trim() : null const alertConfig = alertTypes[alertType] if (alertConfig) { // Add CSS class to blockquote tokens[idx].attrJoin('class', alertConfig.class) - // Handle custom title or remove alert tag - if (customTitle && options.customTitle !== false) { - // Replace with bold custom title - firstChild.content = `**${customTitle}**` - } else if (customTitle && options.customTitle === false) { - // Custom titles disabled but title provided - remove the entire alert line - firstChild.content = '' - } else { - // No custom title - remove the alert tag - firstChild.content = '' - } + // Remove the alert tag + firstChild.content = firstChild.content.replace(/^\[!(NOTE|INFO|TIP|WARNING|IMPORTANT|CAUTION)\]\s*/i, '') // If we emptied the first text node, remove it if (firstChild.content === '') {