From 4e2f07accf5998cd1def93b576f6704135caf604 Mon Sep 17 00:00:00 2001
From: badsketch
Date: Fri, 18 Aug 2023 00:23:32 -0400
Subject: [PATCH 01/20] Refactor note embedding to be extensible
---
packages/foam-vscode/package.json | 16 +++
.../src/features/preview/wikilink-embed.ts | 125 +++++++++++++++---
2 files changed, 125 insertions(+), 16 deletions(-)
diff --git a/packages/foam-vscode/package.json b/packages/foam-vscode/package.json
index 4803575e6..dd91c30fd 100644
--- a/packages/foam-vscode/package.json
+++ b/packages/foam-vscode/package.json
@@ -516,6 +516,22 @@
"default": true,
"description": "Wrap embedded notes in a container when displayed in preview panel"
},
+ "foam.preview.embedStyle": {
+ "type": "string",
+ "default": "full-card",
+ "enum": [
+ "full-inline",
+ "full-card",
+ "content-inline",
+ "content-card"
+ ],
+ "enumDescriptions": [
+ "Include the section with title and style inline",
+ "Include the section with title and style it within a container",
+ "Include the section without title and style inline",
+ "Include the section without title and style it within a container"
+ ]
+ },
"foam.graph.titleMaxLength": {
"type": "number",
"default": 24,
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
index d9a82d7d4..f80d054f5 100644
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.ts
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
@@ -47,25 +47,20 @@ export const markdownItWikilinkEmbed = (
let content = `Embed for [[${wikilink}]]`;
switch (includedNote.type) {
case 'note': {
- let noteText = readFileSync(includedNote.uri.toFsPath()).toString();
- const section = Resource.findSection(
+ const noteStyle = getFoamVsCodeConfig(
+ CONFIG_EMBED_NOTE_IN_CONTAINER
+ )
+ ? 'card'
+ : 'inline';
+ const noteEmbedder = new NoteEmbedder(
includedNote,
- includedNote.uri.fragment
- );
- if (isSome(section)) {
- const rows = noteText.split('\n');
- noteText = rows
- .slice(section.range.start.line, section.range.end.line)
- .join('\n');
- }
- noteText = withLinksRelativeToWorkspaceRoot(
- noteText,
+ 'full',
+ noteStyle,
parser,
- workspace
+ workspace,
+ md
);
- content = getFoamVsCodeConfig(CONFIG_EMBED_NOTE_IN_CONTAINER)
- ? `${md.render(noteText)}
`
- : noteText;
+ content = noteEmbedder.generateEmbedding();
break;
}
case 'attachment':
@@ -123,4 +118,102 @@ function withLinksRelativeToWorkspaceRoot(
return text;
}
+interface EmbedNoteExtractor {
+ extract(note: Resource): string;
+}
+
+class FullExtractor implements EmbedNoteExtractor {
+ parser: ResourceParser;
+ workspace: FoamWorkspace;
+
+ constructor(parser: ResourceParser, workspace: FoamWorkspace) {
+ this.parser = parser;
+ this.workspace = workspace;
+ }
+
+ extract(note: Resource) {
+ let noteText = readFileSync(note.uri.toFsPath()).toString();
+ const section = Resource.findSection(note, note.uri.fragment);
+ if (isSome(section)) {
+ const rows = noteText.split('\n');
+ noteText = rows
+ .slice(section.range.start.line, section.range.end.line)
+ .join('\n');
+ }
+ noteText = withLinksRelativeToWorkspaceRoot(
+ noteText,
+ this.parser,
+ this.workspace
+ );
+ return noteText;
+ }
+}
+
+interface EmbedNoteFormatter {
+ format(content: string): string;
+}
+
+class CardFormatter implements EmbedNoteFormatter {
+ md: markdownit;
+ constructor(md: markdownit) {
+ this.md = md;
+ }
+ format(content: string) {
+ return `${this.md.render(content)}
`;
+ }
+}
+
+class InlineFormatter implements EmbedNoteFormatter {
+ format(content: string) {
+ return content;
+ }
+}
+
+class NoteEmbedder {
+ includedNote: Resource;
+ extractor: EmbedNoteExtractor;
+ formatter: EmbedNoteFormatter;
+
+ /* extractor dependencies */
+ parser: ResourceParser;
+ workspace: FoamWorkspace;
+
+ /* formatter dependencies */
+ md: markdownit;
+
+ constructor(
+ includedNote: Resource,
+ extractorType: string,
+ formatterType: string,
+ parser: ResourceParser,
+ workspace: FoamWorkspace,
+ md: markdownit
+ ) {
+ this.includedNote = includedNote;
+
+ switch (extractorType) {
+ case 'full':
+ case 'content': // TODO: IMPLEMENT
+ default:
+ this.extractor = new FullExtractor(parser, workspace);
+ break;
+ }
+
+ switch (formatterType) {
+ case 'card':
+ this.formatter = new CardFormatter(md);
+ break;
+ case 'inline':
+ default:
+ this.formatter = new InlineFormatter();
+ break;
+ }
+ }
+
+ generateEmbedding() {
+ const rawContent = this.extractor.extract(this.includedNote);
+ return this.formatter.format(rawContent);
+ }
+}
+
export default markdownItWikilinkEmbed;
From e05c1c282e59e995e8c707f8787de8157e73eb05 Mon Sep 17 00:00:00 2001
From: badsketch
Date: Sat, 19 Aug 2023 22:27:46 -0400
Subject: [PATCH 02/20] Refactor pattern to use more functional approach
---
.../src/features/preview/wikilink-embed.ts | 164 ++++++++----------
1 file changed, 70 insertions(+), 94 deletions(-)
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
index f80d054f5..87293c289 100644
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.ts
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
@@ -45,22 +45,42 @@ export const markdownItWikilinkEmbed = (
return `Cyclic link detected for wikilink: ${wikilink}
`;
}
let content = `Embed for [[${wikilink}]]`;
+ let html: string;
+
switch (includedNote.type) {
case 'note': {
- const noteStyle = getFoamVsCodeConfig(
+ let extractor = fullExtractor;
+ const noteContentType = 'full';
+ switch (noteContentType) {
+ case 'full':
+ extractor = fullExtractor;
+ break;
+ }
+
+ const noteStyleType = getFoamVsCodeConfig(
CONFIG_EMBED_NOTE_IN_CONTAINER
)
? 'card'
: 'inline';
- const noteEmbedder = new NoteEmbedder(
+
+ let formatter = cardFormatter;
+ switch (noteStyleType) {
+ case 'card':
+ formatter = cardFormatter;
+ break;
+ case 'inline':
+ formatter = inlineFormatter;
+ break;
+ }
+
+ html = generateNoteEmbedding(
includedNote,
- 'full',
- noteStyle,
parser,
workspace,
- md
+ md,
+ extractor,
+ formatter
);
- content = noteEmbedder.generateEmbedding();
break;
}
case 'attachment':
@@ -69,14 +89,15 @@ export const markdownItWikilinkEmbed = (
${md.renderInline('[[' + wikilink + ']]')}
Embed for attachments is not supported
`;
+ html = md.render(content);
break;
case 'image':
content = `${md.render(
`![](${md.normalizeLink(includedNote.uri.path)})`
)}
`;
+ html = md.render(content);
break;
}
- const html = md.render(content);
refsStack.pop();
return html;
} catch (e) {
@@ -118,102 +139,57 @@ function withLinksRelativeToWorkspaceRoot(
return text;
}
-interface EmbedNoteExtractor {
- extract(note: Resource): string;
-}
-
-class FullExtractor implements EmbedNoteExtractor {
- parser: ResourceParser;
- workspace: FoamWorkspace;
-
- constructor(parser: ResourceParser, workspace: FoamWorkspace) {
- this.parser = parser;
- this.workspace = workspace;
- }
+/**
+ * A type of function that gets the desired content of the note
+ */
+export type EmbedNoteExtractor = (
+ note: Resource,
+ parser: ResourceParser,
+ workspace: FoamWorkspace
+) => string;
- extract(note: Resource) {
- let noteText = readFileSync(note.uri.toFsPath()).toString();
- const section = Resource.findSection(note, note.uri.fragment);
- if (isSome(section)) {
- const rows = noteText.split('\n');
- noteText = rows
- .slice(section.range.start.line, section.range.end.line)
- .join('\n');
- }
- noteText = withLinksRelativeToWorkspaceRoot(
- noteText,
- this.parser,
- this.workspace
- );
- return noteText;
+function fullExtractor(
+ note: Resource,
+ parser: ResourceParser,
+ workspace: FoamWorkspace
+): string {
+ let noteText = readFileSync(note.uri.toFsPath()).toString();
+ const section = Resource.findSection(note, note.uri.fragment);
+ if (isSome(section)) {
+ const rows = noteText.split('\n');
+ noteText = rows
+ .slice(section.range.start.line, section.range.end.line)
+ .join('\n');
}
+ noteText = withLinksRelativeToWorkspaceRoot(noteText, parser, workspace);
+ return noteText;
}
-interface EmbedNoteFormatter {
- format(content: string): string;
-}
+/**
+ * A type of function that renders note content to the desired style
+ */
+export type EmbedNoteFormatter = (content: string, md: markdownit) => string;
-class CardFormatter implements EmbedNoteFormatter {
- md: markdownit;
- constructor(md: markdownit) {
- this.md = md;
- }
- format(content: string) {
- return `${this.md.render(content)}
`;
- }
+function cardFormatter(content: string, md: markdownit): string {
+ return md.render(
+ `${md.render(content)}
`
+ );
}
-class InlineFormatter implements EmbedNoteFormatter {
- format(content: string) {
- return content;
- }
+function inlineFormatter(content: string, md: markdownit): string {
+ return md.render(content);
}
-class NoteEmbedder {
- includedNote: Resource;
- extractor: EmbedNoteExtractor;
- formatter: EmbedNoteFormatter;
-
- /* extractor dependencies */
- parser: ResourceParser;
- workspace: FoamWorkspace;
-
- /* formatter dependencies */
- md: markdownit;
-
- constructor(
- includedNote: Resource,
- extractorType: string,
- formatterType: string,
- parser: ResourceParser,
- workspace: FoamWorkspace,
- md: markdownit
- ) {
- this.includedNote = includedNote;
-
- switch (extractorType) {
- case 'full':
- case 'content': // TODO: IMPLEMENT
- default:
- this.extractor = new FullExtractor(parser, workspace);
- break;
- }
-
- switch (formatterType) {
- case 'card':
- this.formatter = new CardFormatter(md);
- break;
- case 'inline':
- default:
- this.formatter = new InlineFormatter();
- break;
- }
- }
-
- generateEmbedding() {
- const rawContent = this.extractor.extract(this.includedNote);
- return this.formatter.format(rawContent);
- }
+function generateNoteEmbedding(
+ note: Resource,
+ parser: ResourceParser,
+ workspace: FoamWorkspace,
+ md: markdownit,
+ extractor: EmbedNoteExtractor,
+ formatter: EmbedNoteFormatter
+): string {
+ const rawContent = extractor(note, parser, workspace);
+ return formatter(rawContent, md);
}
export default markdownItWikilinkEmbed;
From 33e4438d8a74c33bc9b1cd98fa43914a6a4c7500 Mon Sep 17 00:00:00 2001
From: badsketch
Date: Sun, 20 Aug 2023 15:03:54 -0400
Subject: [PATCH 03/20] Simplify extractor formatter invocation
---
.../src/features/preview/wikilink-embed.ts | 28 ++++---------------
1 file changed, 5 insertions(+), 23 deletions(-)
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
index 87293c289..6c767a4d0 100644
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.ts
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
@@ -49,7 +49,7 @@ export const markdownItWikilinkEmbed = (
switch (includedNote.type) {
case 'note': {
- let extractor = fullExtractor;
+ let extractor: EmbedNoteExtractor = fullExtractor;
const noteContentType = 'full';
switch (noteContentType) {
case 'full':
@@ -63,7 +63,7 @@ export const markdownItWikilinkEmbed = (
? 'card'
: 'inline';
- let formatter = cardFormatter;
+ let formatter: EmbedNoteFormatter = cardFormatter;
switch (noteStyleType) {
case 'card':
formatter = cardFormatter;
@@ -73,14 +73,8 @@ export const markdownItWikilinkEmbed = (
break;
}
- html = generateNoteEmbedding(
- includedNote,
- parser,
- workspace,
- md,
- extractor,
- formatter
- );
+ content = extractor(includedNote, parser, workspace);
+ html = formatter(content, md);
break;
}
case 'attachment':
@@ -166,7 +160,7 @@ function fullExtractor(
}
/**
- * A type of function that renders note content to the desired style
+ * A type of function that renders note content with the desired style in html
*/
export type EmbedNoteFormatter = (content: string, md: markdownit) => string;
@@ -180,16 +174,4 @@ function inlineFormatter(content: string, md: markdownit): string {
return md.render(content);
}
-function generateNoteEmbedding(
- note: Resource,
- parser: ResourceParser,
- workspace: FoamWorkspace,
- md: markdownit,
- extractor: EmbedNoteExtractor,
- formatter: EmbedNoteFormatter
-): string {
- const rawContent = extractor(note, parser, workspace);
- return formatter(rawContent, md);
-}
-
export default markdownItWikilinkEmbed;
From e3fe40016b6aa5cc42d316fb08deff1c04717d65 Mon Sep 17 00:00:00 2001
From: badsketch
Date: Sun, 20 Aug 2023 18:02:04 -0400
Subject: [PATCH 04/20] Prepare new setting to replace
preview.embedNoteInContainer
---
packages/foam-vscode/package.json | 13 ++++-----
.../features/preview/wikilink-embed.test.ts | 28 ++++++++++++++++++
.../src/features/preview/wikilink-embed.ts | 29 +++++++++++++------
3 files changed, 53 insertions(+), 17 deletions(-)
create mode 100644 packages/foam-vscode/src/features/preview/wikilink-embed.test.ts
diff --git a/packages/foam-vscode/package.json b/packages/foam-vscode/package.json
index dd91c30fd..ce08dc970 100644
--- a/packages/foam-vscode/package.json
+++ b/packages/foam-vscode/package.json
@@ -514,22 +514,19 @@
"foam.preview.embedNoteInContainer": {
"type": "boolean",
"default": true,
- "description": "Wrap embedded notes in a container when displayed in preview panel"
+ "description": "Wrap embedded notes in a container when displayed in preview panel",
+ "deprecationMessage": "*DEPRECATED* use foam.preview.embedNoteType instead."
},
- "foam.preview.embedStyle": {
+ "foam.preview.embedNoteType": {
"type": "string",
"default": "full-card",
"enum": [
"full-inline",
- "full-card",
- "content-inline",
- "content-card"
+ "full-card"
],
"enumDescriptions": [
"Include the section with title and style inline",
- "Include the section with title and style it within a container",
- "Include the section without title and style inline",
- "Include the section without title and style it within a container"
+ "Include the section with title and style it within a container"
]
},
"foam.graph.titleMaxLength": {
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.test.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.test.ts
new file mode 100644
index 000000000..11a559219
--- /dev/null
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.test.ts
@@ -0,0 +1,28 @@
+import { retrieveNoteConfig } from './wikilink-embed';
+import * as config from '../../services/config';
+
+describe('Wikilink Note Embedding', () => {
+ describe('Config Parsing', () => {
+ it('should use preview.embedType if deprecated preview.embedNoteInContainer not used', () => {
+ jest
+ .spyOn(config, 'getFoamVsCodeConfig')
+ .mockReturnValueOnce('full-card')
+ .mockReturnValueOnce(false);
+
+ const { noteScope, noteStyle } = retrieveNoteConfig();
+ expect(noteScope).toEqual('full');
+ expect(noteStyle).toEqual('card');
+ });
+
+ it('should use preview.embedNoteInContainer if set', () => {
+ jest
+ .spyOn(config, 'getFoamVsCodeConfig')
+ .mockReturnValueOnce('full-inline')
+ .mockReturnValueOnce(true);
+
+ const { noteScope, noteStyle } = retrieveNoteConfig();
+ expect(noteScope).toEqual('full');
+ expect(noteStyle).toEqual('card');
+ });
+ });
+});
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
index 6c767a4d0..b91b9d69a 100644
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.ts
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
@@ -15,6 +15,7 @@ import { Position } from '../../core/model/position';
import { TextEdit } from '../../core/services/text-edit';
export const CONFIG_EMBED_NOTE_IN_CONTAINER = 'preview.embedNoteInContainer';
+export const CONFIG_EMBED_STYLE = 'preview.embedNoteType';
const refsStack: string[] = [];
export const markdownItWikilinkEmbed = (
@@ -49,22 +50,17 @@ export const markdownItWikilinkEmbed = (
switch (includedNote.type) {
case 'note': {
+ let { noteScope, noteStyle } = retrieveNoteConfig();
+
let extractor: EmbedNoteExtractor = fullExtractor;
- const noteContentType = 'full';
- switch (noteContentType) {
+ switch (noteScope) {
case 'full':
extractor = fullExtractor;
break;
}
- const noteStyleType = getFoamVsCodeConfig(
- CONFIG_EMBED_NOTE_IN_CONTAINER
- )
- ? 'card'
- : 'inline';
-
let formatter: EmbedNoteFormatter = cardFormatter;
- switch (noteStyleType) {
+ switch (noteStyle) {
case 'card':
formatter = cardFormatter;
break;
@@ -133,6 +129,21 @@ function withLinksRelativeToWorkspaceRoot(
return text;
}
+export function retrieveNoteConfig(): {
+ noteScope: string;
+ noteStyle: string;
+} {
+ let config = getFoamVsCodeConfig(CONFIG_EMBED_STYLE); // ex. full-inline
+ let [noteScope, noteStyle] = config.split('-');
+
+ // **DEPRECATED** setting to be removed
+ // for now it overrides the above to preserve user settings if they have it set
+ if (getFoamVsCodeConfig(CONFIG_EMBED_NOTE_IN_CONTAINER, false)) {
+ noteStyle = 'card';
+ }
+ return { noteScope, noteStyle };
+}
+
/**
* A type of function that gets the desired content of the note
*/
From 3b1c903cee0304338234976b2064d80a822f297b Mon Sep 17 00:00:00 2001
From: badsketch
Date: Sun, 20 Aug 2023 18:28:19 -0400
Subject: [PATCH 05/20] Fix wikilink-embed e2e tests
---
.../features/preview/wikilink-embed.spec.ts | 18 +++++++++---------
.../features/preview/wikilink-embed.test.ts | 2 +-
.../src/features/preview/wikilink-embed.ts | 4 ++--
3 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
index 2248bd780..3e7db09b1 100644
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
@@ -8,7 +8,7 @@ import {
} from '../../test/test-utils-vscode';
import {
default as markdownItWikilinkEmbed,
- CONFIG_EMBED_NOTE_IN_CONTAINER,
+ CONFIG_EMBED_NOTE_TYPE,
} from './wikilink-embed';
const parser = createMarkdownParser();
@@ -21,8 +21,8 @@ describe('Displaying included notes in preview', () => {
]);
const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));
await withModifiedFoamConfiguration(
- CONFIG_EMBED_NOTE_IN_CONTAINER,
- false,
+ CONFIG_EMBED_NOTE_TYPE,
+ 'full-inline',
() => {
const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
@@ -48,8 +48,8 @@ describe('Displaying included notes in preview', () => {
const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));
await await withModifiedFoamConfiguration(
- CONFIG_EMBED_NOTE_IN_CONTAINER,
- true,
+ CONFIG_EMBED_NOTE_TYPE,
+ 'full-container',
() => {
const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
@@ -83,8 +83,8 @@ This is the third section of note E
const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
await withModifiedFoamConfiguration(
- CONFIG_EMBED_NOTE_IN_CONTAINER,
- false,
+ CONFIG_EMBED_NOTE_TYPE,
+ 'full-inline',
() => {
expect(
md.render(`This is the root node.
@@ -120,8 +120,8 @@ This is the third section of note E
const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));
await withModifiedFoamConfiguration(
- CONFIG_EMBED_NOTE_IN_CONTAINER,
- true,
+ CONFIG_EMBED_NOTE_TYPE,
+ 'full-container',
() => {
const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.test.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.test.ts
index 11a559219..c5775705b 100644
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.test.ts
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.test.ts
@@ -3,7 +3,7 @@ import * as config from '../../services/config';
describe('Wikilink Note Embedding', () => {
describe('Config Parsing', () => {
- it('should use preview.embedType if deprecated preview.embedNoteInContainer not used', () => {
+ it('should use preview.embedNoteType if deprecated preview.embedNoteInContainer not used', () => {
jest
.spyOn(config, 'getFoamVsCodeConfig')
.mockReturnValueOnce('full-card')
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
index b91b9d69a..80da49142 100644
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.ts
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
@@ -15,7 +15,7 @@ import { Position } from '../../core/model/position';
import { TextEdit } from '../../core/services/text-edit';
export const CONFIG_EMBED_NOTE_IN_CONTAINER = 'preview.embedNoteInContainer';
-export const CONFIG_EMBED_STYLE = 'preview.embedNoteType';
+export const CONFIG_EMBED_NOTE_TYPE = 'preview.embedNoteType';
const refsStack: string[] = [];
export const markdownItWikilinkEmbed = (
@@ -133,7 +133,7 @@ export function retrieveNoteConfig(): {
noteScope: string;
noteStyle: string;
} {
- let config = getFoamVsCodeConfig(CONFIG_EMBED_STYLE); // ex. full-inline
+ let config = getFoamVsCodeConfig(CONFIG_EMBED_NOTE_TYPE); // ex. full-inline
let [noteScope, noteStyle] = config.split('-');
// **DEPRECATED** setting to be removed
From 7d97e782ce554c809461a9a6d6ac3799aa80e73d Mon Sep 17 00:00:00 2001
From: badsketch
Date: Mon, 21 Aug 2023 22:56:40 -0400
Subject: [PATCH 06/20] Improve readability
---
.../src/features/preview/wikilink-embed.ts | 28 +++++++------------
1 file changed, 10 insertions(+), 18 deletions(-)
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
index 80da49142..a25232e6e 100644
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.ts
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
@@ -50,24 +50,16 @@ export const markdownItWikilinkEmbed = (
switch (includedNote.type) {
case 'note': {
- let { noteScope, noteStyle } = retrieveNoteConfig();
-
- let extractor: EmbedNoteExtractor = fullExtractor;
- switch (noteScope) {
- case 'full':
- extractor = fullExtractor;
- break;
- }
-
- let formatter: EmbedNoteFormatter = cardFormatter;
- switch (noteStyle) {
- case 'card':
- formatter = cardFormatter;
- break;
- case 'inline':
- formatter = inlineFormatter;
- break;
- }
+ const { noteScope: _, noteStyle } = retrieveNoteConfig();
+
+ const extractor: EmbedNoteExtractor = fullExtractor;
+
+ const formatter: EmbedNoteFormatter =
+ noteStyle === 'card'
+ ? cardFormatter
+ : noteStyle === 'inline'
+ ? inlineFormatter
+ : cardFormatter;
content = extractor(includedNote, parser, workspace);
html = formatter(content, md);
From 2598689609e070298ba454679f834869e315be8a Mon Sep 17 00:00:00 2001
From: badsketch
Date: Mon, 21 Aug 2023 23:02:48 -0400
Subject: [PATCH 07/20] Try to fix wikilink-embed e2e tests by returning md
content instead of html content
---
.../src/features/preview/wikilink-embed.ts | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
index a25232e6e..cad65698f 100644
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.ts
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
@@ -61,8 +61,8 @@ export const markdownItWikilinkEmbed = (
? inlineFormatter
: cardFormatter;
- content = extractor(includedNote, parser, workspace);
- html = formatter(content, md);
+ const rawContent = extractor(includedNote, parser, workspace);
+ content = formatter(rawContent, md);
break;
}
case 'attachment':
@@ -71,15 +71,14 @@ export const markdownItWikilinkEmbed = (
${md.renderInline('[[' + wikilink + ']]')}
Embed for attachments is not supported
`;
- html = md.render(content);
break;
case 'image':
content = `${md.render(
`![](${md.normalizeLink(includedNote.uri.path)})`
)}
`;
- html = md.render(content);
break;
}
+ html = md.render(content);
refsStack.pop();
return html;
} catch (e) {
@@ -168,13 +167,11 @@ function fullExtractor(
export type EmbedNoteFormatter = (content: string, md: markdownit) => string;
function cardFormatter(content: string, md: markdownit): string {
- return md.render(
- `${md.render(content)}
`
- );
+ return `${md.render(content)}
`;
}
function inlineFormatter(content: string, md: markdownit): string {
- return md.render(content);
+ return content;
}
export default markdownItWikilinkEmbed;
From 35536c5b1f5d20d807a13f6056dc21a9b2968a6b Mon Sep 17 00:00:00 2001
From: badsketch
Date: Tue, 22 Aug 2023 00:42:05 -0400
Subject: [PATCH 08/20] Revert "Try to fix wikilink-embed e2e tests by
returning md content instead of html content"
This reverts commit 2598689609e070298ba454679f834869e315be8a.
---
.../src/features/preview/wikilink-embed.ts | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
index cad65698f..a25232e6e 100644
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.ts
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
@@ -61,8 +61,8 @@ export const markdownItWikilinkEmbed = (
? inlineFormatter
: cardFormatter;
- const rawContent = extractor(includedNote, parser, workspace);
- content = formatter(rawContent, md);
+ content = extractor(includedNote, parser, workspace);
+ html = formatter(content, md);
break;
}
case 'attachment':
@@ -71,14 +71,15 @@ export const markdownItWikilinkEmbed = (
${md.renderInline('[[' + wikilink + ']]')}
Embed for attachments is not supported
`;
+ html = md.render(content);
break;
case 'image':
content = `${md.render(
`![](${md.normalizeLink(includedNote.uri.path)})`
)}
`;
+ html = md.render(content);
break;
}
- html = md.render(content);
refsStack.pop();
return html;
} catch (e) {
@@ -167,11 +168,13 @@ function fullExtractor(
export type EmbedNoteFormatter = (content: string, md: markdownit) => string;
function cardFormatter(content: string, md: markdownit): string {
- return `${md.render(content)}
`;
+ return md.render(
+ `${md.render(content)}
`
+ );
}
function inlineFormatter(content: string, md: markdownit): string {
- return content;
+ return md.render(content);
}
export default markdownItWikilinkEmbed;
From c1eaded7bcecd66f8853adfacfa6cbe9e473ade3 Mon Sep 17 00:00:00 2001
From: badsketch
Date: Tue, 22 Aug 2023 00:44:35 -0400
Subject: [PATCH 09/20] Try to fix wikilink-embed e2e tests by resetting mocks
in unit tests
---
.../foam-vscode/src/features/preview/wikilink-embed.test.ts | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.test.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.test.ts
index c5775705b..56fbcb201 100644
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.test.ts
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.test.ts
@@ -2,6 +2,10 @@ import { retrieveNoteConfig } from './wikilink-embed';
import * as config from '../../services/config';
describe('Wikilink Note Embedding', () => {
+ afterEach(() => {
+ jest.clearAllMocks();
+ });
+
describe('Config Parsing', () => {
it('should use preview.embedNoteType if deprecated preview.embedNoteInContainer not used', () => {
jest
From f86dc7e14413c49e4ac7f86bf06269f7288f5c6f Mon Sep 17 00:00:00 2001
From: badsketch
Date: Tue, 22 Aug 2023 00:47:22 -0400
Subject: [PATCH 10/20] Try to fix wikilink-embed e2e tests by deleting unit
test
---
.../features/preview/wikilink-embed.test.ts | 32 -------------------
1 file changed, 32 deletions(-)
delete mode 100644 packages/foam-vscode/src/features/preview/wikilink-embed.test.ts
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.test.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.test.ts
deleted file mode 100644
index 56fbcb201..000000000
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.test.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-import { retrieveNoteConfig } from './wikilink-embed';
-import * as config from '../../services/config';
-
-describe('Wikilink Note Embedding', () => {
- afterEach(() => {
- jest.clearAllMocks();
- });
-
- describe('Config Parsing', () => {
- it('should use preview.embedNoteType if deprecated preview.embedNoteInContainer not used', () => {
- jest
- .spyOn(config, 'getFoamVsCodeConfig')
- .mockReturnValueOnce('full-card')
- .mockReturnValueOnce(false);
-
- const { noteScope, noteStyle } = retrieveNoteConfig();
- expect(noteScope).toEqual('full');
- expect(noteStyle).toEqual('card');
- });
-
- it('should use preview.embedNoteInContainer if set', () => {
- jest
- .spyOn(config, 'getFoamVsCodeConfig')
- .mockReturnValueOnce('full-inline')
- .mockReturnValueOnce(true);
-
- const { noteScope, noteStyle } = retrieveNoteConfig();
- expect(noteScope).toEqual('full');
- expect(noteStyle).toEqual('card');
- });
- });
-});
From 7caac918c9412c06beaabf803d024a98aa5acbaa Mon Sep 17 00:00:00 2001
From: badsketch
Date: Tue, 22 Aug 2023 01:01:10 -0400
Subject: [PATCH 11/20] Try to fix wikilink-embed e2e tests by removing extra
await
---
.../foam-vscode/src/features/preview/wikilink-embed.spec.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
index 3e7db09b1..e08268239 100644
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
@@ -47,7 +47,7 @@ describe('Displaying included notes in preview', () => {
]);
const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));
- await await withModifiedFoamConfiguration(
+ await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_TYPE,
'full-container',
() => {
From 17baa5c9e4294cdea6d2cf6a2e3ed75e0e686f96 Mon Sep 17 00:00:00 2001
From: badsketch
Date: Tue, 22 Aug 2023 01:06:45 -0400
Subject: [PATCH 12/20] Try to fix wikilink-embed e2e tests by deleting the e2e
tests to check if there's a caching issue
---
.../features/preview/wikilink-embed.spec.ts | 175 ------------------
1 file changed, 175 deletions(-)
delete mode 100644 packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
deleted file mode 100644
index e08268239..000000000
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
+++ /dev/null
@@ -1,175 +0,0 @@
-import MarkdownIt from 'markdown-it';
-import { FoamWorkspace } from '../../core/model/workspace';
-import { createMarkdownParser } from '../../core/services/markdown-parser';
-import {
- createFile,
- deleteFile,
- withModifiedFoamConfiguration,
-} from '../../test/test-utils-vscode';
-import {
- default as markdownItWikilinkEmbed,
- CONFIG_EMBED_NOTE_TYPE,
-} from './wikilink-embed';
-
-const parser = createMarkdownParser();
-
-describe('Displaying included notes in preview', () => {
- it('should render an included note in flat mode', async () => {
- const note = await createFile('This is the text of note A', [
- 'preview',
- 'note-a.md',
- ]);
- const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));
- await withModifiedFoamConfiguration(
- CONFIG_EMBED_NOTE_TYPE,
- 'full-inline',
- () => {
- const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
-
- expect(
- md.render(`This is the root node.
-
- ![[note-a]]`)
- ).toMatch(
- `This is the root node.
-This is the text of note A
-
`
- );
- }
- );
- await deleteFile(note);
- });
-
- it('should render an included note in container mode', async () => {
- const note = await createFile('This is the text of note A', [
- 'preview',
- 'note-a.md',
- ]);
- const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));
-
- await withModifiedFoamConfiguration(
- CONFIG_EMBED_NOTE_TYPE,
- 'full-container',
- () => {
- const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
-
- const res = md.render(`This is the root node. ![[note-a]]`);
- expect(res).toContain('This is the root node');
- expect(res).toContain('embed-container-note');
- expect(res).toContain('This is the text of note A');
- }
- );
- await deleteFile(note);
- });
-
- it('should render an included section', async () => {
- // here we use createFile as the test note doesn't fill in
- // all the metadata we need
- const note = await createFile(
- `
-# Section 1
-This is the first section of note E
-
-# Section 2
-This is the second section of note E
-
-# Section 3
-This is the third section of note E
- `,
- ['note-e.md']
- );
- const parser = createMarkdownParser([]);
- const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));
- const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
-
- await withModifiedFoamConfiguration(
- CONFIG_EMBED_NOTE_TYPE,
- 'full-inline',
- () => {
- expect(
- md.render(`This is the root node.
-
- ![[note-e#Section 2]]`)
- ).toMatch(
- `This is the root node.
-Section 2
-This is the second section of note E
-`
- );
- }
- );
-
- await deleteFile(note);
- });
-
- it('should render an included section in container mode', async () => {
- const note = await createFile(
- `
-# Section 1
-This is the first section of note E
-
-# Section 2
-This is the second section of note E
-
-# Section 3
-This is the third section of note E
- `,
- ['note-e-container.md']
- );
- const parser = createMarkdownParser([]);
- const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));
-
- await withModifiedFoamConfiguration(
- CONFIG_EMBED_NOTE_TYPE,
- 'full-container',
- () => {
- const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
-
- const res = md.render(
- `This is the root node. ![[note-e-container#Section 3]]`
- );
- expect(res).toContain('This is the root node');
- expect(res).toContain('embed-container-note');
- expect(res).toContain('Section 3');
- expect(res).toContain('This is the third section of note E');
- }
- );
-
- await deleteFile(note);
- });
-
- it('should fallback to the bare text when the note is not found', () => {
- const md = markdownItWikilinkEmbed(
- MarkdownIt(),
- new FoamWorkspace(),
- parser
- );
-
- expect(md.render(`This is the root node. ![[non-existing-note]]`)).toMatch(
- `This is the root node. ![[non-existing-note]]
`
- );
- });
-
- it('should display a warning in case of cyclical inclusions', async () => {
- const noteA = await createFile(
- 'This is the text of note A which includes ![[note-b]]',
- ['preview', 'note-a.md']
- );
-
- const noteBText = 'This is the text of note B which includes ![[note-a]]';
- const noteB = await createFile(noteBText, ['preview', 'note-b.md']);
-
- const ws = new FoamWorkspace()
- .set(parser.parse(noteA.uri, noteA.content))
- .set(parser.parse(noteB.uri, noteB.content));
- const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
- const res = md.render(noteBText);
-
- expect(res).toContain('This is the text of note B which includes');
- expect(res).toContain('This is the text of note A which includes');
- expect(res).toContain('Cyclic link detected for wikilink');
-
- deleteFile(noteA);
- deleteFile(noteB);
- });
-});
From f4e8575735bf35d69d7be083ea967decedf01c4d Mon Sep 17 00:00:00 2001
From: badsketch
Date: Tue, 22 Aug 2023 01:10:38 -0400
Subject: [PATCH 13/20] Try to fix wikilink-embed e2e tests by recreating the
e2e tests to check if there's a caching issue
---
.../features/preview/wikilink-embed.spec.ts | 170 ++++++++++++++++++
1 file changed, 170 insertions(+)
create mode 100644 packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
new file mode 100644
index 000000000..f3a9c119d
--- /dev/null
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
@@ -0,0 +1,170 @@
+import MarkdownIt from 'markdown-it';
+import { FoamWorkspace } from '../../core/model/workspace';
+import { createMarkdownParser } from '../../core/services/markdown-parser';
+import {
+ createFile,
+ deleteFile,
+ withModifiedFoamConfiguration,
+} from '../../test/test-utils-vscode';
+import {
+ default as markdownItWikilinkEmbed,
+ CONFIG_EMBED_NOTE_TYPE,
+} from './wikilink-embed';
+
+const parser = createMarkdownParser();
+
+describe('Displaying included notes in preview', () => {
+ it('should render an included note in flat mode', async () => {
+ const note = await createFile('This is the text of note A', [
+ 'preview',
+ 'note-a.md',
+ ]);
+ const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));
+ await withModifiedFoamConfiguration(
+ CONFIG_EMBED_NOTE_TYPE,
+ 'full-inline',
+ () => {
+ const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
+
+ expect(
+ md.render(`This is the root node.
+
+ ![[note-a]]`)
+ ).toMatch(
+ `This is the root node.
+This is the text of note A
+`
+ );
+ }
+ );
+ await deleteFile(note);
+ });
+
+ it('should render an included note in container mode', async () => {
+ const note = await createFile('This is the text of note A', [
+ 'preview',
+ 'note-a.md',
+ ]);
+ const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));
+
+ await withModifiedFoamConfiguration(
+ CONFIG_EMBED_NOTE_TYPE,
+ 'full-container',
+ () => {
+ const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
+
+ const res = md.render(`This is the root node. ![[note-a]]`);
+ expect(res).toContain('This is the root node');
+ expect(res).toContain('embed-container-note');
+ expect(res).toContain('This is the text of note A');
+ }
+ );
+ await deleteFile(note);
+ });
+
+ it('should render an included section', async () => {
+ // here we use createFile as the test note doesn't fill in
+ // all the metadata we need
+ const note = await createFile(
+ `
+# Section 1
+This is the first section of note E
+# Section 2
+This is the second section of note E
+# Section 3
+This is the third section of note E
+ `,
+ ['note-e.md']
+ );
+ const parser = createMarkdownParser([]);
+ const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));
+ const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
+
+ await withModifiedFoamConfiguration(
+ CONFIG_EMBED_NOTE_TYPE,
+ 'full-inline',
+ () => {
+ expect(
+ md.render(`This is the root node.
+ ![[note-e#Section 2]]`)
+ ).toMatch(
+ `This is the root node.
+Section 2
+This is the second section of note E
+`
+ );
+ }
+ );
+
+ await deleteFile(note);
+ });
+
+ it('should render an included section in container mode', async () => {
+ const note = await createFile(
+ `
+# Section 1
+This is the first section of note E
+# Section 2
+This is the second section of note E
+# Section 3
+This is the third section of note E
+ `,
+ ['note-e-container.md']
+ );
+ const parser = createMarkdownParser([]);
+ const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));
+
+ await withModifiedFoamConfiguration(
+ CONFIG_EMBED_NOTE_TYPE,
+ 'full-container',
+ () => {
+ const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
+
+ const res = md.render(
+ `This is the root node. ![[note-e-container#Section 3]]`
+ );
+ expect(res).toContain('This is the root node');
+ expect(res).toContain('embed-container-note');
+ expect(res).toContain('Section 3');
+ expect(res).toContain('This is the third section of note E');
+ }
+ );
+
+ await deleteFile(note);
+ });
+
+ it('should fallback to the bare text when the note is not found', () => {
+ const md = markdownItWikilinkEmbed(
+ MarkdownIt(),
+ new FoamWorkspace(),
+ parser
+ );
+
+ expect(md.render(`This is the root node. ![[non-existing-note]]`)).toMatch(
+ `This is the root node. ![[non-existing-note]]
`
+ );
+ });
+
+ it('should display a warning in case of cyclical inclusions', async () => {
+ const noteA = await createFile(
+ 'This is the text of note A which includes ![[note-b]]',
+ ['preview', 'note-a.md']
+ );
+
+ const noteBText = 'This is the text of note B which includes ![[note-a]]';
+ const noteB = await createFile(noteBText, ['preview', 'note-b.md']);
+
+ const ws = new FoamWorkspace()
+ .set(parser.parse(noteA.uri, noteA.content))
+ .set(parser.parse(noteB.uri, noteB.content));
+ const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
+ const res = md.render(noteBText);
+
+ expect(res).toContain('This is the text of note B which includes');
+ expect(res).toContain('This is the text of note A which includes');
+ expect(res).toContain('Cyclic link detected for wikilink');
+
+ deleteFile(noteA);
+ deleteFile(noteB);
+ });
+});
From 2f5fe5ef5ec20081f9f1ece76deda8b2b836d556 Mon Sep 17 00:00:00 2001
From: badsketch
Date: Tue, 22 Aug 2023 03:12:25 -0400
Subject: [PATCH 14/20] Try to fix wikilink-embed e2e tests by restoring
deleted spacing
---
.../foam-vscode/src/features/preview/wikilink-embed.spec.ts | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
index f3a9c119d..e08268239 100644
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
@@ -69,8 +69,10 @@ describe('Displaying included notes in preview', () => {
`
# Section 1
This is the first section of note E
+
# Section 2
This is the second section of note E
+
# Section 3
This is the third section of note E
`,
@@ -86,6 +88,7 @@ This is the third section of note E
() => {
expect(
md.render(`This is the root node.
+
![[note-e#Section 2]]`)
).toMatch(
`This is the root node.
@@ -104,8 +107,10 @@ This is the third section of note E
`
# Section 1
This is the first section of note E
+
# Section 2
This is the second section of note E
+
# Section 3
This is the third section of note E
`,
From 4f773f93c728351c8d5dcb9b0698d65843c20f0a Mon Sep 17 00:00:00 2001
From: badsketch
Date: Tue, 22 Aug 2023 22:38:29 -0400
Subject: [PATCH 15/20] Try to fix wikilink-embed e2e tests by removing
embedNoteInContainer config
---
packages/foam-vscode/src/features/preview/wikilink-embed.ts | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
index a25232e6e..62ce3c918 100644
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.ts
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
@@ -130,9 +130,9 @@ export function retrieveNoteConfig(): {
// **DEPRECATED** setting to be removed
// for now it overrides the above to preserve user settings if they have it set
- if (getFoamVsCodeConfig(CONFIG_EMBED_NOTE_IN_CONTAINER, false)) {
- noteStyle = 'card';
- }
+ // if (getFoamVsCodeConfig(CONFIG_EMBED_NOTE_IN_CONTAINER, false)) {
+ // noteStyle = 'card';
+ // }
return { noteScope, noteStyle };
}
From 24a6b598961e3bf9f47d1e9d1ad8d4456bd41a9b Mon Sep 17 00:00:00 2001
From: badsketch
Date: Tue, 22 Aug 2023 23:02:04 -0400
Subject: [PATCH 16/20] Revert "Try to fix wikilink-embed e2e tests by removing
embedNoteInContainer config"
This reverts commit 4f773f93c728351c8d5dcb9b0698d65843c20f0a.
---
packages/foam-vscode/src/features/preview/wikilink-embed.ts | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
index 62ce3c918..a25232e6e 100644
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.ts
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.ts
@@ -130,9 +130,9 @@ export function retrieveNoteConfig(): {
// **DEPRECATED** setting to be removed
// for now it overrides the above to preserve user settings if they have it set
- // if (getFoamVsCodeConfig(CONFIG_EMBED_NOTE_IN_CONTAINER, false)) {
- // noteStyle = 'card';
- // }
+ if (getFoamVsCodeConfig(CONFIG_EMBED_NOTE_IN_CONTAINER, false)) {
+ noteStyle = 'card';
+ }
return { noteScope, noteStyle };
}
From 4190c438a1378b89e059f393ab9a27a9483b0845 Mon Sep 17 00:00:00 2001
From: badsketch
Date: Tue, 22 Aug 2023 23:02:32 -0400
Subject: [PATCH 17/20] Try to fix wikilink-embed e2e tests by fixing the name
of the config in the tests
---
.../foam-vscode/src/features/preview/wikilink-embed.spec.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
index e08268239..e1c79979a 100644
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
@@ -49,7 +49,7 @@ describe('Displaying included notes in preview', () => {
await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_TYPE,
- 'full-container',
+ 'full-card',
() => {
const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
@@ -121,7 +121,7 @@ This is the third section of note E
await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_TYPE,
- 'full-container',
+ 'full-card',
() => {
const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
From 090d941a6d0a76a73498bd009dde0c87eec52308 Mon Sep 17 00:00:00 2001
From: badsketch
Date: Tue, 22 Aug 2023 23:36:13 -0400
Subject: [PATCH 18/20] Try to fix wikilink-embed e2e tests by initializing
embedNoteInContainer in the tests
---
.../features/preview/wikilink-embed.spec.ts | 97 ++++++++++++-------
1 file changed, 61 insertions(+), 36 deletions(-)
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
index e1c79979a..c2ecfe0f1 100644
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
@@ -9,6 +9,7 @@ import {
import {
default as markdownItWikilinkEmbed,
CONFIG_EMBED_NOTE_TYPE,
+ CONFIG_EMBED_NOTE_IN_CONTAINER,
} from './wikilink-embed';
const parser = createMarkdownParser();
@@ -21,19 +22,25 @@ describe('Displaying included notes in preview', () => {
]);
const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));
await withModifiedFoamConfiguration(
- CONFIG_EMBED_NOTE_TYPE,
- 'full-inline',
- () => {
- const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
-
- expect(
- md.render(`This is the root node.
+ CONFIG_EMBED_NOTE_IN_CONTAINER,
+ false,
+ async () => {
+ await withModifiedFoamConfiguration(
+ CONFIG_EMBED_NOTE_TYPE,
+ 'full-inline',
+ () => {
+ const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
+
+ expect(
+ md.render(`This is the root node.
![[note-a]]`)
- ).toMatch(
- `This is the root node.
+ ).toMatch(
+ `This is the root node.
This is the text of note A
`
+ );
+ }
);
}
);
@@ -48,15 +55,21 @@ describe('Displaying included notes in preview', () => {
const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));
await withModifiedFoamConfiguration(
- CONFIG_EMBED_NOTE_TYPE,
- 'full-card',
- () => {
- const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
-
- const res = md.render(`This is the root node. ![[note-a]]`);
- expect(res).toContain('This is the root node');
- expect(res).toContain('embed-container-note');
- expect(res).toContain('This is the text of note A');
+ CONFIG_EMBED_NOTE_IN_CONTAINER,
+ false,
+ async () => {
+ await withModifiedFoamConfiguration(
+ CONFIG_EMBED_NOTE_TYPE,
+ 'full-card',
+ () => {
+ const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
+
+ const res = md.render(`This is the root node. ![[note-a]]`);
+ expect(res).toContain('This is the root node');
+ expect(res).toContain('embed-container-note');
+ expect(res).toContain('This is the text of note A');
+ }
+ );
}
);
await deleteFile(note);
@@ -83,18 +96,24 @@ This is the third section of note E
const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
await withModifiedFoamConfiguration(
- CONFIG_EMBED_NOTE_TYPE,
- 'full-inline',
- () => {
- expect(
- md.render(`This is the root node.
+ CONFIG_EMBED_NOTE_IN_CONTAINER,
+ false,
+ async () => {
+ await withModifiedFoamConfiguration(
+ CONFIG_EMBED_NOTE_TYPE,
+ 'full-inline',
+ () => {
+ expect(
+ md.render(`This is the root node.
![[note-e#Section 2]]`)
- ).toMatch(
- `This is the root node.
+ ).toMatch(
+ `This is the root node.
Section 2
This is the second section of note E
`
+ );
+ }
);
}
);
@@ -120,18 +139,24 @@ This is the third section of note E
const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));
await withModifiedFoamConfiguration(
- CONFIG_EMBED_NOTE_TYPE,
- 'full-card',
- () => {
- const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
-
- const res = md.render(
- `This is the root node. ![[note-e-container#Section 3]]`
+ CONFIG_EMBED_NOTE_IN_CONTAINER,
+ false,
+ async () => {
+ await withModifiedFoamConfiguration(
+ CONFIG_EMBED_NOTE_TYPE,
+ 'full-card',
+ () => {
+ const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);
+
+ const res = md.render(
+ `This is the root node. ![[note-e-container#Section 3]]`
+ );
+ expect(res).toContain('This is the root node');
+ expect(res).toContain('embed-container-note');
+ expect(res).toContain('Section 3');
+ expect(res).toContain('This is the third section of note E');
+ }
);
- expect(res).toContain('This is the root node');
- expect(res).toContain('embed-container-note');
- expect(res).toContain('Section 3');
- expect(res).toContain('This is the third section of note E');
}
);
From 7b9c95d2abcb09b9d78e8f6d407cdd5377ab1534 Mon Sep 17 00:00:00 2001
From: badsketch
Date: Tue, 22 Aug 2023 23:46:20 -0400
Subject: [PATCH 19/20] Revert "Try to fix wikilink-embed e2e tests by deleting
unit test"
This reverts commit f86dc7e14413c49e4ac7f86bf06269f7288f5c6f.
---
.../features/preview/wikilink-embed.test.ts | 32 +++++++++++++++++++
1 file changed, 32 insertions(+)
create mode 100644 packages/foam-vscode/src/features/preview/wikilink-embed.test.ts
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.test.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.test.ts
new file mode 100644
index 000000000..56fbcb201
--- /dev/null
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.test.ts
@@ -0,0 +1,32 @@
+import { retrieveNoteConfig } from './wikilink-embed';
+import * as config from '../../services/config';
+
+describe('Wikilink Note Embedding', () => {
+ afterEach(() => {
+ jest.clearAllMocks();
+ });
+
+ describe('Config Parsing', () => {
+ it('should use preview.embedNoteType if deprecated preview.embedNoteInContainer not used', () => {
+ jest
+ .spyOn(config, 'getFoamVsCodeConfig')
+ .mockReturnValueOnce('full-card')
+ .mockReturnValueOnce(false);
+
+ const { noteScope, noteStyle } = retrieveNoteConfig();
+ expect(noteScope).toEqual('full');
+ expect(noteStyle).toEqual('card');
+ });
+
+ it('should use preview.embedNoteInContainer if set', () => {
+ jest
+ .spyOn(config, 'getFoamVsCodeConfig')
+ .mockReturnValueOnce('full-inline')
+ .mockReturnValueOnce(true);
+
+ const { noteScope, noteStyle } = retrieveNoteConfig();
+ expect(noteScope).toEqual('full');
+ expect(noteStyle).toEqual('card');
+ });
+ });
+});
From 7365f5d8e50a53d5da148b037a96e8c704c49ff7 Mon Sep 17 00:00:00 2001
From: badsketch
Date: Tue, 22 Aug 2023 23:58:55 -0400
Subject: [PATCH 20/20] Set embedNoteInContainer to null in e2e tests to more
closely mimic live state
---
.../src/features/preview/wikilink-embed.spec.ts | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
index c2ecfe0f1..948ec1cad 100644
--- a/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
+++ b/packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
@@ -23,7 +23,7 @@ describe('Displaying included notes in preview', () => {
const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));
await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_IN_CONTAINER,
- false,
+ null,
async () => {
await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_TYPE,
@@ -56,7 +56,7 @@ describe('Displaying included notes in preview', () => {
await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_IN_CONTAINER,
- false,
+ null,
async () => {
await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_TYPE,
@@ -97,7 +97,7 @@ This is the third section of note E
await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_IN_CONTAINER,
- false,
+ null,
async () => {
await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_TYPE,
@@ -140,7 +140,7 @@ This is the third section of note E
await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_IN_CONTAINER,
- false,
+ null,
async () => {
await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_TYPE,