diff --git a/__tests__/ExpensiMark-Markdown-test.js b/__tests__/ExpensiMark-Markdown-test.js index a8bf1769..093f5ca5 100644 --- a/__tests__/ExpensiMark-Markdown-test.js +++ b/__tests__/ExpensiMark-Markdown-test.js @@ -497,6 +497,18 @@ test('map div with quotes', () => { expect(parser.htmlToMarkdown(testString)).toBe(resultString); }); +test('double quotes in same line', () => { + const testString = '
line 1
'; + const resultString = '>> line 1'; + expect(parser.htmlToMarkdown(testString)).toBe(resultString); +}); + +test('triple quotes in same line', () => { + const testString = '
line 1
'; + const resultString = '>>> line 1'; + expect(parser.htmlToMarkdown(testString)).toBe(resultString); +}); + test('map table to newline', () => { const testString = 'line 1line 2'; const resultString = 'line 1\nline 2'; diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index 49acff22..6b77fcee 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -425,8 +425,32 @@ export default class ExpensiMark { .trim() .split('\n'); - const prependGreaterSign = (m) => `> ${m}`; - resultString = _.map(resultString, prependGreaterSign).join('\n'); + // Wrap each string in the array with
and
+ // Define a named function to wrap each line with blockquote + function wrapWithBlockquote(line) { + return `
${line}
`; + } + + // Use _.map with the named function + resultString = _.map(resultString, wrapWithBlockquote); + + function processString(m) { + // Recursive function to replace nested
with ">" + function replaceBlockquotes(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); + } + + resultString = _.map(resultString, processString).join('\n'); + // We want to keep
tag here and let method replaceBlockElementWithNewLine to handle the line break later return `
${resultString}
`; },