Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
docs: Correct scope of copied material from copy button.
Karl Stolleyd6c21c223791
diff --git a/web/src/portico/help.js b/web/src/portico/help.jsindex 9978b4e26d4..a80171e4719 100644--- a/web/src/portico/help.js+++ b/web/src/portico/help.js@@ -30,17 +30,19 @@ function registerCodeSection($codeSection) {});}-// Display the copy-to-clipboard button inside the markdown.pre element+// Display the copy-to-clipboard button inside the .codehilite element// within the API and Help Center docs using clipboard.js-function add_copy_to_clipboard_element($pre) {+function add_copy_to_clipboard_element($codehilite) {const $copy_button = $("<button>").addClass("copy-codeblock");$copy_button.html(copy_to_clipboard_svg());- $($pre).append($copy_button);+ $($codehilite).append($copy_button);const clipboard = new ClipboardJS($copy_button[0], {text(copy_element) {- return $(copy_element).siblings("code").text();+ // trim to remove trailing whitespace introduced+ // by additional elements inside <pre>+ return $(copy_element).siblings("pre").text().trim();},});@@ -90,8 +92,8 @@ function render_code_sections() {registerCodeSection($(this));});- // Add a copy-to-clipboard button for each pre element- $(".markdown pre").each(function () {+ // Add a copy-to-clipboard button for each .codehilite element+ $(".markdown .codehilite").each(function () {add_copy_to_clipboard_element($(this));});diff --git a/web/styles/portico/markdown.css b/web/styles/portico/markdown.cssindex 0577300f98c..67ed07c8bdc 100644--- a/web/styles/portico/markdown.css+++ b/web/styles/portico/markdown.css@@ -381,11 +381,13 @@background-color: hsl(0deg 0% 93%);}- & pre {+ .codehilite {/* Relative positioning is used to place the copy-to-clipboard buttonin the top-right corner. */position: relative;+ }+ & pre {& code {font-size: 14px;white-space: pre-wrap;