Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid committed Dec 4, 2024
1 parent d12e9ed commit 6611dab
Showing 1 changed file with 0 additions and 88 deletions.
88 changes: 0 additions & 88 deletions lib/ExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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], '<pre>');
}

// Since the last space will be trimmed and would incorrectly disable a condition we check it manually
const isLastBlockquote = textSplitted[i] === '&gt;' && i === textSplitted.length - 1;

// We only want to modify lines starting with "&gt; " that is not codefence
if ((Str.startsWith(textSplitted[i], '&gt; ') || isLastBlockquote) && !insideCodefence) {
if (textSplitted[i] === '&gt;') {
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], '</pre>');
}
}
}

// 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 '&gt;' and trim the spaces between nested quotes
const formatRow = (row: string) => {
let quoteContent = row[4] === ' ' ? row.substr(5) : row.substr(4);
if (row === '&gt; ') quoteContent = row.substr(4);

if (quoteContent.trimStart().startsWith('&gt;')) {
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 &gt;( ) from text and recursively calls replace function to process nested quotes and build blockquote HTML result.
Expand Down

0 comments on commit 6611dab

Please sign in to comment.