Skip to content
This repository was archived by the owner on Jun 26, 2025. It is now read-only.

Commit 63a85b8

Browse files
committed
feat: pass plugin instance to CssSnippetStoreModal and SnippetReadmeModal for improved context
1 parent fbce149 commit 63a85b8

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

main.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default class CssSnippetStore extends Plugin {
6363
customButton.style.marginLeft = "8px";
6464

6565
customButton.onclick = () => {
66-
new CssSnippetStoreModal(this.app, this.snippets).open();
66+
new CssSnippetStoreModal(this.app, this.snippets, this).open();
6767
};
6868

6969
controlElement.appendChild(customButton);
@@ -92,7 +92,7 @@ export default class CssSnippetStore extends Plugin {
9292
}
9393

9494
class CssSnippetStoreModal extends Modal {
95-
constructor(app: App, private snippets: Snippet[]) {
95+
constructor(app: App, private snippets: Snippet[], private plugin: Plugin) {
9696
super(app);
9797
this.modalEl.addClass('mod-snippet-store');
9898
}
@@ -253,7 +253,8 @@ class CssSnippetStoreModal extends Modal {
253253
return;
254254
}
255255
const readme = await response.text();
256-
new SnippetReadmeModal(this.app, snippet, readme).open();
256+
// Pass the plugin instance (this.plugin)
257+
new SnippetReadmeModal(this.app, snippet, readme, this.plugin).open();
257258
} else {
258259
new Notice("No Internet connection...");
259260
}
@@ -349,7 +350,8 @@ class SnippetReadmeModal extends Modal {
349350
constructor(
350351
app: App,
351352
private snippet: Snippet,
352-
private readmeContent: string
353+
private readmeContent: string,
354+
private plugin: Plugin // Add reference to the plugin instance
353355
) {
354356
super(app);
355357
}
@@ -361,28 +363,20 @@ class SnippetReadmeModal extends Modal {
361363
this.modalEl.style.width = "80vw";
362364
this.modalEl.style.height = "80vh";
363365

364-
// Title
365-
contentEl.createEl("h2", {
366-
text: `${this.snippet.name} – README`,
367-
});
368-
369366
// Rewrite relative image paths to absolute GitHub raw URLs
370367
const adjustedContent = this.rewriteRelativeMediaPaths(this.readmeContent);
371368

372369
// Markdown container
373370
const markdownContainer = contentEl.createDiv();
374-
markdownContainer.style.overflowY = "auto";
375-
markdownContainer.style.maxHeight = "65vh";
376-
markdownContainer.style.padding = "1rem";
377-
markdownContainer.style.backgroundColor = "var(--background-secondary)";
378-
markdownContainer.style.borderRadius = "8px";
379371

380372
// Render Markdown using Obsidian's renderer
381-
await MarkdownRenderer.renderMarkdown(
373+
// Use the plugin instance instead of "this"
374+
await MarkdownRenderer.render(
375+
this.app,
382376
adjustedContent,
383377
markdownContainer,
384378
"",
385-
this
379+
this.plugin // Pass the plugin instance which is a Component
386380
);
387381

388382
markdownContainer.querySelectorAll("img").forEach((img) => {
@@ -401,7 +395,7 @@ class SnippetReadmeModal extends Modal {
401395
const base = `https://raw.githubusercontent.com/${this.snippet.repo}/refs/heads/main/${this.snippet.folder}/`;
402396

403397
// Regex to match image/video markdown with relative path
404-
return content.replace(/!\[([^\]]*)\]\((\.\/[^)]+)\)/g, (match, alt, relPath) => {
398+
return content.replace(/!\[([^\]]*)]\((\.\/[^)]+)\)/g, (match, alt, relPath) => {
405399
const url = base + relPath.replace("./", "");
406400
return `![${alt}](${url})`;
407401
});

0 commit comments

Comments
 (0)