"use strict"; const {strict: assert} = require("assert"); const {zrequire} = require("./lib/namespace"); const {run_test} = require("./lib/test"); const copy_and_paste = zrequire("copy_and_paste"); run_test("maybe_transform_html", () => { // Copied HTML from VS Code let paste_html = `
if ($preview_src.endsWith("&size=full"))
`; let paste_text = `if ($preview_src.endsWith("&size=full"))`; const escaped_paste_text = "if ($preview_src.endsWith("&size=full"))"; const expected_output = "
" + escaped_paste_text + "
"; assert.equal(copy_and_paste.maybe_transform_html(paste_html, paste_text), expected_output); // Untransformed HTML paste_html = "
Hello
World!
"; paste_text = "Hello\nWorld!"; assert.equal(copy_and_paste.maybe_transform_html(paste_html, paste_text), paste_html); }); run_test("paste_handler_converter", () => { /* Pasting from another Zulip message */ // Bold text let input = ' love the Zulip Organization.'; assert.equal( copy_and_paste.paste_handler_converter(input), " love the **Zulip** **Organization**.", ); // Inline code input = 'The JSDOM constructor'; assert.equal(copy_and_paste.paste_handler_converter(input), "The `JSDOM` constructor"); // A python code block input = `

zulip code block in python

print("hello")\nprint("world")
`; assert.equal( copy_and_paste.paste_handler_converter(input), 'zulip code block in python\n\n```Python\nprint("hello")\nprint("world")\n```', ); // Single line in a code block input = '
single line
'; assert.equal(copy_and_paste.paste_handler_converter(input), "`single line`"); // Raw links without custom text input = 'https://zulip.readthedocs.io/en/latest/subsystems/logging.html'; assert.equal( copy_and_paste.paste_handler_converter(input), "https://zulip.readthedocs.io/en/latest/subsystems/logging.html", ); // Links with custom text input = 'Contributing guide'; assert.equal( copy_and_paste.paste_handler_converter(input), "[Contributing guide](https://zulip.readthedocs.io/en/latest/contributing/contributing.html)", ); // Only numbered list (list style retained) input = '
  1. text
'; assert.equal(copy_and_paste.paste_handler_converter(input), "1. text"); // Heading input = '

Zulip overview

normal text

'; assert.equal(copy_and_paste.paste_handler_converter(input), "# Zulip overview\n\nnormal text"); // Only heading (strip heading style) input = '

Zulip overview

'; assert.equal(copy_and_paste.paste_handler_converter(input), "Zulip overview"); // Italic text input = 'normal text This text is italic'; assert.equal( copy_and_paste.paste_handler_converter(input), "normal text *This text is italic*", ); // Strikethrough text input = 'normal text This text is struck through'; assert.equal( copy_and_paste.paste_handler_converter(input), "normal text ~~This text is struck through~~", ); // Emojis input = 'emojis: :smile: :family_man_woman_girl:'; assert.equal( copy_and_paste.paste_handler_converter(input), "emojis: :smile: :family_man_woman_girl:", ); // Nested lists input = ''; assert.equal( copy_and_paste.paste_handler_converter(input), "* bulleted\n* nested\n * nested level 1\n * nested level 1 continue\n * nested level 2\n * nested level 2 continue", ); // 2 paragraphs with line break/s in between input = '

paragraph 1


paragraph 2

'; assert.equal(copy_and_paste.paste_handler_converter(input), "paragraph 1\n\nparagraph 2"); // Pasting from external sources // Pasting list from GitHub input = '

Test list:

  • Item 1
  • Item 2
'; assert.equal(copy_and_paste.paste_handler_converter(input), "Test list:\n* Item 1\n* Item 2"); // Pasting list from VS Code input = '
Test list:
'; assert.equal(copy_and_paste.paste_handler_converter(input), "Test list:\n* Item 1\n* Item 2"); // Pasting from Google Sheets (remove 123'; assert.equal(copy_and_paste.paste_handler_converter(input), "123"); });