diff --git a/frontend_tests/node_tests/copy_and_paste.js b/frontend_tests/node_tests/copy_and_paste.js index d5b5952644..38a9d332a9 100644 --- a/frontend_tests/node_tests/copy_and_paste.js +++ b/frontend_tests/node_tests/copy_and_paste.js @@ -33,4 +33,12 @@ var copy_and_paste = zrequire('copy_and_paste'); // and the ' \n' is a bit strange as well assert.equal(copy_and_paste.paste_handler_converter(input), ' \n1\\. text'); + + input = '

Zulip overview

'; + assert.equal(copy_and_paste.paste_handler_converter(input), + 'Zulip overview'); + + input = 'This text is italic'; + assert.equal(copy_and_paste.paste_handler_converter(input), + '*This text is italic*'); }()); diff --git a/static/js/copy_and_paste.js b/static/js/copy_and_paste.js index acbf8e6716..b35961425b 100644 --- a/static/js/copy_and_paste.js +++ b/static/js/copy_and_paste.js @@ -141,7 +141,24 @@ function copy_handler() { } exports.paste_handler_converter = function (paste_html) { - var markdown_html = toMarkdown(paste_html); + var converters = { + converters: [ + { + filter: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'], + replacement: function (content) { + return content; + }, + }, + + { + filter: ['em', 'i'], + replacement: function (content) { + return '*' + content + '*'; + }, + }, + ], + }; + var markdown_html = toMarkdown(paste_html, converters); // Now that we've done the main conversion, we want to remove // any HTML tags that weren't converted to markdown-style