Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
dragnoir committed May 20, 2024
1 parent 0a1e26e commit 0023d73
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,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 @@ -421,29 +421,30 @@ 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?(<h1># )/g, '$1')
.replace(/(<h1>|<\/h1>)+/g, '\n')
.trim()
.split('\n');

resultString = _.map(resultString, (m) => {
function processString(m) {
// Recursive function to replace nested <blockquote> with ">"
function replaceBlockquotes(text) {
while (/<blockquote>/i.test(text)) {
// Count how many <blockquote> tags
let depth = (text.match(/<blockquote>/gi) || []).length;
// Replace all blockquote tags and add ">" per depth level
text = text.replace(/<blockquote>/gi, '');
text = text.replace(/<\/blockquote>/gi, '');
return `${'>'.repeat(depth)} ${text}`;
}
return text;
}
let modifiedText = text;
let depth;
do {
depth = (modifiedText.match(/<blockquote>/gi) || []).length;
modifiedText = modifiedText.replace(/<blockquote>/gi, '');
modifiedText = modifiedText.replace(/<\/blockquote>/gi, '');
} while (/<blockquote>/i.test(modifiedText));
return `${'>'.repeat(depth)} ${modifiedText}`;
}
return replaceBlockquotes(m);
}).join('\n');
}

resultString = _.map(resultString, processString).join('\n');

// We want to keep <blockquote> tag here and let method replaceBlockElementWithNewLine to handle the line break later
return `<blockquote>${resultString}</blockquote>`;
Expand Down

0 comments on commit 0023d73

Please sign in to comment.