From 0023d733a3e5bed7fa6c18aca7ef9af9c2367ac8 Mon Sep 17 00:00:00 2001 From: dragnoir Date: Mon, 20 May 2024 17:20:15 +0100 Subject: [PATCH] fix lint --- lib/ExpensiMark.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index 45d7a9df..2d0e0a28 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -177,7 +177,7 @@ export default class ExpensiMark { { name: 'reportMentions', - regex: /(?$1', }, @@ -421,7 +421,7 @@ export default class ExpensiMark { { name: 'quote', regex: /<(blockquote|q)(?:"[^"]*"|'[^']*'|[^'">])*>([\s\S]*?)<\/\1>(?![^<]*(<\/pre>|<\/code>))/gi, - replacement: (match, g1, g2) => { + replacement(match) { // We remove the line break before heading inside quote to avoid adding extra line let resultString = match .replace(/\n?(

# )/g, '$1') @@ -429,21 +429,22 @@ export default class ExpensiMark { .trim() .split('\n'); - resultString = _.map(resultString, (m) => { + function processString(m) { // Recursive function to replace nested
with ">" function replaceBlockquotes(text) { - while (/
/i.test(text)) { - // Count how many
tags - let depth = (text.match(/
/gi) || []).length; - // Replace all blockquote tags and add ">" per depth level - text = text.replace(/
/gi, ''); - text = text.replace(/<\/blockquote>/gi, ''); - return `${'>'.repeat(depth)} ${text}`; - } - return text; - } + let modifiedText = text; + let depth; + do { + depth = (modifiedText.match(/
/gi) || []).length; + modifiedText = modifiedText.replace(/
/gi, ''); + modifiedText = modifiedText.replace(/<\/blockquote>/gi, ''); + } while (/
/i.test(modifiedText)); + return `${'>'.repeat(depth)} ${modifiedText}`; + } return replaceBlockquotes(m); - }).join('\n'); + } + + resultString = _.map(resultString, processString).join('\n'); // We want to keep
tag here and let method replaceBlockElementWithNewLine to handle the line break later return `
${resultString}
`;