rendered_markdown: Fix code getting copied when visiting playground.

Fixes #29844.
This commit is contained in:
nimishmedatwal 2024-04-27 00:27:30 +05:30 committed by Tim Abbott
parent 178d4f364b
commit acf13e49cf
2 changed files with 13 additions and 10 deletions

View File

@ -307,14 +307,15 @@ export const update_elements = ($content: JQuery): void => {
$view_in_playground_button.attr("data-tippy-content", title);
$view_in_playground_button.attr("aria-label", title);
}
const clipboard = new ClipboardJS($buttonContainer[0], {
const $copy_button = $buttonContainer.find(".copy_codeblock");
const clipboard = new ClipboardJS($copy_button[0], {
text(copy_element) {
return $(copy_element).siblings("code").text();
const $code = $(copy_element).parent().siblings("code");
return $code.text();
},
});
clipboard.on("success", () => {
const $copy_button = $buttonContainer.find(".copy_codeblock");
show_copied_confirmation($copy_button[0]);
});
$codehilite.addClass("zulip-code-block");

View File

@ -529,12 +529,14 @@ function assert_clipboard_setup() {
assert.equal(clipboard_args[0], "copy-code-stub");
const text = clipboard_args[1].text({
to_$: () => ({
siblings(arg) {
assert.equal(arg, "code");
return {
text: () => "text",
};
},
parent: () => ({
siblings(arg) {
assert.equal(arg, "code");
return {
text: () => "text",
};
},
}),
}),
});
assert.equal(text, "text");