Skip to content

Commit c726232

Browse files
committed
feat: Allow Markdown parsing of inline rant blocks as well, enabling styling, links, etc.
1 parent a9b93c7 commit c726232

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ Thin wrapper around the [Rant language](https://rant-lang.org/) Rust crate to be
88
## Usage
99

1010
Use a code block with the `rant` type, in which you can enter a Rant program.
11-
The program is then compiled and executed with Rant, and the result shown as in the Obsidian preview mode.
11+
The program is then compiled and executed with Rant, and the result shown in the Obsidian preview mode.
1212

1313
Use the command `Re-rant with random seed (active file)` (default hotkey: `Cmd+R`/`Ctrl+R`) to run Rant again on each block in the active (preview) file.
1414

1515
It's also possible to insert a Rant program inline by starting an inline code block with "`rant:`".
1616

17-
Within a `rant` (non-inline) code block, the result of the program is then rendered with the Obsidian MarkdownParser.
17+
Within a `rant` block (both inline and code blocks), the result of the program is then rendered with the Obsidian MarkdownParser.
1818
That means that you can add styling, links, or other markdown-processing elements inside a `rant` block, and they will be rendered accordingly.
1919
In order to avoid Rant syntax errors, you can wrap these elements in double quotes, because Rant treats everything inside double quotes as [string literals](https://docs.rant-lang.org/language/text.html#string-literals), and will not evaluate the content.
2020

src/processor.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,17 @@ export class CodeblockRantProcessor extends BaseRantProcessor {
6060

6161
export class InlineRantProcessor extends BaseRantProcessor {
6262
renderResult() {
63+
let temp = createEl("div");
64+
MarkdownRenderer.renderMarkdown(this.result, temp, this.sourcePath, this);
65+
6366
this.container.empty();
6467
this.container.className = this.getStyles().join(" ");
65-
this.container.appendText(this.result);
68+
69+
temp.childNodes.forEach((paragraph) => {
70+
paragraph.childNodes.forEach((node) => {
71+
this.container.appendChild(node.cloneNode(true));
72+
});
73+
});
6674
}
6775

6876
getStyles() {

0 commit comments

Comments
 (0)