|
1 | | -import { Component, MarkdownRenderer } from 'obsidian'; |
| 1 | +import {App} from 'obsidian'; |
| 2 | +import {MarkdownBuilder} from './markdown/MarkdownBuilder'; |
| 3 | +import JsEnginePlugin from '../main'; |
| 4 | +import {MarkdownString} from './markdown/MarkdownString'; |
| 5 | +import { |
| 6 | + BlockQuoteElement, |
| 7 | + CalloutElement, |
| 8 | + CodeBlockElement, |
| 9 | + CodeElement, |
| 10 | + HeadingElement, |
| 11 | + ParagraphElement, |
| 12 | + TableElement, |
| 13 | + TextElement, |
| 14 | +} from './markdown/AbstractMarkdownElementContainer'; |
2 | 15 |
|
3 | | -export class MarkdownString { |
4 | | - content: string; |
5 | 16 |
|
6 | | - constructor(content: string) { |
7 | | - this.content = content; |
| 17 | + |
| 18 | +export class MarkdownAPI { |
| 19 | + readonly app: App; |
| 20 | + readonly plugin: JsEnginePlugin; |
| 21 | + |
| 22 | + |
| 23 | + constructor(app: App, plugin: JsEnginePlugin) { |
| 24 | + this.app = app; |
| 25 | + this.plugin = plugin; |
8 | 26 | } |
9 | 27 |
|
10 | | - async render(element: HTMLElement, sourcePath: string, component: Component): Promise<void> { |
11 | | - await MarkdownRenderer.renderMarkdown(this.content, element, sourcePath, component); |
| 28 | + createBuilder(): MarkdownBuilder { |
| 29 | + return new MarkdownBuilder(); |
| 30 | + } |
| 31 | + |
| 32 | + create(markdown: string): MarkdownString { |
| 33 | + return new MarkdownString(markdown); |
| 34 | + } |
| 35 | + |
| 36 | + createText(text: string): TextElement { |
| 37 | + return new TextElement(text, false, false, false); |
| 38 | + } |
| 39 | + |
| 40 | + createBoldText(text: string): TextElement { |
| 41 | + return new TextElement(text, true, false, false); |
| 42 | + } |
| 43 | + |
| 44 | + createCursiveText(text: string): TextElement { |
| 45 | + return new TextElement(text, false, true, false); |
| 46 | + } |
| 47 | + |
| 48 | + createUnderlinedText(text: string): TextElement { |
| 49 | + return new TextElement(text, false, false, true); |
12 | 50 | } |
13 | | -} |
14 | 51 |
|
15 | | -export class MarkdownAPI {} |
| 52 | + createCode(text: string): CodeElement { |
| 53 | + return new CodeElement(text); |
| 54 | + } |
| 55 | + |
| 56 | + createParagraph(content: string): ParagraphElement { |
| 57 | + return new ParagraphElement(content); |
| 58 | + } |
| 59 | + |
| 60 | + createHeading(level: number, content: string): HeadingElement { |
| 61 | + return new HeadingElement(level, content); |
| 62 | + } |
| 63 | + |
| 64 | + createBlockQuote(): BlockQuoteElement { |
| 65 | + return new BlockQuoteElement(); |
| 66 | + } |
| 67 | + |
| 68 | + createCallout(title: string, type: string, args: string = ''): CalloutElement { |
| 69 | + return new CalloutElement(title, type, args); |
| 70 | + } |
| 71 | + |
| 72 | + createCodeBlock(language: string, content: string): CodeBlockElement { |
| 73 | + return new CodeBlockElement(language, content); |
| 74 | + } |
| 75 | + |
| 76 | + createTable(header: string[], body: string[][]): TableElement { |
| 77 | + return new TableElement(header, body); |
| 78 | + } |
| 79 | +} |
0 commit comments