From d53c34e37efebe04858e36484815966437012918 Mon Sep 17 00:00:00 2001 From: samuele-cozzi Date: Sat, 9 Mar 2024 14:20:53 +0100 Subject: [PATCH] fix: file is null --- src/views/marpPreviewView.ts | 60 ++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/src/views/marpPreviewView.ts b/src/views/marpPreviewView.ts index e4009f9..b100414 100644 --- a/src/views/marpPreviewView.ts +++ b/src/views/marpPreviewView.ts @@ -65,7 +65,7 @@ export class MarpPreviewView extends ItemView { if (this.settings.ThemePath != '') { const fileContents: string[] = await Promise.all( this.app.vault.getFiles() - .filter(x => x.parent.path == normalizePath(this.settings.ThemePath)) + .filter(x => x.parent?.path == normalizePath(this.settings.ThemePath)) .map((file) => this.app.vault.cachedRead(file)) ); @@ -130,31 +130,37 @@ export class MarpPreviewView extends ItemView { async displaySlides(view : MarkdownView) { - this.file = view.file; - const basePath = (new FilePath(this.settings)).getCompleteFileBasePath(view.file); - const markdownText = view.data; - - const container = this.containerEl.children[1]; - container.empty(); - - - let { html, css } = this.marp.render(markdownText); - - // Replace Backgorund Url for images - html = html.replace(/(?!background-image:url\("http)background-image:url\("/g, `background-image:url("${basePath}`); - - const htmlFile = ` - - - - - - - ${html} - - `; - - container.innerHTML = htmlFile; - this.marpBrowser?.update(); + if (view.file != null) { + this.file = view.file; + const basePath = (new FilePath(this.settings)).getCompleteFileBasePath(view.file); + const markdownText = view.data; + + const container = this.containerEl.children[1]; + container.empty(); + + + let { html, css } = this.marp.render(markdownText); + + // Replace Backgorund Url for images + html = html.replace(/(?!background-image:url\("http)background-image:url\("/g, `background-image:url("${basePath}`); + + const htmlFile = ` + + + + + + + ${html} + + `; + + container.innerHTML = htmlFile; + this.marpBrowser?.update(); + } + else + { + console.log("Errore: view.file is null") + } } } \ No newline at end of file