Skip to content

Commit

Permalink
Remove angle brackets when checking the scheme (#133419)
Browse files Browse the repository at this point in the history
* Remove angle brackets when checking the scheme

This only removes the brackets during the scheme check if the initial link provided actually has angle brackets.

* Move angle bracket logic to document link file

Change to use replace instead of match for easier reading
  • Loading branch information
codingLogan committed Oct 4, 2021
1 parent 93ab0da commit 35ea6c0
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ function parseLink(
document: vscode.TextDocument,
link: string,
): { uri: vscode.Uri, tooltip?: string } | undefined {
const externalSchemeUri = getUriForLinkWithKnownExternalScheme(link);

const cleanLink = stripAngleBrackets(link);
const externalSchemeUri = getUriForLinkWithKnownExternalScheme(cleanLink);
if (externalSchemeUri) {
// Normalize VS Code links to target currently running version
if (isOfScheme(Schemes.vscode, link) || isOfScheme(Schemes['vscode-insiders'], link)) {
Expand Down Expand Up @@ -89,6 +91,15 @@ function extractDocumentLink(
}
}

/* Used to strip brackets from the markdown link
<http://example.com> will be transformed to
http://example.com
*/
export function stripAngleBrackets(link: string) {
const bracketMatcher = /^<(.*)>$/;
return link.replace(bracketMatcher, '$1');
}

export default class LinkProvider implements vscode.DocumentLinkProvider {
private readonly linkPattern = /(\[((!\[[^\]]*?\]\(\s*)([^\s\(\)]+?)\s*\)\]|(?:\\\]|[^\]])*\])\(\s*)(([^\s\(\)]|\([^\s\(\)]*?\))+)\s*(".*?")?\)/g;
private readonly referenceLinkPattern = /(\[((?:\\\]|[^\]])+)\]\[\s*?)([^\s\]]*?)\]/g;
Expand Down

0 comments on commit 35ea6c0

Please sign in to comment.