diff --git a/__tests__/ExpensiMark-Markdown-test.js b/__tests__/ExpensiMark-Markdown-test.js index 09c68462..8e0b834f 100644 --- a/__tests__/ExpensiMark-Markdown-test.js +++ b/__tests__/ExpensiMark-Markdown-test.js @@ -679,3 +679,14 @@ test('Test blockquote linebreak handling with text, block and inline elements', const testStringSurroundedByBlockElementHeading = '

h1 a

quote a

quote b

h1 b


h1 c

quote c

h1 c

'; expect(parser.htmlToMarkdown(testStringSurroundedByBlockElementHeading)).toBe('# h1 a\n> quote a\n\n> quote b\n# h1 b\n\n# h1 c\n> quote c\n# h1 c'); }); + +test('Test codeFence copy from selection does not add extra new line', () => { + let testString = '
code
text
'; + expect(parser.htmlToMarkdown(testString)).toBe('```\ncode\n```\ntext'); + + testString = '
code
text'; + expect(parser.htmlToMarkdown(testString)).toBe('```\ncode\n```\ntext'); + + testString = '

test heading

Code snippet\n

link

'; + expect(parser.htmlToMarkdown(testString)).toBe('test heading\n```\nCode snippet\n```\n> [link](https://www.example.com)') +}); diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index d5fd18b4..644b108b 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -256,6 +256,11 @@ export default class ExpensiMark { ), replacement: '', }, + { + name: 'nested', + regex: /<(pre)(?:"[^"]*"|'[^']*'|[^'">])*><(div|code)(?:"[^"]*"|'[^']*'|[^'">])*>([\s\S]*?)<\/\2><\/pre>/gi, + replacement: '
$3
' + }, { name: 'newline',