Skip to content

Commit

Permalink
Merge pull request #564 from akamefi202/selection-copy-markdown
Browse files Browse the repository at this point in the history
Delete nested tag inside codeFence
  • Loading branch information
puneetlath authored Aug 14, 2023
2 parents 1076899 + 23a1a44 commit 4cc5f72
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions __tests__/ExpensiMark-Markdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,3 +679,14 @@ test('Test blockquote linebreak handling with text, block and inline elements',
const testStringSurroundedByBlockElementHeading = '<h1>h1 a</h1><blockquote>quote a</blockquote><br /><blockquote>quote b</blockquote><h1>h1 b</h1><br /><h1>h1 c</h1><blockquote>quote c</blockquote><h1>h1 c</h1>';
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 = '<div><div><comment><pre><div><span>code</span><br></div></pre>text</comment></div></div>';
expect(parser.htmlToMarkdown(testString)).toBe('```\ncode\n```\ntext');

testString = '<pre>code<br></pre>text';
expect(parser.htmlToMarkdown(testString)).toBe('```\ncode\n```\ntext');

testString = '<h3>test heading</h3><div><pre class=\"notranslate\"><code class=\"notranslate\">Code snippet\n</code></pre></div><blockquote><p><a href=\"https://www.example.com\">link</a></p></blockquote>';
expect(parser.htmlToMarkdown(testString)).toBe('test heading\n```\nCode snippet\n```\n> [link](https://www.example.com)')
});
5 changes: 5 additions & 0 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ export default class ExpensiMark {
),
replacement: '',
},
{
name: 'nested',
regex: /<(pre)(?:"[^"]*"|'[^']*'|[^'">])*><(div|code)(?:"[^"]*"|'[^']*'|[^'">])*>([\s\S]*?)<\/\2><\/pre>/gi,
replacement: '<pre>$3</pre>'
},
{
name: 'newline',

Expand Down

0 comments on commit 4cc5f72

Please sign in to comment.