Skip to content

Commit

Permalink
Fix use of asExternalUri
Browse files Browse the repository at this point in the history
  • Loading branch information
renkun-ken committed Oct 9, 2022
1 parent 5f6089a commit ff2f1bc
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/helpViewer/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ export class HelpPanel {
viewer ||= config().get<string>('session.viewers.viewColumn.helpPanel');
const viewColumn = asViewColumn(viewer);

// get or create webview:
const webview = this.getWebview(preserveFocus, viewColumn);

// make sure helpFile is not a promise:
helpFile = await helpFile;

Expand All @@ -154,9 +157,6 @@ export class HelpPanel {
// modify html
helpFile = await this.pimpMyHelp(helpFile, this.webviewStyleUri, this.webviewScriptUri);

// get or create webview:
const webview = this.getWebview(preserveFocus, viewColumn);

// actually show the help page
webview.html = helpFile.html;

Expand Down Expand Up @@ -360,33 +360,34 @@ export class HelpPanel {
// replace katex js/css urls with http://localhost:<port>/ origin
// and remove others.
const url = new URL(helpFile.url);
const externalUri = (await vscode.env.asExternalUri(vscode.Uri.parse(url.origin))).toString(true);

$('link').each((i, e) => {
const obj = $(e);
for (const elem of $('link')) {
const obj = $(elem);
const linkUrl = obj.attr('href');
if (linkUrl) {
if (linkUrl.includes('katex')) {
const newUrl = new URL(linkUrl, externalUri);
obj.attr('href', newUrl.toString());
const newUrl = new URL(linkUrl, url.origin);
const newUri = await vscode.env.asExternalUri(vscode.Uri.parse(newUrl.toString()));
obj.attr('href', newUri.toString(true));
} else {
obj.remove();
}
}
});
}

$('script').each((i, e) => {
const obj = $(e);
for (const elem of $('script')) {
const obj = $(elem);
const scriptUrl = obj.attr('src');
if (scriptUrl) {
if (scriptUrl.includes('katex')) {
const newUrl = new URL(scriptUrl, externalUri);
obj.attr('src', newUrl.toString());
const newUrl = new URL(scriptUrl, url.origin);
const newUri = await vscode.env.asExternalUri(vscode.Uri.parse(newUrl.toString()));
obj.attr('src', newUri.toString(true));
} else {
obj.remove();
}
}
});
}
}

if (styleUri) {
Expand Down

0 comments on commit ff2f1bc

Please sign in to comment.