Skip to content

Commit 82e46b2

Browse files
Improved rendering of embedded notes. Fixes #1443
1 parent 1999b04 commit 82e46b2

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

packages/foam-vscode/src/features/preview/wikilink-embed.ts

+9-11
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export const markdownItWikilinkEmbed = (
8585
md
8686
);
8787
refsStack.pop();
88-
return content;
88+
return refsStack.length === 0 ? md.render(content) : content;
8989
} catch (e) {
9090
Logger.error(
9191
`Error while including ${wikilinkItem} into the current document of the Preview panel`,
@@ -105,7 +105,7 @@ function getNoteContent(
105105
md: markdownit
106106
): string {
107107
let content = `Embed for [[${includedNote.uri.path}]]`;
108-
let html: string;
108+
let toRender: string;
109109

110110
switch (includedNote.type) {
111111
case 'note': {
@@ -126,7 +126,7 @@ function getNoteContent(
126126
: cardFormatter;
127127

128128
content = extractor(includedNote, parser, workspace);
129-
html = formatter(content, md);
129+
toRender = formatter(content, md);
130130
break;
131131
}
132132
case 'attachment':
@@ -135,19 +135,19 @@ function getNoteContent(
135135
${md.renderInline('[[' + includedNote.uri.path + ']]')}<br/>
136136
Embed for attachments is not supported
137137
</div>`;
138-
html = md.render(content);
138+
toRender = md.render(content);
139139
break;
140140
case 'image':
141141
content = `<div class="embed-container-image">${md.render(
142142
`![](${md.normalizeLink(includedNote.uri.path)})`
143143
)}</div>`;
144-
html = md.render(content);
144+
toRender = md.render(content);
145145
break;
146146
default:
147-
html = content;
147+
toRender = content;
148148
}
149149

150-
return html;
150+
return toRender;
151151
}
152152

153153
function withLinksRelativeToWorkspaceRoot(
@@ -271,13 +271,11 @@ function contentExtractor(
271271
export type EmbedNoteFormatter = (content: string, md: markdownit) => string;
272272

273273
function cardFormatter(content: string, md: markdownit): string {
274-
return md.render(
275-
`<div class="embed-container-note">${md.render(content)}</div>`
276-
);
274+
return `<div class="embed-container-note">\n\n${content}\n\n</div>`;
277275
}
278276

279277
function inlineFormatter(content: string, md: markdownit): string {
280-
return md.render(content);
278+
return content;
281279
}
282280

283281
export default markdownItWikilinkEmbed;

0 commit comments

Comments
 (0)