Skip to content

Commit

Permalink
fix: image loading failed in vscode plugin (#748)
Browse files Browse the repository at this point in the history
fix: ts's `HeadersInit` deletion

close #744
  • Loading branch information
RSS1102 committed Apr 21, 2024
1 parent 5f43a52 commit b2c6a0e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion vscodePlugin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"target": "es6",
"outDir": "out",
"lib": [
"es6"
"es6",
"DOM"
],
"sourceMap": true,
"rootDir": "src",
Expand All @@ -14,6 +15,9 @@
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
".vscode-test"
Expand Down
14 changes: 11 additions & 3 deletions vscodePlugin/web-resources/scripts/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'mathjax/es5/tex-svg.js';
import path from 'path-browserify';
import vscodeApi from 'vscode';
// import md5 from 'md5';

/**
Expand Down Expand Up @@ -295,15 +296,22 @@ const basicConfig = {
// eslint-disable-next-line no-undef
changeString2Pinyin: pinyin,
beforeImageMounted(srcProp, srcValue) {
console.log('beforeImageMounted', srcProp, srcValue);
if (isHttpUrl(srcValue) || isDataUrl(srcValue)) {
return {
src: srcValue,
};
}
// eslint-disable-next-line no-underscore-dangle
const basePath = window._baseResourcePath || '';
let imgPath = srcValue;
const { workspaceFolders } = vscodeApi.workspace;
if (workspaceFolders && workspaceFolders.length > 0) {
const workspacePath = workspaceFolders[0].uri.fsPath;
imgPath = path.join(workspacePath, srcValue);
}

return {
src: path.join(basePath, srcValue),
// src: path.join(basePath, srcValue),
src: imgPath,
};
},
},
Expand Down

0 comments on commit b2c6a0e

Please sign in to comment.