diff --git a/.gitignore b/.gitignore index f386483..f56bbb8 100644 --- a/.gitignore +++ b/.gitignore @@ -8,9 +8,9 @@ # npm node_modules -# Don't include the compiled main.js file in the repo. +# Don't include the compiled files in the repo. # They should be uploaded to GitHub releases instead. -main.js +dist/ # Exclude sourcemaps *.map diff --git a/esbuild.config.mjs b/esbuild.config.mjs index c927952..4357eac 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -14,7 +14,7 @@ const context = await esbuild.context({ banner: { js: banner, }, - entryPoints: ["main.ts"], + entryPoints: ["src/main.ts"], bundle: true, external: [ "obsidian", @@ -37,7 +37,7 @@ const context = await esbuild.context({ logLevel: "info", sourcemap: prod ? false : "inline", treeShaking: true, - outfile: "main.js", + outfile: "dist/main.js", }); if (prod) { diff --git a/main.ts b/src/main.ts similarity index 81% rename from main.ts rename to src/main.ts index 0c06961..0b81d3e 100644 --- a/main.ts +++ b/src/main.ts @@ -1,3 +1,4 @@ +import { Extension } from "@codemirror/state"; import { Plugin } from "obsidian"; interface Color { @@ -7,12 +8,17 @@ interface Color { } export default class SVGView extends Plugin { + private ext: Extension[]; + async onload() { - this.registerMarkdownPostProcessor((element, context) => { + console.log("Loading SVG-Obsidian."); + + this.registerMarkdownPostProcessor((element, _context) => { const images = element.querySelectorAll("img"); - images.forEach((item) => { - if (!item.src.startsWith("data:image/svg+xml")) { + for (let index = 0; index < images.length; index++) { + const item = images.item(index); + if (!item.src.contains(".svg")) { // Exclude image who aren't SVG return; } @@ -76,9 +82,10 @@ export default class SVGView extends Plugin { filter: "invert(1)", }); } - }); + } }); - } - onunload() {} + /* this.ext = ?? */ + this.registerEditorExtension([this.ext]); + } }