Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/markdown-language-features/src/util/url.ts
3292 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as vscode from 'vscode';
7
8
/**
9
* Tries to convert an url into a vscode uri and returns undefined if this is not possible.
10
* `url` can be absolute or relative.
11
*/
12
export function urlToUri(url: string, base: vscode.Uri): vscode.Uri | undefined {
13
try {
14
// `vscode.Uri.joinPath` cannot be used, since it understands
15
// `src` as path, not as relative url. This is problematic for query args.
16
const parsedUrl = new URL(url, base.toString());
17
const uri = vscode.Uri.parse(parsedUrl.toString());
18
return uri;
19
} catch (e) {
20
// Don't crash if `URL` cannot parse `src`.
21
return undefined;
22
}
23
}
24
25