Skip to content

Commit

Permalink
Clean duplicate title shown in reference snippets of hierarchical docs
Browse files Browse the repository at this point in the history
Hierarchical documents like org-mode, markdown have their ancestry
shown in first line. Remove it to show cleaner, deduplicated reference
text from org-mode, markdown files
  • Loading branch information
debanjum committed Aug 4, 2024
1 parent 6526bcf commit 40b7568
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 0 additions & 4 deletions src/interface/web/app/components/chatMessage/chatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,11 @@ export default function ChatMessage(props: ChatMessageProps) {

useEffect(() => {
const observer = new MutationObserver((mutationsList, observer) => {
console.log("called mutation observer");
// If the addedNodes property has one or more nodes
if (messageRef.current) {
for (let mutation of mutationsList) {
if (mutation.type === "childList" && mutation.addedNodes.length > 0) {
// Call your function here

console.log("render katex in body");

renderMathInElement(messageRef.current, {
delimiters: [
{ left: "$$", right: "$$", display: true },
Expand Down
15 changes: 12 additions & 3 deletions src/interface/web/app/components/referencePanel/referencePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,20 @@ interface NotesContextReferenceCardProps extends NotesContextReferenceData {
showFullContent: boolean;
}

function extractSnippet(props: NotesContextReferenceCardProps): string {
const hierarchicalFileExtensions = ["org", "md", "markdown"];
const extension = props.title.split(".").pop() || "";
const cleanContent = hierarchicalFileExtensions.includes(extension)
? props.content.split("\n").slice(1).join("\n")
: props.content;
return props.showFullContent
? DOMPurify.sanitize(md.render(cleanContent))
: DOMPurify.sanitize(cleanContent);
}

function NotesContextReferenceCard(props: NotesContextReferenceCardProps) {
const snippet = props.showFullContent
? DOMPurify.sanitize(md.render(props.content))
: DOMPurify.sanitize(props.content);
const fileIcon = getIconFromFilename(props.title || ".txt", "w-6 h-6 text-muted-foreground inline-flex mr-2");
const snippet = extractSnippet(props);
const [isHovering, setIsHovering] = useState(false);

return (
Expand Down

0 comments on commit 40b7568

Please sign in to comment.