diff --git a/frontend/src/utils/chat/markdown.js b/frontend/src/utils/chat/markdown.js index fdff9ab34f..53b6804fef 100644 --- a/frontend/src/utils/chat/markdown.js +++ b/frontend/src/utils/chat/markdown.js @@ -2,15 +2,17 @@ import { encode as HTMLEncode } from "he"; import markdownIt from "markdown-it"; import hljs from "highlight.js"; import "highlight.js/styles/github-dark-dimmed.min.css"; +import { v4 } from "uuid"; const markdown = markdownIt({ html: true, typographer: true, highlight: function (str, lang) { + const uuid = v4(); if (lang && hljs.getLanguage(lang)) { try { return ( - `
` + + `" ); @@ -18,19 +20,19 @@ const markdown = markdownIt({ } return ( - `` + hljs.highlight(lang, str, true).value + "` + + `" ); }, }); -window.copySnippet = function () { - if (!event?.target) return false; - - const target = event?.target; +window.copySnippet = function (uuid = "") { + const target = document.getElementById(`code-${uuid}`); const markdown = - target.parentElement?.parentElement?.querySelector(".markdown")?.innerText; + target.parentElement?.parentElement?.querySelector( + "pre:first-of-type" + )?.innerText; if (!markdown) return false; window.navigator.clipboard.writeText(markdown);` + HTMLEncode(str) + "