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.
pull/7766/head
Akibur Rahman 3 months ago
parent ed17a4e4f4
commit 4bf4ceb771

@ -8,7 +8,7 @@
"vue"
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"i18n-ally.localesPaths": [
"server/locales"

@ -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)

@ -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 = `<b>${customTitle}</b>`
} 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 === '') {

@ -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

@ -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 === '') {

Loading…
Cancel
Save