mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-03 13:19:16 +00:00
Copy chat message with it's markdown formatting in Web, Desktop apps
This commit is contained in:
@@ -13,9 +13,14 @@
|
||||
|
||||
<script>
|
||||
let chatOptions = [];
|
||||
function copyParentText(event) {
|
||||
function createCopyParentText(message) {
|
||||
return function(event) {
|
||||
copyParentText(event, message);
|
||||
}
|
||||
}
|
||||
function copyParentText(event, message=null) {
|
||||
const button = event.currentTarget;
|
||||
const textContent = button.parentNode.textContent.trim();
|
||||
const textContent = message ?? button.parentNode.textContent.trim();
|
||||
navigator.clipboard.writeText(textContent).then(() => {
|
||||
button.firstChild.src = "./assets/icons/copy-button-success.svg";
|
||||
setTimeout(() => {
|
||||
@@ -306,9 +311,9 @@
|
||||
return renderMessage(message, by, dt, references, false, "return");
|
||||
}
|
||||
|
||||
function formatHTMLMessage(htmlMessage, raw=false, willReplace=true) {
|
||||
function formatHTMLMessage(message, raw=false, willReplace=true) {
|
||||
var md = window.markdownit();
|
||||
let newHTML = htmlMessage;
|
||||
let newHTML = message;
|
||||
|
||||
// Remove any text between <s>[INST] and </s> tags. These are spurious instructions for the AI chat model.
|
||||
newHTML = newHTML.replace(/<s>\[INST\].+(<\/s>)?/g, '');
|
||||
@@ -340,7 +345,7 @@
|
||||
copyIcon.src = "./assets/icons/copy-button.svg";
|
||||
copyIcon.classList.add("copy-icon");
|
||||
copyButton.appendChild(copyIcon);
|
||||
copyButton.addEventListener('click', copyParentText);
|
||||
copyButton.addEventListener('click', createCopyParentText(message));
|
||||
element.append(copyButton);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user