src/ and dist/

This commit is contained in:
Mylloon 2023-10-02 00:03:10 +02:00
parent 24df99815f
commit 4069c345a0
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 17 additions and 10 deletions

4
.gitignore vendored
View file

@ -8,9 +8,9 @@
# npm # npm
node_modules 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. # They should be uploaded to GitHub releases instead.
main.js dist/
# Exclude sourcemaps # Exclude sourcemaps
*.map *.map

View file

@ -14,7 +14,7 @@ const context = await esbuild.context({
banner: { banner: {
js: banner, js: banner,
}, },
entryPoints: ["main.ts"], entryPoints: ["src/main.ts"],
bundle: true, bundle: true,
external: [ external: [
"obsidian", "obsidian",
@ -37,7 +37,7 @@ const context = await esbuild.context({
logLevel: "info", logLevel: "info",
sourcemap: prod ? false : "inline", sourcemap: prod ? false : "inline",
treeShaking: true, treeShaking: true,
outfile: "main.js", outfile: "dist/main.js",
}); });
if (prod) { if (prod) {

View file

@ -1,3 +1,4 @@
import { Extension } from "@codemirror/state";
import { Plugin } from "obsidian"; import { Plugin } from "obsidian";
interface Color { interface Color {
@ -7,12 +8,17 @@ interface Color {
} }
export default class SVGView extends Plugin { export default class SVGView extends Plugin {
private ext: Extension[];
async onload() { async onload() {
this.registerMarkdownPostProcessor((element, context) => { console.log("Loading SVG-Obsidian.");
this.registerMarkdownPostProcessor((element, _context) => {
const images = element.querySelectorAll("img"); const images = element.querySelectorAll("img");
images.forEach((item) => { for (let index = 0; index < images.length; index++) {
if (!item.src.startsWith("data:image/svg+xml")) { const item = images.item(index);
if (!item.src.contains(".svg")) {
// Exclude image who aren't SVG // Exclude image who aren't SVG
return; return;
} }
@ -76,9 +82,10 @@ export default class SVGView extends Plugin {
filter: "invert(1)", filter: "invert(1)",
}); });
} }
});
});
} }
});
onunload() {} /* this.ext = ?? */
this.registerEditorExtension([this.ext]);
}
} }