Do not transform URIs of online images.

This commit is contained in:
CismonX 2021-04-16 18:58:52 +08:00
parent c647d7d86b
commit f86534985b
Signed by: cismonx
GPG Key ID: 3094873E29A482FB
3 changed files with 7 additions and 5 deletions

View File

@ -188,10 +188,10 @@
"default": false,
"description": "Suppress warnings."
},
"texinfo.preview.displayImage": {
"texinfo.preview.localImage": {
"type": "boolean",
"default": false,
"description": "Display images in in preview."
"description": "Display local images in in preview."
},
"texinfo.preview.customCSS": {
"type": "string",

View File

@ -79,9 +79,11 @@ export default class PreviewContext {
private pendingUpdate = false;
private get imageTransformer(): Optional<Operator<string>> {
if (!Options.displayImage) return undefined;
if (!Options.localImage) return undefined;
const pathName = path.dirname(this.document.fileName);
return src => {
// Do not transform URIs of online images.
if (src.startsWith('https://') || src.startsWith('http://')) return src;
const srcUri = vscode.Uri.file(pathName + '/' + src);
// To display images in webviews, image URIs in HTML should be converted to VSCode-recognizable ones.
return this.panel.webview.asWebviewUri(srcUri).toString();

View File

@ -70,8 +70,8 @@ export default class Options implements vscode.Disposable {
return Options.instance.getBoolean('preview.noWarnings');
}
static get displayImage() {
return Options.instance.getBoolean('preview.displayImage');
static get localImage() {
return Options.instance.getBoolean('preview.localImage');
}
static get customCSS() {