Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

compose: Always retain link formatting when pasting just a link.

N-Shar-maeca6738b004f
diff --git a/web/src/copy_and_paste.js b/web/src/copy_and_paste.js
index 5ae49fb9797..8de867d9cf0 100644
--- a/web/src/copy_and_paste.js
+++ b/web/src/copy_and_paste.js
@@ -319,10 +319,10 @@ export function paste_handler_converter(paste_html) {
copied_html_fragment.childNodes.length === 1 &&
copied_html_fragment.firstElementChild &&
copied_html_fragment.firstElementChild.innerHTML;
- const outer_elements_to_retain = ["PRE", "OL"];
+ const outer_elements_to_retain = ["PRE", "OL", "A"];
// If the entire selection copied is within a single HTML element (like an
- // `h1`), we don't want to retain its styling, except when it helps identify
- // the intended structure of the copied content (like `pre` and `ol`).
+ // `h1`), we don't want to retain its styling, except when it is needed to
+ // identify the intended structure of the copied content.
if (
copied_within_single_element &&
!outer_elements_to_retain.includes(copied_html_fragment.firstElementChild.nodeName)
diff --git a/web/tests/copy_and_paste.test.js b/web/tests/copy_and_paste.test.js
index b4d211addc4..975c7631cd8 100644
--- a/web/tests/copy_and_paste.test.js
+++ b/web/tests/copy_and_paste.test.js
@@ -45,10 +45,10 @@ run_test("paste_handler_converter", () => {
// Links with custom text
input =
- '<meta http-equiv="content-type" content="text/html; charset=utf-8">normal text <a class="reference external" href="https://zulip.readthedocs.io/en/latest/contributing/contributing.html" style="box-sizing: border-box; color: hsl(283, 39%, 53%); text-decoration: none; cursor: pointer; outline: 0px; font-family: Lato, proxima-nova, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: hsl(0, 0%, 99%);">Contributing guide</a>';
+ '<meta http-equiv="content-type" content="text/html; charset=utf-8"><a class="reference external" href="https://zulip.readthedocs.io/en/latest/contributing/contributing.html" style="box-sizing: border-box; color: hsl(283, 39%, 53%); text-decoration: none; cursor: pointer; outline: 0px; font-family: Lato, proxima-nova, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: hsl(0, 0%, 99%);">Contributing guide</a>';
assert.equal(
copy_and_paste.paste_handler_converter(input),
- "normal text [Contributing guide](https://zulip.readthedocs.io/en/latest/contributing/contributing.html)",
+ "[Contributing guide](https://zulip.readthedocs.io/en/latest/contributing/contributing.html)",
);
// Only numbered list (list style retained)