diff --git a/lib/ExpensiMark.ts b/lib/ExpensiMark.ts index 8c5343dd..e81d39a0 100644 --- a/lib/ExpensiMark.ts +++ b/lib/ExpensiMark.ts @@ -1214,94 +1214,6 @@ export default class ExpensiMark { return replacedText; } - /** - * Modify text for Quotes replacing chevrons with html elements - */ - modifyTextForQuote(regex: RegExp, textToCheck: string, replacement: ReplacementFn): string { - let replacedText = ''; - let textToFormat = ''; - const match = textToCheck.match(regex); - - // If there's matches we need to modify the quotes - if (match !== null) { - let insideCodefence = false; - - // Split the textToCheck in lines - const textSplitted = textToCheck.split('\n'); - - for (let i = 0; i < textSplitted.length; i++) { - if (!insideCodefence) { - // We need to know when there is a start of codefence so we dont quote - insideCodefence = Str.contains(textSplitted[i], '
'); - } - - // Since the last space will be trimmed and would incorrectly disable a condition we check it manually - const isLastBlockquote = textSplitted[i] === '>' && i === textSplitted.length - 1; - - // We only want to modify lines starting with "> " that is not codefence - if ((Str.startsWith(textSplitted[i], '> ') || isLastBlockquote) && !insideCodefence) { - if (textSplitted[i] === '>') { - textToFormat += `${textSplitted[i]} \n`; - insideCodefence = true; - } else { - textToFormat += `${textSplitted[i]}\n`; - } - } else { - // Make sure we will only modify if we have Text needed to be formatted for quote - if (textToFormat !== '') { - replacedText += this.formatTextForQuote(regex, textToFormat, replacement); - textToFormat = ''; - } - - // We dont want a \n after the textSplitted if it is the last row - if (i === textSplitted.length - 1) { - replacedText += `${textSplitted[i]}`; - } else { - replacedText += `${textSplitted[i]}\n`; - } - - // We need to know when we are not inside codefence anymore - if (insideCodefence) { - insideCodefence = !Str.contains(textSplitted[i], ''); - } - } - } - - // When loop ends we need the last quote to be formatted if we have quotes at last rows - if (textToFormat !== '') { - replacedText += this.formatTextForQuote(regex, textToFormat, replacement); - } - } else { - // If we doesn't have matches make sure the function will return the same textToCheck - replacedText = textToCheck; - } - return replacedText; - } - - /** - * Format the content of blockquote if the text matches the regex or else just return the original text - */ - formatTextForQuote(regex: RegExp, textToCheck: string, replacement: ReplacementFn): string { - if (textToCheck.match(regex)) { - // Remove '>' and trim the spaces between nested quotes - const formatRow = (row: string) => { - let quoteContent = row[4] === ' ' ? row.substr(5) : row.substr(4); - if (row === '> ') quoteContent = row.substr(4); - - if (quoteContent.trimStart().startsWith('>')) { - return quoteContent.trimStart(); - } - return quoteContent; - }; - let textToFormat = textToCheck.split('\n').map(formatRow).join('\n'); - - // Remove leading and trailing line breaks - textToFormat = textToFormat.replace(/^\n+|\n+$/g, ''); - return replacement(EXTRAS_DEFAULT, textToFormat); - } - return textToCheck; - } - /** * Main text to html 'quote' parsing logic. * Removes >( ) from text and recursively calls replace function to process nested quotes and build blockquote HTML result.