Skip to content

Commit

Permalink
Add logic for explicit modifier and remove deprecated preview.embedNo…
Browse files Browse the repository at this point in the history
…teInContainer
  • Loading branch information
badsketch committed Sep 1, 2023
1 parent df4efc5 commit a9b9417
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 159 deletions.
6 changes: 0 additions & 6 deletions packages/foam-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -609,12 +609,6 @@
],
"description": "Whether or not to navigate to the target daily note when a daily note snippet is selected."
},
"foam.preview.embedNoteInContainer": {
"type": "boolean",
"default": true,
"description": "Wrap embedded notes in a container when displayed in preview panel",
"deprecationMessage": "*DEPRECATED* use foam.preview.embedNoteType instead."
},
"foam.preview.embedNoteType": {
"type": "string",
"default": "full-card",
Expand Down
223 changes: 84 additions & 139 deletions packages/foam-vscode/src/features/preview/wikilink-embed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import {
default as markdownItWikilinkEmbed,
CONFIG_EMBED_NOTE_TYPE,
CONFIG_EMBED_NOTE_IN_CONTAINER,
} from './wikilink-embed';

const parser = createMarkdownParser();
Expand All @@ -22,25 +21,19 @@ describe('Displaying included notes in preview', () => {
]);
const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));
await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_IN_CONTAINER,
null,
async () => {
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_TYPE,
'full-inline',
() => {
const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);

expect(
md.render(`This is the root node.
![[note-a]]`)
).toMatch(
`<p>This is the root node.</p>
).toMatch(
`<p>This is the root node.</p>
<p><p>This is the text of note A</p>
</p>`
);
}
);
}
);
Expand All @@ -55,21 +48,15 @@ describe('Displaying included notes in preview', () => {
const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));

await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_IN_CONTAINER,
null,
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');
}
);
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);
Expand All @@ -96,24 +83,18 @@ This is the third section of note E
const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);

await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_IN_CONTAINER,
null,
async () => {
await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_TYPE,
'full-inline',
() => {
expect(
md.render(`This is the root node.
CONFIG_EMBED_NOTE_TYPE,
'full-inline',
() => {
expect(
md.render(`This is the root node.
![[note-e#Section 2]]`)
).toMatch(
`<p>This is the root node.</p>
).toMatch(
`<p>This is the root node.</p>
<p><h1>Section 2</h1>
<p>This is the second section of note E</p>
</p>`
);
}
);
}
);
Expand All @@ -139,24 +120,18 @@ 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,
null,
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');
}
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');
}
);

Expand All @@ -176,26 +151,20 @@ This is the first section of note E`,
const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));

await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_IN_CONTAINER,
null,
async () => {
await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_TYPE,
'content-inline',
() => {
const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);

expect(
md.render(`This is the root node.
CONFIG_EMBED_NOTE_TYPE,
'content-inline',
() => {
const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);

expect(
md.render(`This is the root node.
![[note-e]]`)
).toMatch(
`<p>This is the root node.</p>
).toMatch(
`<p>This is the root node.</p>
<p><h2>Section 1</h2>
<p>This is the first section of note E</p>
</p>`
);
}
);
}
);
Expand All @@ -216,24 +185,18 @@ This is the first section of note E
const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));

await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_IN_CONTAINER,
null,
async () => {
await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_TYPE,
'content-card',
() => {
const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);

const res = md.render(`This is the root node. ![[note-e.md]]`);

expect(res).toContain('This is the root node');
expect(res).toContain('embed-container-note');
expect(res).toContain('Section 1');
expect(res).toContain('This is the first section of note E');
expect(res).not.toContain('Title');
}
);
CONFIG_EMBED_NOTE_TYPE,
'content-card',
() => {
const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);

const res = md.render(`This is the root node. ![[note-e.md]]`);

expect(res).toContain('This is the root node');
expect(res).toContain('embed-container-note');
expect(res).toContain('Section 1');
expect(res).toContain('This is the first section of note E');
expect(res).not.toContain('Title');
}
);

Expand All @@ -257,27 +220,21 @@ This is the first subsection of note E
const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));

await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_IN_CONTAINER,
null,
async () => {
await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_TYPE,
'content-inline',
() => {
const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);

expect(
md.render(`This is the root node.
CONFIG_EMBED_NOTE_TYPE,
'content-inline',
() => {
const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);

expect(
md.render(`This is the root node.
![[note-e#Section 1]]`)
).toMatch(
`<p>This is the root node.</p>
).toMatch(
`<p>This is the root node.</p>
<p><p>This is the first section of note E</p>
<h3>Subsection a</h3>
<p>This is the first subsection of note E</p>
</p>`
);
}
);
}
);
Expand All @@ -299,25 +256,19 @@ This is the first subsection of note E`,
const ws = new FoamWorkspace().set(parser.parse(note.uri, note.content));

await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_IN_CONTAINER,
null,
async () => {
await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_TYPE,
'content-inline',
() => {
const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);

expect(
md.render(`This is the root node.
CONFIG_EMBED_NOTE_TYPE,
'content-inline',
() => {
const md = markdownItWikilinkEmbed(MarkdownIt(), ws, parser);

expect(
md.render(`This is the root node.
![[note-e#Subsection a]]`)
).toMatch(
`<p>This is the root node.</p>
).toMatch(
`<p>This is the root node.</p>
<p><p>This is the first subsection of note E</p>
</p>`
);
}
);
}
);
Expand Down Expand Up @@ -351,21 +302,15 @@ This is the first subsection of note E`,
.set(parser.parse(noteB.uri, noteB.content));

await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_IN_CONTAINER,
null,
async () => {
await withModifiedFoamConfiguration(
CONFIG_EMBED_NOTE_TYPE,
'full-card',
() => {
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');
}
);
CONFIG_EMBED_NOTE_TYPE,
'full-card',
() => {
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');
}
);

Expand Down
22 changes: 15 additions & 7 deletions packages/foam-vscode/src/features/preview/wikilink-embed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,32 @@ describe('Wikilink Note Embedding', () => {
});

describe('Config Parsing', () => {
it('should use preview.embedNoteType if deprecated preview.embedNoteInContainer not used', () => {
it('should use preview.embedNoteType if an explicit modifier is not passed in', () => {
jest
.spyOn(config, 'getFoamVsCodeConfig')
.mockReturnValueOnce('full-card')
.mockReturnValueOnce(false);
.mockReturnValueOnce('full-card');

const { noteScope, noteStyle } = retrieveNoteConfig();
const { noteScope, noteStyle } = retrieveNoteConfig(undefined);
expect(noteScope).toEqual('full');
expect(noteStyle).toEqual('card');
});

it('should use preview.embedNoteInContainer if set', () => {
it('should use explicit modifier over user settings if passed in', () => {
jest
.spyOn(config, 'getFoamVsCodeConfig')
.mockReturnValueOnce('full-inline')
.mockReturnValueOnce(true);
.mockReturnValueOnce('full-inline')
.mockReturnValueOnce('full-inline');

let { noteScope, noteStyle } = retrieveNoteConfig('content-card');
expect(noteScope).toEqual('content');
expect(noteStyle).toEqual('card');

({ noteScope, noteStyle } = retrieveNoteConfig('content'));
expect(noteScope).toEqual('content');
expect(noteStyle).toEqual('inline');

const { noteScope, noteStyle } = retrieveNoteConfig();
({ noteScope, noteStyle } = retrieveNoteConfig('card'));
expect(noteScope).toEqual('full');
expect(noteStyle).toEqual('card');
});
Expand Down
Loading

0 comments on commit a9b9417

Please sign in to comment.