Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
37 lines (30 sloc)
968 Bytes
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
| import { MarkdownRenderChild, MarkdownRenderer } from "obsidian"; | |
| export class PurpleImage extends MarkdownRenderChild { | |
| static ALL_EMOJIS: Record<string, string> = { | |
| ":+1:": "👍", | |
| ":sunglasses:": "😎", | |
| ":smile:": "😄", | |
| }; | |
| text: string; | |
| constructor(containerEl: HTMLElement, text: string) { | |
| super(containerEl); | |
| this.text = text; | |
| } | |
| onload() { | |
| const items = this.text.split("\n"); | |
| const markdownItems = items.map(createMarkdownImage); | |
| const container = this.containerEl.createDiv(); | |
| if (items.length > 1) { | |
| container.addClass("image-grid"); | |
| } | |
| MarkdownRenderer.renderMarkdown(markdownItems.join(""), container, null, null); | |
| this.containerEl.replaceWith(container); | |
| } | |
| } | |
| function createMarkdownImage(text: string) { | |
| if (text.length == 0) { | |
| return "" | |
| } else { | |
| return "![[" + text.substring(1) + "]]" | |
| } | |
| } |