Skip to content

Commit adc2a09

Browse files
committed
fix: Fix markdown processing of code blocks (e.g. dice roller) within inline rant block and block links
1 parent 11d2f99 commit adc2a09

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/main.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ export default class RantLangPlugin extends Plugin {
6767
codeblock.replaceWith(container);
6868

6969
const code = text.substring(inlineRantQueryPrefix.length).trim();
70-
const processorClass = code.match(BLOCK_LINK_REGEX)
70+
const Processor = code.match(BLOCK_LINK_REGEX)
7171
? BlockLinkRantProcessor
7272
: InlineRantProcessor;
7373

74-
const processor = new processorClass(
74+
const processor = new Processor(
7575
this,
7676
code,
7777
container,

src/processor.ts

+16-14
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,18 @@ export class CodeblockRantProcessor extends BaseRantProcessor {
6161

6262
export class InlineRantProcessor extends BaseRantProcessor {
6363
renderResult() {
64-
let temp = createEl("div");
64+
let temp = createEl("span");
6565
MarkdownRenderer.renderMarkdown(this.result, temp, this.sourcePath, this);
6666

67-
this.container.empty();
68-
this.container.className = this.getStyles().join(" ");
69-
67+
let nodes: Node[] = [];
7068
temp.childNodes.forEach((paragraph) => {
71-
paragraph.childNodes.forEach((node) => {
72-
this.container.appendChild(node.cloneNode(true));
73-
});
69+
nodes.push(...(paragraph.childNodes as any as Node[]));
70+
nodes.push(createEl("br"));
7471
});
72+
nodes.pop();
73+
74+
this.container.className = this.getStyles().join(" ");
75+
this.container.replaceChildren(...nodes);
7576
}
7677

7778
getStyles() {
@@ -134,17 +135,18 @@ export class BlockLinkRantProcessor extends BaseRantProcessor {
134135
}
135136

136137
renderResult() {
137-
let temp = createEl("div");
138+
let temp = createEl("span");
138139
MarkdownRenderer.renderMarkdown(this.result, temp, this.sourcePath, this);
139140

140-
this.container.empty();
141-
this.container.className = this.getStyles().join(" ");
142-
141+
let nodes: Node[] = [];
143142
temp.childNodes.forEach((paragraph) => {
144-
paragraph.childNodes.forEach((node) => {
145-
this.container.appendChild(node.cloneNode(true));
146-
});
143+
nodes.push(...(paragraph.childNodes as any as Node[]));
144+
nodes.push(createEl("br"));
147145
});
146+
nodes.pop();
147+
148+
this.container.className = this.getStyles().join(" ");
149+
this.container.replaceChildren(...nodes);
148150
}
149151

150152
getStyles() {

0 commit comments

Comments
 (0)