diff --git a/src/core/render/compiler/blockquote.js b/src/core/render/compiler/blockquote.js index 5f00951de..8fc2607e1 100644 --- a/src/core/render/compiler/blockquote.js +++ b/src/core/render/compiler/blockquote.js @@ -1,36 +1,45 @@ export const blockquoteCompiler = ({ renderer }) => (renderer.blockquote = function ({ tokens }) { - const calloutData = - tokens[0].type === 'paragraph' && - // 0: Match "[!TIP] My Title" - // 1: Mark "[!TIP]" - // 2: Type "TIP" - tokens[0].raw.match(/^(\[!(\w+)\])/); - let openTag = '
'; let closeTag = ''; - if (calloutData) { - const calloutMark = calloutData[1]; // "[!TIP]" - const calloutType = calloutData[2].toLowerCase(); // "tip" - const token = tokens[0].tokens[0]; + // Find the first paragraph token in the blockquote + const firstParagraphIndex = tokens.findIndex(t => t.type === 'paragraph'); + const firstParagraph = tokens[firstParagraphIndex]; - // Remove callout mark from tokens - ['raw', 'text'].forEach(key => { - token[key] = token[key].replace(calloutMark, '').trimStart(); - }); + if (firstParagraph) { + // Check if the paragraph starts with a callout like [!TIP] or [!NOTE] + const calloutData = firstParagraph.raw.match(/^(\[!(\w+)\])/); - // Remove empty paragraph - if (tokens.length > 1 && !token.raw.trim()) { - tokens = tokens.slice(1); - } + if (calloutData) { + const calloutMark = calloutData[1]; // "[!TIP]" + const calloutType = calloutData[2].toLowerCase(); // "tip" + + // Remove the callout mark from the paragraph raw text + firstParagraph.raw = firstParagraph.raw + .replace(calloutMark, '') + .trimStart(); + if (firstParagraph.tokens && firstParagraph.tokens.length > 0) { + firstParagraph.tokens.forEach(t => { + if (t.raw) { + t.raw = t.raw.replace(calloutMark, ''); + } + if (t.text) { + t.text = t.text.replace(calloutMark, ''); + } + }); + } - openTag = `
Text
+Text
Text
+Text
Text
+Text
Text
+Text
Text
+Text