From 21cfb8a2b5b6e0724212ae04474e92b8287928df Mon Sep 17 00:00:00 2001 From: Christian Bager Bach Houmann Date: Fri, 17 Mar 2023 14:36:03 +0100 Subject: [PATCH] feat: render markdown & HTML in choice names re #415 --- src/gui/choiceList/ChoiceListItem.svelte | 108 +++++++++--------- src/gui/choiceList/MultiChoiceListItem.svelte | 18 ++- src/gui/suggesters/choiceSuggester.ts | 8 +- src/styles.css | 24 ++++ 4 files changed, 104 insertions(+), 54 deletions(-) diff --git a/src/gui/choiceList/ChoiceListItem.svelte b/src/gui/choiceList/ChoiceListItem.svelte index 50cedec..7fe8795 100644 --- a/src/gui/choiceList/ChoiceListItem.svelte +++ b/src/gui/choiceList/ChoiceListItem.svelte @@ -1,58 +1,62 @@
- {choice.name} - - + + +
- + diff --git a/src/gui/choiceList/MultiChoiceListItem.svelte b/src/gui/choiceList/MultiChoiceListItem.svelte index aa6c9fb..c0bafec 100644 --- a/src/gui/choiceList/MultiChoiceListItem.svelte +++ b/src/gui/choiceList/MultiChoiceListItem.svelte @@ -5,6 +5,7 @@ import IMultiChoice from "../../types/choices/IMultiChoice"; import RightButtons from "./ChoiceItemRightButtons.svelte"; import {createEventDispatcher} from "svelte"; + import { Component, htmlToMarkdown, MarkdownRenderer } from "obsidian"; export let choice: IMultiChoice; export let collapseId: string; @@ -28,6 +29,21 @@ function duplicateChoice() { dispatcher('duplicateChoice', {choice}); } + + let nameElement: HTMLSpanElement; + + $: { + if (nameElement) { + nameElement.innerHTML = ""; + const nameHTML = htmlToMarkdown(choice.name); + MarkdownRenderer.renderMarkdown( + nameHTML, + nameElement, + "/", + null as unknown as Component + ); + } + }
@@ -35,7 +51,7 @@
choice.collapsed = !choice.collapsed}> - {choice.name} +
{ if (choiceExecutor) this.choiceExecutor = choiceExecutor; } + renderSuggestion(item: FuzzyMatch, el: HTMLElement): void { + el.empty(); + MarkdownRenderer.renderMarkdown(item.item.name, el, '', this.plugin); + el.classList.add("quickadd-choice-suggestion"); + } + getItemText(item: IChoice): string { return item.name; } diff --git a/src/styles.css b/src/styles.css index b5d78be..c26e821 100644 --- a/src/styles.css +++ b/src/styles.css @@ -214,3 +214,27 @@ .qaFileSuggestionItem .suggestion-sub-text { font-style: italic; } + +/* ChoiceListItem.svelte */ +.choiceListItem { + display: flex; + font-size: 16px; + align-items: center; + margin: 12px 0 0 0; + transition: 1000ms ease-in-out; +} + + +.choiceListItemName { + flex: 1 0 0; +} + +.choiceListItemName p { + margin: 0; + display: inline; +} + +/* ChoiceSuggester.ts */ +.quickadd-choice-suggestion p { + margin: 0; +} \ No newline at end of file