Skip to content

Commit

Permalink
external urls are not automatically encoded (#186786)
Browse files Browse the repository at this point in the history
  • Loading branch information
MeghanKulkarni authored Jun 30, 2023
1 parent 39efe30 commit 5b74404
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ enum MediaKind {
Audio,
}

const externalUriSchemes = [
'http',
'https',
];

export const mediaFileExtensions = new Map<string, MediaKind>([
// Images
['bmp', MediaKind.Image],
Expand Down Expand Up @@ -161,7 +166,12 @@ export function createUriListSnippet(
insertedLinkCount++;
snippet.appendText('[');
snippet.appendPlaceholder(escapeBrackets(title) || 'Title', placeholderValue);
snippet.appendText(`](${escapeMarkdownLinkPath(mdPath)})`);
if (externalUriSchemes.includes(uri.scheme)) {
const uriString = uri.toString(true);
snippet.appendText(`](${uriString})`);
} else {
snippet.appendText(`](${escapeMarkdownLinkPath(mdPath)})`);
}
}
}

Expand Down Expand Up @@ -292,7 +302,6 @@ function escapeMarkdownLinkPath(mdPath: string): string {

function escapeBrackets(value: string): string {
value = value.replace(/[\[\]]/g, '\\$&');
// value = value.replace(/\r\n\r\n/g, '\n\n');
return value;
}

Expand Down

0 comments on commit 5b74404

Please sign in to comment.