diff --git a/manifest.json b/manifest.json index dc8ffca..43a6311 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "scambier.obsidian-omnisearch", "name": "Omnisearch", - "version": "0.1.6", + "version": "0.1.7", "minAppVersion": "0.14.2", "description": "Search over organization", "author": "Simon Cambier", diff --git a/package.json b/package.json index f555868..b0e463c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scambier.obsidian-search", - "version": "0.1.6", + "version": "0.1.7", "description": "Search over organization", "main": "dist/main.js", "scripts": { @@ -34,7 +34,6 @@ "typescript": "^4.6.3" }, "dependencies": { - "markdown-to-txt": "^2.0.0", "minisearch": "^5.0.0-beta1" } } \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3428ce7..40106e6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,7 +14,6 @@ specifiers: eslint-plugin-import: 2.22.1 eslint-plugin-node: 11.1.0 eslint-plugin-promise: 5.0.0 - markdown-to-txt: ^2.0.0 minisearch: ^5.0.0-beta1 obsidian: latest prettier: ^2.6.2 @@ -25,7 +24,6 @@ specifiers: typescript: ^4.6.3 dependencies: - markdown-to-txt: 2.0.0 minisearch: 5.0.0-beta1 devDependencies: @@ -1536,18 +1534,10 @@ packages: path-exists: 3.0.0 dev: true - /lodash.escape/4.0.1: - resolution: {integrity: sha1-yQRGkMIeBClL6qUXcS/e0fqI3pg=} - dev: false - /lodash.merge/4.6.2: resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==} dev: true - /lodash.unescape/4.0.1: - resolution: {integrity: sha1-vyJJiGzlFM2hEvrpIYzcBlIR/Jw=} - dev: false - /lodash/4.17.21: resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} dev: true @@ -1577,20 +1567,6 @@ packages: sourcemap-codec: 1.4.8 dev: true - /markdown-to-txt/2.0.0: - resolution: {integrity: sha512-H5DSAY6frUQ6/CR0nJMlGCEuSA3pvi14dYfICJPKLAvd/rDk6eb+cj84zU5XTNYzECyCcujoAL1PHhjmOgeqUw==} - dependencies: - lodash.escape: 4.0.1 - lodash.unescape: 4.0.1 - marked: 3.0.8 - dev: false - - /marked/3.0.8: - resolution: {integrity: sha512-0gVrAjo5m0VZSJb4rpL59K1unJAMb/hm8HRXqasD8VeC8m91ytDPMritgFSlKonfdt+rRYYpP/JfLxgIX8yoSw==} - engines: {node: '>= 12'} - hasBin: true - dev: false - /merge2/1.4.1: resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==} engines: {node: '>= 8'} diff --git a/src/main.ts b/src/main.ts index 000f9ec..1d583d7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,7 +1,7 @@ import { Notice, Plugin, TAbstractFile, TFile } from 'obsidian' import MiniSearch from 'minisearch' -import { clearContent, extractHeadingsFromCache, wait } from './utils' import type { IndexedNote } from './globals' +import { escapeHTML, extractHeadingsFromCache, wait } from './utils' import { OmnisearchModal } from './modal' export default class OmnisearchPlugin extends Plugin { @@ -93,7 +93,7 @@ export default class OmnisearchPlugin extends Plugin { } // Fetch content from the cache, // trim the markdown, remove embeds and clear wikilinks - const content = clearContent(await this.app.vault.cachedRead(file)) + const content = escapeHTML(await this.app.vault.cachedRead(file)) // Purge HTML before indexing const tmp = document.createElement('div') @@ -102,7 +102,7 @@ export default class OmnisearchPlugin extends Plugin { // Make the document and index it const note: IndexedNote = { basename: file.basename, - content: tmp.innerText, + content: tmp.innerText, // content, path: file.path, headings1: fileCache ? extractHeadingsFromCache(fileCache, 1).join(' ') diff --git a/src/modal.ts b/src/modal.ts index 72b29e5..9c5c105 100644 --- a/src/modal.ts +++ b/src/modal.ts @@ -1,8 +1,8 @@ import { MarkdownView, SuggestModal, TFile } from 'obsidian' import type { ResultNote } from './globals' import type OmnisearchPlugin from './main' -import { escapeRegex, getAllIndexes, highlighter } from './utils' import Component from './Component.svelte' +import { escapeHTML, escapeRegex, getAllIndexes, highlighter } from './utils' export class OmnisearchModal extends SuggestModal { private plugin: OmnisearchPlugin @@ -121,7 +121,9 @@ export class OmnisearchModal extends SuggestModal { results.map(async result => { const file = this.app.vault.getAbstractFileByPath(result.id) as TFile // const metadata = this.app.metadataCache.getFileCache(file) - let content = (await this.app.vault.cachedRead(file)).toLowerCase() + let content = escapeHTML( + await this.app.vault.cachedRead(file), + ).toLowerCase() let basename = file.basename // Sort the terms from smaller to larger diff --git a/src/utils.ts b/src/utils.ts index b80293a..e3286a4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,3 @@ -import markdownToTxt from 'markdown-to-txt' import { CachedMetadata } from 'obsidian' import { isSearchMatch, @@ -12,12 +11,13 @@ export function highlighter(str: string): string { return '' + str + '' } -/** - * Strips the markdown and frontmatter - * @param text - */ -export function clearContent(text: string): string { - return markdownToTxt(removeFrontMatter(text)) +export function escapeHTML(html: string): string { + return html + .replaceAll('&', '&') + .replaceAll('<', '<') + .replaceAll('>', '>') + .replaceAll('"', '"') + .replaceAll("'", ''') } /** diff --git a/tsconfig.json b/tsconfig.json index 20f2ab0..f4f6ce8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,9 +16,7 @@ "isolatedModules": true, "lib": [ "DOM", - "ES5", - "ES6", - "ES7" + "ES2021" ] }, "include": [ diff --git a/versions.json b/versions.json index 7f659f9..13a2c78 100644 --- a/versions.json +++ b/versions.json @@ -5,5 +5,6 @@ "0.1.3": "0.14.2", "0.1.4": "0.14.2", "0.1.5": "0.14.2", - "0.1.6": "0.14.2" + "0.1.6": "0.14.2", + "0.1.7": "0.14.2" } \ No newline at end of file