Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1321. Link references escaping HTML. #1322

Merged
merged 1 commit into from
Jan 15, 2024
Merged
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 @@ -135,13 +135,13 @@ describe('generateLinkReferences', () => {
expect(actual).toEqual(expected);
});

it('should encode spaces links', async () => {
it('should put links with spaces in angel brackets', async () => {
const note = findBySlug('angel-reference');
const expected = {
newText: textForNote(
`
[//begin]: # "Autogenerated link references for markdown compatibility"
[Note being referred as angel]: Note%20being%20referred%20as%20angel "Note being referred as angel"
[Note being referred as angel]: <Note being referred as angel> "Note being referred as angel"
[//end]: # "Autogenerated link references"`
),
range: Range.create(3, 0, 3, 0),
Expand Down
8 changes: 7 additions & 1 deletion packages/foam-vscode/src/core/services/markdown-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ export function createMarkdownReferences(
relativeUri = relativeUri.changeExtension('*', '');
}

// Extract base path and link name separately.
const basePath = relativeUri.path.split('/').slice(0, -1).join('/');
const linkName = relativeUri.path.split('/').pop();

const encodedURL = encodeURIComponent(linkName).replace(/%20/g, ' ');

// [wikilink-text]: path/to/file.md "Page title"
return {
// embedded looks like ![[note-a]]
Expand All @@ -145,7 +151,7 @@ export function createMarkdownReferences(
link.isEmbed ? 3 : 2,
link.rawText.length - 2
),
url: encodeURIComponent(relativeUri.path),
url: `${basePath ? basePath + '/' : ''}${encodedURL}`,
title: target.title,
};
})
Expand Down
Loading