diff --git a/main.ts b/main.ts index d6046fa..2bcb1be 100644 --- a/main.ts +++ b/main.ts @@ -1,4 +1,4 @@ -import { App, Editor, FuzzyMatch, FuzzySuggestModal, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting, TFile } from 'obsidian'; +import { App, Editor, FuzzyMatch, FuzzySuggestModal, MarkdownRenderer, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting, TFile } from 'obsidian'; // TODO Remember to rename these classes and interfaces! @@ -172,22 +172,44 @@ class BlockSearchModal extends FuzzySuggestModal { } renderSuggestion({ item }: FuzzyMatch, el: HTMLElement ) { - const suggestionEl = el.createEl("div", { - cls: "suggestion-item", - }); - + // TODO make this optional const contentWithoutId = item.content.replace(`^${item.id}`, ""); - suggestionEl.createEl("div", { - text: contentWithoutId, - cls: "suggestion-content", - }); - - // TODO setting for path vs basename - const from = item.file.basename; - suggestionEl.createEl("small", { - text: `${from}#^${item.id}`, - cls: "suggestion-file", + // TODO make this optional + function unlinkfy(text: string): string { + return text.replace( + /\[([^\]]+)\]\([^)]+\)/g, + `$1` + ); + } + const sansLink = unlinkfy(contentWithoutId); + + el.createDiv({ cls: "suggestion-content" }, (contentDiv) => { + const textDiv = contentDiv.createDiv({ + // text: sansLink, + cls: "suggestion-block-text", + }); + textDiv.innerHTML = sansLink; + + // TODO setting for path vs basename + const from = item.file.basename; + contentDiv.createDiv({ + text: `${from}#^${item.id}`, + cls: "suggestion-block-file", + }); + + // TODO maybe use markdownRenderer? doesn't quite look right though.. + // but alternative is that i handle markdown like `**bold**` i guess? 🤔 + // OTOH markdown is just readable text too... so maybe not a big deal? + // + // here's an example anyway: + // + // const markdownDiv = contentDiv.createDiv({ + // cls: "suggestion-markdown-test", + // }); + // const sourcePath = this.app.workspace.getActiveFile()?.path; + // if (!sourcePath) throw new Error("No source path"); // TODO feels wrong + // MarkdownRenderer.render(this.app, contentWithoutId, markdownDiv, sourcePath, this.plugin) }); } diff --git a/manifest-beta.json b/manifest-beta.json index 263f491..9e3de24 100644 --- a/manifest-beta.json +++ b/manifest-beta.json @@ -1,7 +1,7 @@ { "id": "blockreffer", "name": "Blockreffer", - "version": "1.1.0", + "version": "1.2.0", "minAppVersion": "0.15.0", "description": "Search and embed blocks with ^block-references (aka ^block-ids)", "author": "tyler-dot-earth", diff --git a/manifest.json b/manifest.json index 263f491..9e3de24 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "blockreffer", "name": "Blockreffer", - "version": "1.1.0", + "version": "1.2.0", "minAppVersion": "0.15.0", "description": "Search and embed blocks with ^block-references (aka ^block-ids)", "author": "tyler-dot-earth", diff --git a/package-lock.json b/package-lock.json index 9b2c45c..e79882b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "Blockreffer", - "version": "1.1.0", + "version": "1.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "Blockreffer", - "version": "1.1.0", + "version": "1.2.0", "license": "MIT", "devDependencies": { "@types/node": "^16.11.6", diff --git a/package.json b/package.json index c2f7e38..7ac2467 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Blockreffer", - "version": "1.1.0", + "version": "1.2.0", "description": "Search and embed blocks with ^block-references (aka ^block-ids)", "main": "main.js", "scripts": { diff --git a/styles.css b/styles.css index 3302ac2..a861b5c 100644 --- a/styles.css +++ b/styles.css @@ -7,7 +7,18 @@ If your plugin does not need CSS, delete this file. */ -.suggestion-file { - font-size: 0.8rem; +.suggestion-content { + display: flex; + flex-direction: column; + gap: 0.15rem; +} + +.suggestion-block-link { + text-decoration: underline; + text-decoration-color: var(--text-faint); + text-underline-offset: 0.2rem; +} + +.suggestion-block-file { color: var(--text-muted); }