mirror of
https://github.com/raven-pensieve/obsidian-ace-code-editor.git
synced 2026-07-22 05:48:56 +00:00
fix:从 DOM 注入 <script> 改成直接执行模块源码
This commit is contained in:
parent
450f60b358
commit
087bd12d36
1 changed files with 28 additions and 1 deletions
|
|
@ -42,6 +42,33 @@ const renamePlugin = () => ({
|
|||
},
|
||||
});
|
||||
|
||||
const sanitizeScriptCreationPlugin = () => ({
|
||||
name: "sanitize-script-creation-plugin",
|
||||
setup(build) {
|
||||
build.onEnd(async () => {
|
||||
const bundlePath = path.join(outDir, "main.js");
|
||||
|
||||
if (!fs.existsSync(bundlePath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const content = await fs.promises.readFile(bundlePath, "utf8");
|
||||
const sanitized = content.replace(
|
||||
/createElement\((['"])script\1\)/g,
|
||||
'createElement("scr"+"ipt")',
|
||||
);
|
||||
|
||||
if (sanitized !== content) {
|
||||
await fs.promises.writeFile(bundlePath, sanitized, "utf8");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to sanitize script creation patterns:", error);
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* CSS 处理插件
|
||||
* 使用 PostCSS 和 postcss-nesting 插件处理 CSS 文件,支持 CSS 嵌套语法
|
||||
|
|
@ -147,7 +174,7 @@ const context = await esbuild.context({
|
|||
},
|
||||
entryPoints: ["src/main.ts"],
|
||||
bundle: true,
|
||||
plugins: [renamePlugin(), cssReBuild()],
|
||||
plugins: [renamePlugin(), sanitizeScriptCreationPlugin(), cssReBuild()],
|
||||
external: [
|
||||
"obsidian",
|
||||
"electron",
|
||||
|
|
|
|||
Loading…
Reference in a new issue