Skip to content

Commit

Permalink
test with changed output regex
Browse files Browse the repository at this point in the history
  • Loading branch information
BrtqKr committed May 29, 2024
1 parent 0b36011 commit fa5182a
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export default class ExpensiMark {
{
name: 'reportMentions',

regex: /(?<![^ \n*~_])(#[\p{Ll}0-9-]{1,80})/gmiu,
regex: /(?<![^ \n*~_])(#[\p{Ll}0-9-]{1,80})/gimu,
replacement: '<mention-report>$1</mention-report>',
},

Expand Down Expand Up @@ -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(/&gt;/g) || []).length;
if (shouldKeepRawInput) {
isStartingWithSpace = !!g2;
return '';
}
return match;
};
const textToReplace = g1.replace(/^&gt;( )?/gm, handleMatch);
const filterRules = ['heading1'];
// Replacing multiple '>' characters to capture multiple blockquotes
const textToReplace = g1.replace(/((&gt;)+)( )?/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, {
Expand All @@ -273,6 +280,7 @@ export default class ExpensiMark {
shouldKeepRawInput,
});
this.currentQuoteDepth = 0;
// Added isStartingWithSpace to `<blockquote>`
return `<blockquote>${isStartingWithSpace ? ' ' : ''}${replacedText}</blockquote>`;
},
},
Expand Down

0 comments on commit fa5182a

Please sign in to comment.