Skip to content

Commit 40e6970

Browse files
committed
Sanitize existing command links from hover Javadocs
Replace any existing `command:command.name?param=true` style links in hover Javadoc with the display text for the link. eg. `[click here](command:command.name?param=true)` becomes `click here`. Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent 14fdf79 commit 40e6970

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"search.exclude": {
77
"out": true // set this to false to include "out" folder in search results
88
},
9-
"typescript.tsdk": "./node_modules/typescript/lib",
9+
"js/ts.tsdk.path": "./node_modules/typescript/lib",
1010
"git.alwaysSignOff": true,
1111
"vsicons.presets.angular": false // we want to use the TS server from our node_modules folder to control its version
1212
}

src/extension.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ function getHeapDumpFolderFromSettings(): string {
110110
}
111111

112112
const REPLACE_JDT_LINKS_PATTERN: RegExp = /(\[(?:[^\]])+\]\()(jdt:\/\/(?:(?:(?:\\\))|([^)]))+))\)/g;
113+
const EXISTING_COMMAND_PATTERN: RegExp = /\[([^\]]+)\]\(command:[^)]+\)/g;
113114

114115
/**
115116
* Replace `jdt://` links in the documentation with links that execute the VS Code command required to open the referenced file.
@@ -120,7 +121,11 @@ const REPLACE_JDT_LINKS_PATTERN: RegExp = /(\[(?:[^\]])+\]\()(jdt:\/\/(?:(?:(?:\
120121
* @returns the documentation with fixed links
121122
*/
122123
export function fixJdtLinksInDocumentation(oldDocumentation: MarkdownString): MarkdownString {
123-
const newContent: string = oldDocumentation.value.replace(REPLACE_JDT_LINKS_PATTERN, (_substring, group1, group2) => {
124+
// sanitize existing command: links
125+
const sanitizedContent = oldDocumentation.value.replace(EXISTING_COMMAND_PATTERN, (_substring, group1: string, group2) => {
126+
return group1;
127+
});
128+
const newContent: string = sanitizedContent.replace(REPLACE_JDT_LINKS_PATTERN, (_substring, group1, group2) => {
124129
const uri = `command:${Commands.OPEN_FILE}?${encodeURI(JSON.stringify([encodeURIComponent(group2)]))}`;
125130
return `${group1}${uri})`;
126131
});

0 commit comments

Comments
 (0)