Merge branch 'master' into svelte

# Conflicts:
#	pnpm-lock.yaml
#	src/main.ts
#	src/modal.ts
This commit is contained in:
Simon Cambier
2022-04-15 17:43:56 +02:00
8 changed files with 19 additions and 43 deletions

View File

@@ -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(' ')

View File

@@ -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<ResultNote> {
private plugin: OmnisearchPlugin
@@ -121,7 +121,9 @@ export class OmnisearchModal extends SuggestModal<ResultNote> {
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

View File

@@ -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 '<span class="search-result-file-matched-text">' + str + '</span>'
}
/**
* 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('&', '&amp;')
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')
.replaceAll('"', '&quot;')
.replaceAll("'", '&#039;')
}
/**