feat(ocr): display OCR text only in search results

This commit is contained in:
Elian Doran 2025-07-26 12:55:52 +03:00
parent 6212ea0304
commit 925c9c1e7b
No known key found for this signature in database
2 changed files with 7 additions and 5 deletions

View File

@ -23,6 +23,7 @@ interface Options {
tooltip?: boolean; tooltip?: boolean;
trim?: boolean; trim?: boolean;
imageHasZoom?: boolean; imageHasZoom?: boolean;
showOcrText?: boolean;
} }
const CODE_MIME_TYPES = new Set(["application/json"]); const CODE_MIME_TYPES = new Set(["application/json"]);
@ -48,7 +49,7 @@ async function getRenderedContent(this: {} | { ctx: string }, entity: FNote | FA
} else if (["image", "canvas", "mindMap"].includes(type)) { } else if (["image", "canvas", "mindMap"].includes(type)) {
await renderImage(entity, $renderedContent, options); await renderImage(entity, $renderedContent, options);
} else if (!options.tooltip && ["file", "pdf", "audio", "video"].includes(type)) { } else if (!options.tooltip && ["file", "pdf", "audio", "video"].includes(type)) {
await renderFile(entity, type, $renderedContent); await renderFile(entity, type, $renderedContent, options);
} else if (type === "mermaid") { } else if (type === "mermaid") {
await renderMermaid(entity, $renderedContent); await renderMermaid(entity, $renderedContent);
} else if (type === "render" && entity instanceof FNote) { } else if (type === "render" && entity instanceof FNote) {
@ -175,7 +176,7 @@ async function renderImage(entity: FNote | FAttachment, $renderedContent: JQuery
imageContextMenuService.setupContextMenu($img); imageContextMenuService.setupContextMenu($img);
// Add OCR text display for image notes // Add OCR text display for image notes
if (entity instanceof FNote) { if (entity instanceof FNote && options.showOcrText) {
await addOCRTextIfAvailable(entity, $renderedContent); await addOCRTextIfAvailable(entity, $renderedContent);
} }
} }
@ -205,7 +206,7 @@ async function addOCRTextIfAvailable(note: FNote, $content: JQuery<HTMLElement>)
} }
} }
async function renderFile(entity: FNote | FAttachment, type: string, $renderedContent: JQuery<HTMLElement>) { async function renderFile(entity: FNote | FAttachment, type: string, $renderedContent: JQuery<HTMLElement>, options: Options = {}) {
let entityType, entityId; let entityType, entityId;
if (entity instanceof FNote) { if (entity instanceof FNote) {
@ -242,7 +243,7 @@ async function renderFile(entity: FNote | FAttachment, type: string, $renderedCo
} }
// Add OCR text display for file notes // Add OCR text display for file notes
if (entity instanceof FNote) { if (entity instanceof FNote && options.showOcrText) {
await addOCRTextIfAvailable(entity, $content); await addOCRTextIfAvailable(entity, $content);
} }

View File

@ -351,7 +351,8 @@ class ListOrGridView extends ViewMode<{}> {
try { try {
const { $renderedContent, type } = await contentRenderer.getRenderedContent(note, { const { $renderedContent, type } = await contentRenderer.getRenderedContent(note, {
trim: this.viewType === "grid" // for grid only short content is needed trim: this.viewType === "grid", // for grid only short content is needed
showOcrText: this.parentNote.type === "search" // show OCR text only in search results
}); });
if (this.highlightRegex) { if (this.highlightRegex) {