Clean duplicate title shown in reference snippets of hierarchical docs

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
This commit is contained in:
Debanjum Singh Solanky
2024-08-05 04:58:46 +05:30
parent 95c2a52775
commit e296d387e1
2 changed files with 12 additions and 7 deletions

View File

@@ -35,14 +35,23 @@ 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 (