提交 ef5326f1 编写于 作者: M Matt Bierner

More html text preprocessing into vscode process

This does not need to happen in the webview itself
上级 18ba826e
......@@ -45,9 +45,6 @@
},
onMessage: (channel, handler) => {
handlers[channel] = handler;
},
preProcessHtml: (text) => {
return text.replace(/(?:["'])vscode-resource:([^\s'"]+)(?:["'])/gi, '/vscode-resource$1');
}
});
}());
......
......@@ -99,7 +99,6 @@
* postMessage: (channel: string, data?: any) => void,
* onMessage: (channel: string, handler: any) => void,
* injectHtml?: (document: HTMLDocument) => void,
* preProcessHtml?: (text: string) => void,
* focusIframeOnCreate?: boolean
* }} HostCommunications
*/
......@@ -263,7 +262,7 @@
host.onMessage('content', (_event, data) => {
const options = data.options;
const text = host.preProcessHtml ? host.preProcessHtml(data.contents) : data.contents;
const text = data.contents;
const newDocument = new DOMParser().parseFromString(text, 'text/html');
newDocument.querySelectorAll('a').forEach(a => {
......
......@@ -152,19 +152,23 @@ export class IFrameWebview extends Disposable implements Webview {
public set html(value: string) {
this.content = {
html: value,
html: this.preprocessHtml(value),
options: this.content.options,
state: this.content.state,
};
this.doUpdateContent();
}
private preprocessHtml(value: string): string {
return value.replace(/(?:["'])vscode-resource:([^\s'"]+)(?:["'])/gi, '/vscode-resource$1');
}
public update(html: string, options: WebviewContentOptions, retainContextWhenHidden: boolean) {
if (retainContextWhenHidden && html === this.content.html && areWebviewInputOptionsEqual(options, this.content.options)) {
return;
}
this.content = {
html: html,
html: this.preprocessHtml(html),
options: options,
state: this.content.state,
};
......@@ -209,7 +213,6 @@ export class IFrameWebview extends Disposable implements Webview {
this._send('message', data);
}
layout(): void {
// noop
}
......@@ -217,6 +220,7 @@ export class IFrameWebview extends Disposable implements Webview {
focus(): void {
this.element.focus();
}
dispose(): void {
if (this.element) {
if (this.element.parentElement) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册