diff --git a/private/pages/interface.php b/private/pages/interface.php index fe6506c..ce949d6 100644 --- a/private/pages/interface.php +++ b/private/pages/interface.php @@ -722,6 +722,30 @@ function CopyContentToClipboard(target) { table.parentNode.replaceChild(textNode, table); }); + // Remove code language from copy content + if(clone.tagName === "CODE") { + const firstChildNode = clone.firstChild; + const lastChildNode = clone.lastChild; + + if(firstChildNode && firstChildNode.nodeName === "#text") { + // Remove the first node, as it contains the code language + // It is possible that the code language is followed by actual code, so check for that + if(firstChildNode.textContent.includes("\n")) { + firstChildNode.textContent = firstChildNode.textContent.split("\n")[1]; + } else { + clone.removeChild(firstChildNode); + } + } + + if (lastChildNode && lastChildNode.nodeName === "#text") { + // In some cases, there might be markdown content at the end of the code block due to formatting errors + const re = "\n?```" + if(lastChildNode.textContent.match(re)) { + lastChildNode.textContent = lastChildNode.textContent.replace("\n```", ""); + } + } + } + // Get the text content of the modified clone const msgTxt = clone.textContent.trim();