Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,28 @@ describe('Link Conversion Commands', () => {
await deleteFile(uri);
});

it('should convert a directory wikilink to its resolved index file', async () => {
const readme = await createFile('# My Folder Index', [
'my-folder',
'README.md',
]);
const { uri } = await createFile('Text before [[my-folder]] text after');
const { editor } = await showInEditor(uri);
await waitForNoteInFoamWorkspace(readme.uri);

editor.selection = new vscode.Selection(0, 15, 0, 15);

await vscode.commands.executeCommand(CONVERT_WIKILINK_TO_MDLINK.command);

const result = editor.document.getText();
expect(result).toBe(
'Text before [My Folder Index](my-folder/README.md) text after'
);

await deleteFile(readme.uri);
await deleteFile(uri);
});

it('should show info message when no wikilink at cursor', async () => {
const { uri } = await createFile('Text with no wikilinks');
const { editor } = await showInEditor(uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ async function convertWikilinkToMarkdown(foam: Foam): Promise<void> {
}

const linkInfo = MarkdownLink.analyzeLink(targetLink);
const targetResource = foam.workspace.find(linkInfo.target);
// Resolve the link the way navigation does. resolveLink may embed the
// section as a URI fragment; strip it to get the resource URI.
const targetUri = foam.workspace.resolveLink(resource, targetLink).asPlain();
const targetResource = foam.workspace.find(targetUri);
if (!targetResource) {
throw new Error(`Resource "${linkInfo.target}" not found`);
}
Expand Down