From 81af8a359013e8fdff67a3c158a2cdf6fbc0209c Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Wed, 28 Jul 2021 23:48:41 +0530 Subject: [PATCH 1/3] quote support --- lib/ExpensiMark.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index e5e683b0..6610a441 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -214,6 +214,14 @@ export default class ExpensiMark { regex: /<(del)(?:"[^"]*"|'[^']*'|[^'">])*>(.*?)<\/\1>(?![^<]*(<\/pre>|<\/code>))/gi, replacement: '~$2~' }, + { + name: 'quote', + regex: /\n?<(blockquote|q)(?:"[^"]*"|'[^']*'|[^'">])*>([\s\S]*?)<\/\1>(?![^<]*(<\/pre>|<\/code>))/gi, + replacement: (match, g1, g2) => { + const resultString = g2.trim().split('\n').map(m => `> ${m}`).join('\n'); + return `\n${resultString}\n`; + } + }, ]; } From 4a6d45be79412af6c0d26622f9ec942f68f1d351 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Thu, 29 Jul 2021 00:23:01 +0530 Subject: [PATCH 2/3] added tests and fix quote conversion --- __tests__/ExpensiMark-Markdown-test.js | 10 ++++++++++ lib/ExpensiMark.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/__tests__/ExpensiMark-Markdown-test.js b/__tests__/ExpensiMark-Markdown-test.js index cfd9e288..850b0b30 100644 --- a/__tests__/ExpensiMark-Markdown-test.js +++ b/__tests__/ExpensiMark-Markdown-test.js @@ -114,3 +114,13 @@ test('Test HTML string with encoded entities', () => { expect(parser.htmlToMarkdown(testString)).toBe(resultString); }); + + +test('Test HTML string with blockquote', () => { + const testString = '

This GH seems to assume that there will be something in the paste\nbuffer when you copy block-quoted text out of slack. But when I dump\nsome lorem ipsum into a blockquote in Slack, copy it to the\nbuffer, then dump it into terminal, there\'s nothing. And if I dump it

' + + '
line1\nline2\n\nsome lorem ipsum into a blockquote in Slack, copy it to the\n\n\nbuffer
'; + const resultString = '\n> This GH seems to assume that there will be something in the paste\n> buffer when you copy block-quoted text out of slack. But when I dump\n> some _lorem ipsum_ into a blockquote in Slack, copy it to the\n> buffer, then dump it into terminal, there\'s nothing. And if I dump it\n' + + '\n> line1\n> line2\n> \n> some _lorem ipsum_ into a blockquote in Slack, copy it to the\n> \n> \n> buffer\n'; + + expect(parser.htmlToMarkdown(testString)).toBe(resultString); +}); diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index 6610a441..760e8f70 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -218,7 +218,7 @@ export default class ExpensiMark { name: 'quote', regex: /\n?<(blockquote|q)(?:"[^"]*"|'[^']*'|[^'">])*>([\s\S]*?)<\/\1>(?![^<]*(<\/pre>|<\/code>))/gi, replacement: (match, g1, g2) => { - const resultString = g2.trim().split('\n').map(m => `> ${m}`).join('\n'); + const resultString = g2.trim().split('\n').map(m => `> ${m || ''}`).join('\n'); return `\n${resultString}\n`; } }, From 2a718f0772ac76eb52241bbc5ed36dab75521a57 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Fri, 30 Jul 2021 00:42:21 +0530 Subject: [PATCH 3/3] quote improvement --- __tests__/ExpensiMark-Markdown-test.js | 7 +++++-- lib/ExpensiMark.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/__tests__/ExpensiMark-Markdown-test.js b/__tests__/ExpensiMark-Markdown-test.js index 850b0b30..fca8c4c5 100644 --- a/__tests__/ExpensiMark-Markdown-test.js +++ b/__tests__/ExpensiMark-Markdown-test.js @@ -118,9 +118,12 @@ test('Test HTML string with encoded entities', () => { test('Test HTML string with blockquote', () => { const testString = '

This GH seems to assume that there will be something in the paste\nbuffer when you copy block-quoted text out of slack. But when I dump\nsome lorem ipsum into a blockquote in Slack, copy it to the\nbuffer, then dump it into terminal, there\'s nothing. And if I dump it

' - + '
line1\nline2\n\nsome lorem ipsum into a blockquote in Slack, copy it to the\n\n\nbuffer
'; + + '
line1\nline2\n\nsome lorem ipsum into a blockquote in Slack, copy it to the\n\n\nbuffer
' + + '
line1 lorem ipsum
'; + const resultString = '\n> This GH seems to assume that there will be something in the paste\n> buffer when you copy block-quoted text out of slack. But when I dump\n> some _lorem ipsum_ into a blockquote in Slack, copy it to the\n> buffer, then dump it into terminal, there\'s nothing. And if I dump it\n' - + '\n> line1\n> line2\n> \n> some _lorem ipsum_ into a blockquote in Slack, copy it to the\n> \n> \n> buffer\n'; + + '\n> line1\n> line2\n> \n> some _lorem ipsum_ into a blockquote in Slack, copy it to the\n> \n> \n> buffer\n' + + '\n> line1 _lorem ipsum_\n'; expect(parser.htmlToMarkdown(testString)).toBe(resultString); }); diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index 760e8f70..6610a441 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -218,7 +218,7 @@ export default class ExpensiMark { name: 'quote', regex: /\n?<(blockquote|q)(?:"[^"]*"|'[^']*'|[^'">])*>([\s\S]*?)<\/\1>(?![^<]*(<\/pre>|<\/code>))/gi, replacement: (match, g1, g2) => { - const resultString = g2.trim().split('\n').map(m => `> ${m || ''}`).join('\n'); + const resultString = g2.trim().split('\n').map(m => `> ${m}`).join('\n'); return `\n${resultString}\n`; } },