Skip to content

Commit 41c8f3a

Browse files
authored
Update "Fix inline list rendering in live preview (#2387)" (#2416)
* Revert "Fix inline list rendering in live preview (#2387)" This reverts commit 6a6e025. * Fix inline rendering for lists in live preview * fix formatting
1 parent 5ac0424 commit 41c8f3a

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

src/ui/render.ts

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,45 @@ export async function renderCompactMarkdown(
1111
markdown: string,
1212
container: HTMLElement,
1313
sourcePath: string,
14-
component: Component
14+
component: Component,
15+
isInlineFieldLivePreview: boolean = false
1516
) {
16-
let subcontainer = container.createSpan();
17-
await MarkdownRenderer.render(app, markdown, subcontainer, sourcePath, component);
17+
// check if the call is from the CM6 view plugin defined in src/ui/views/inline-field-live-preview.ts
18+
if (isInlineFieldLivePreview) {
19+
await renderCompactMarkdownForInlineFieldLivePreview(app, markdown, container, sourcePath, component);
20+
} else {
21+
let subcontainer = container.createSpan();
22+
await MarkdownRenderer.render(app, markdown, subcontainer, sourcePath, component);
1823

19-
let paragraph = subcontainer.querySelector(":scope > p");
20-
if (subcontainer.children.length == 1 && paragraph) {
21-
while (paragraph.firstChild) {
22-
subcontainer.appendChild(paragraph.firstChild);
24+
let paragraph = subcontainer.querySelector(":scope > p");
25+
if (subcontainer.children.length == 1 && paragraph) {
26+
while (paragraph.firstChild) {
27+
subcontainer.appendChild(paragraph.firstChild);
28+
}
29+
subcontainer.removeChild(paragraph);
2330
}
24-
subcontainer.removeChild(paragraph);
2531
}
2632
}
2733

34+
async function renderCompactMarkdownForInlineFieldLivePreview(
35+
app: App,
36+
markdown: string,
37+
container: HTMLElement,
38+
sourcePath: string,
39+
component: Component
40+
) {
41+
const tmpContainer = createSpan();
42+
await MarkdownRenderer.render(app, markdown, tmpContainer, sourcePath, component);
43+
let paragraph = tmpContainer.querySelector(":scope > p");
44+
if (tmpContainer.childNodes.length == 1 && paragraph) {
45+
container.appendChild(paragraph.childNodes.item(paragraph.childNodes.length - 1));
46+
} else {
47+
container.replaceChildren(...tmpContainer.childNodes);
48+
}
49+
50+
tmpContainer.remove();
51+
}
52+
2853
/** Render a pre block with an error in it; returns the element to allow for dynamic updating. */
2954
export function renderErrorPre(container: HTMLElement, error: string): HTMLElement {
3055
let pre = container.createEl("pre", { cls: ["dataview", "dataview-error"] });
@@ -62,15 +87,22 @@ export async function renderValue(
6287
}
6388

6489
if (Values.isNull(field)) {
65-
await renderCompactMarkdown(app, settings.renderNullAs, container, originFile, component);
90+
await renderCompactMarkdown(
91+
app,
92+
settings.renderNullAs,
93+
container,
94+
originFile,
95+
component,
96+
isInlineFieldLivePreview
97+
);
6698
} else if (Values.isDate(field)) {
6799
container.appendText(renderMinimalDate(field, settings, currentLocale()));
68100
} else if (Values.isDuration(field)) {
69101
container.appendText(renderMinimalDuration(field));
70102
} else if (Values.isString(field) || Values.isBoolean(field) || Values.isNumber(field)) {
71-
await renderCompactMarkdown(app, "" + field, container, originFile, component);
103+
await renderCompactMarkdown(app, "" + field, container, originFile, component, isInlineFieldLivePreview);
72104
} else if (Values.isLink(field)) {
73-
await renderCompactMarkdown(app, field.markdown(), container, originFile, component);
105+
await renderCompactMarkdown(app, field.markdown(), container, originFile, component, isInlineFieldLivePreview);
74106
} else if (Values.isHtml(field)) {
75107
container.appendChild(field);
76108
} else if (Values.isWidget(field)) {

src/ui/views/inline-field-live-preview.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,11 @@ class InlineFieldWidget extends WidgetType {
235235
},
236236
});
237237

238-
renderCompactMarkdown(this.app, this.field.key, key, this.sourcePath, this.component);
238+
renderCompactMarkdown(this.app, this.field.key, key, this.sourcePath, this.component, true);
239239

240240
const value = renderContainer.createSpan({
241241
cls: ["dataview", "inline-field-value"],
242242
});
243-
244243
renderValue(
245244
this.app,
246245
parseInlineValue(this.field.value),
@@ -260,7 +259,6 @@ class InlineFieldWidget extends WidgetType {
260259
const value = renderContainer.createSpan({
261260
cls: ["dataview", "inline-field-standalone-value"],
262261
});
263-
264262
renderValue(
265263
this.app,
266264
parseInlineValue(this.field.value),

0 commit comments

Comments
 (0)