From fa5182a63f27f3fc125ad107e20ed9232848fc02 Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Wed, 29 May 2024 15:00:38 +0200 Subject: [PATCH] test with changed output regex --- lib/ExpensiMark.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index 84fecad6..73fc6e28 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -170,7 +170,7 @@ export default class ExpensiMark { { name: 'reportMentions', - regex: /(?$1', }, @@ -251,20 +251,27 @@ export default class ExpensiMark { // We want to enable 2 options of nested heading inside the blockquote: "># heading" and "> # heading". // To do this we need to parse body of the quote without first space let isStartingWithSpace = false; + let blockquoteDepth = 0; // Define blockquoteDepth here const handleMatch = (match, g2) => { + // Counting '>' characters to count number of blockquotes + blockquoteDepth = (match.match(/>/g) || []).length; if (shouldKeepRawInput) { isStartingWithSpace = !!g2; return ''; } return match; }; - const textToReplace = g1.replace(/^>( )?/gm, handleMatch); - const filterRules = ['heading1']; + // Replacing multiple '>' characters to capture multiple blockquotes + const textToReplace = g1.replace(/((>)+)( )?/gm, handleMatch); - // if we don't reach the max quote depth we allow the recursive call to process possible quote - if (this.currentQuoteDepth < this.maxQuoteDepth - 1 || isStartingWithSpace) { - filterRules.push('quote'); - this.currentQuoteDepth++; + let filterRules = ['heading1']; + + // If we don't reach the max quote depth we allow the recursive call to process possible quote + // Adding condition to process for multi blockquotes ">>>" + if (blockquoteDepth <= this.maxQuoteDepth - 1 || isStartingWithSpace) { + // Adding `quote` rule for each blockquote found + filterRules = [...filterRules, ...new Array(blockquoteDepth).fill('quote')]; + this.currentQuoteDepth += blockquoteDepth; } const replacedText = this.replace(textToReplace, { @@ -273,6 +280,7 @@ export default class ExpensiMark { shouldKeepRawInput, }); this.currentQuoteDepth = 0; + // Added isStartingWithSpace to `
` return `
${isStartingWithSpace ? ' ' : ''}${replacedText}
`; }, },