mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-06 13:22:12 +00:00
Pass current component as arg to markdown renderer in chat view
This doesn't work on search modal, but hopefully will get resolved once we migrate search into a view from a modal
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { MarkdownRenderer, WorkspaceLeaf, request, requestUrl, setIcon } from 'obsidian';
|
import { ItemView, MarkdownRenderer, WorkspaceLeaf, request, requestUrl, setIcon } from 'obsidian';
|
||||||
import * as DOMPurify from 'dompurify';
|
import * as DOMPurify from 'dompurify';
|
||||||
import { KhojSetting } from 'src/settings';
|
import { KhojSetting } from 'src/settings';
|
||||||
import { KhojPaneView } from 'src/pane_view';
|
import { KhojPaneView } from 'src/pane_view';
|
||||||
@@ -304,7 +304,7 @@ export class KhojChatView extends KhojPaneView {
|
|||||||
// Convert the message to html, sanitize the message html and render it to the real DOM
|
// Convert the message to html, sanitize the message html and render it to the real DOM
|
||||||
let chat_message_body_text_el = this.contentEl.createDiv();
|
let chat_message_body_text_el = this.contentEl.createDiv();
|
||||||
chat_message_body_text_el.className = "chat-message-text-response";
|
chat_message_body_text_el.className = "chat-message-text-response";
|
||||||
chat_message_body_text_el.innerHTML = this.markdownTextToSanitizedHtml(message);
|
chat_message_body_text_el.innerHTML = this.markdownTextToSanitizedHtml(message, this);
|
||||||
|
|
||||||
// Add a copy button to each chat message, if it doesn't already exist
|
// Add a copy button to each chat message, if it doesn't already exist
|
||||||
if (willReplace === true) {
|
if (willReplace === true) {
|
||||||
@@ -314,13 +314,12 @@ export class KhojChatView extends KhojPaneView {
|
|||||||
return chat_message_body_text_el;
|
return chat_message_body_text_el;
|
||||||
}
|
}
|
||||||
|
|
||||||
markdownTextToSanitizedHtml(markdownText: string): string {
|
markdownTextToSanitizedHtml(markdownText: string, component: ItemView): string {
|
||||||
// Render markdown to an unlinked DOM element
|
// Render markdown to an unlinked DOM element
|
||||||
let virtualChatMessageBodyTextEl = document.createElement("div");
|
let virtualChatMessageBodyTextEl = document.createElement("div");
|
||||||
|
|
||||||
// Convert the message to html
|
// Convert the message to html
|
||||||
// @ts-ignore
|
MarkdownRenderer.renderMarkdown(markdownText, virtualChatMessageBodyTextEl, '', component);
|
||||||
MarkdownRenderer.renderMarkdown(markdownText, virtualChatMessageBodyTextEl, '', null);
|
|
||||||
|
|
||||||
// Remove image HTML elements with any non whitelisted src prefix
|
// Remove image HTML elements with any non whitelisted src prefix
|
||||||
virtualChatMessageBodyTextEl.innerHTML = virtualChatMessageBodyTextEl.innerHTML.replace(
|
virtualChatMessageBodyTextEl.innerHTML = virtualChatMessageBodyTextEl.innerHTML.replace(
|
||||||
@@ -407,7 +406,7 @@ export class KhojChatView extends KhojPaneView {
|
|||||||
chat_message_body_text_el.innerHTML = message;
|
chat_message_body_text_el.innerHTML = message;
|
||||||
} else {
|
} else {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
chat_message_body_text_el.innerHTML = this.markdownTextToSanitizedHtml(message);
|
chat_message_body_text_el.innerHTML = this.markdownTextToSanitizedHtml(message, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add action buttons to each chat message element
|
// Add action buttons to each chat message element
|
||||||
@@ -453,7 +452,7 @@ export class KhojChatView extends KhojPaneView {
|
|||||||
// Sanitize the markdown to render
|
// Sanitize the markdown to render
|
||||||
this.result = DOMPurify.sanitize(this.result);
|
this.result = DOMPurify.sanitize(this.result);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
htmlElement.innerHTML = this.markdownTextToSanitizedHtml(this.result);
|
htmlElement.innerHTML = this.markdownTextToSanitizedHtml(this.result, this);
|
||||||
// Render action buttons for the message
|
// Render action buttons for the message
|
||||||
this.renderActionButtons(this.result, htmlElement);
|
this.renderActionButtons(this.result, htmlElement);
|
||||||
// Scroll to bottom of modal, till the send message input box
|
// Scroll to bottom of modal, till the send message input box
|
||||||
|
|||||||
Reference in New Issue
Block a user