generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: render markdown & HTML in choice names
re #415
- Loading branch information
Showing
4 changed files
with
104 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,62 @@ | ||
<script lang="ts"> | ||
import IChoice from "../../types/choices/IChoice"; | ||
import RightButtons from "./ChoiceItemRightButtons.svelte"; | ||
import {createEventDispatcher} from "svelte"; | ||
export let choice: IChoice; | ||
export let dragDisabled: boolean; | ||
let showConfigureButton: boolean = true; | ||
const dispatcher = createEventDispatcher(); | ||
function deleteChoice() { | ||
dispatcher('deleteChoice', {choice}); | ||
} | ||
function configureChoice() { | ||
dispatcher('configureChoice', {choice}); | ||
} | ||
function toggleCommandForChoice() { | ||
dispatcher('toggleCommand', {choice}); | ||
} | ||
function duplicateChoice() { | ||
dispatcher('duplicateChoice', {choice}); | ||
} | ||
import IChoice from "../../types/choices/IChoice"; | ||
import RightButtons from "./ChoiceItemRightButtons.svelte"; | ||
import { createEventDispatcher } from "svelte"; | ||
import { Component, htmlToMarkdown, MarkdownRenderer } from "obsidian"; | ||
export let choice: IChoice; | ||
export let dragDisabled: boolean; | ||
let showConfigureButton: boolean = true; | ||
const dispatcher = createEventDispatcher(); | ||
function deleteChoice() { | ||
dispatcher("deleteChoice", { choice }); | ||
} | ||
function configureChoice() { | ||
dispatcher("configureChoice", { choice }); | ||
} | ||
function toggleCommandForChoice() { | ||
dispatcher("toggleCommand", { choice }); | ||
} | ||
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 | ||
); | ||
} | ||
} | ||
</script> | ||
|
||
<div class="choiceListItem"> | ||
<span class="choiceListItemName">{choice.name}</span> | ||
|
||
<RightButtons | ||
on:mousedown | ||
on:touchstart | ||
on:deleteChoice={deleteChoice} | ||
on:configureChoice={configureChoice} | ||
on:toggleCommand={toggleCommandForChoice} | ||
on:duplicateChoice={duplicateChoice} | ||
bind:choiceName={choice.name} | ||
bind:commandEnabled={choice.command} | ||
bind:showConfigureButton | ||
bind:dragDisabled | ||
showDuplicateButton={true} | ||
/> | ||
<span class="choiceListItemName" bind:this={nameElement} /> | ||
|
||
<RightButtons | ||
on:mousedown | ||
on:touchstart | ||
on:deleteChoice={deleteChoice} | ||
on:configureChoice={configureChoice} | ||
on:toggleCommand={toggleCommandForChoice} | ||
on:duplicateChoice={duplicateChoice} | ||
bind:choiceName={choice.name} | ||
bind:commandEnabled={choice.command} | ||
bind:showConfigureButton | ||
bind:dragDisabled | ||
showDuplicateButton={true} | ||
/> | ||
</div> | ||
|
||
<style> | ||
.choiceListItem { | ||
display: flex; | ||
font-size: 16px; | ||
align-items: center; | ||
margin: 12px 0 0 0; | ||
transition: 1000ms ease-in-out; | ||
} | ||
.choiceListItemName { | ||
flex: 1 0 0; | ||
} | ||
</style> | ||
<style></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters