From 0c3027d04ef57dd4747dbfb0b31826fdf52a8183 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Sun, 30 Jan 2022 21:03:15 +0100 Subject: [PATCH] guard against some undefined values --- manifest.json | 20 ++++++++++---------- src/main.ts | 17 +++++++++++------ versions.json | 7 ++++--- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/manifest.json b/manifest.json index fa51583..b268b02 100644 --- a/manifest.json +++ b/manifest.json @@ -1,10 +1,10 @@ -{ - "id": "tag-word-cloud", - "name": "Tag & Word Cloud", - "version": "1.0.0", - "minAppVersion": "0.12.0", - "description": "Show a cloud of your tags/words in a note", - "author": "Johannes Theiner", - "authorUrl": "https://github.com/joethei", - "isDesktopOnly": false -} +{ + "id": "tag-word-cloud", + "name": "Tag & Word Cloud", + "version": "1.0.1", + "minAppVersion": "0.12.0", + "description": "Show a cloud of your tags/words in a note", + "author": "Johannes Theiner", + "authorUrl": "https://github.com/joethei", + "isDesktopOnly": false +} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 8029ce1..2861866 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,15 +16,17 @@ export interface CodeblockOptions { export default class TagCloudPlugin extends Plugin { - parseCodeblockOptions(source: string): CodeblockOptions { + parseCodeblockOptions(source: string): CodeblockOptions | null { const yaml = source ? parseYaml(source) : {}; - const max_width = getComputedStyle( + const previewBlock = getComputedStyle( document.querySelector( '.markdown-preview-view.is-readable-line-width .markdown-preview-sizer' - ) - ).getPropertyValue('width'); + )); + if(previewBlock === undefined) return undefined; + + const max_width = previewBlock.getPropertyValue('width'); //remove any units const width = yaml.width ? yaml.width : Number(max_width.replace(/[^\d]/g, '')); @@ -36,10 +38,11 @@ export default class TagCloudPlugin extends Plugin { const darkEL = document.getElementsByClassName("theme-dark")[0]; const lightEl = document.getElementsByClassName("theme-light")[0]; + if (isDarkMode) { - background = getComputedStyle(darkEL).getPropertyValue('--background-primary'); + background = window.getComputedStyle(darkEL).getPropertyValue('--background-primary'); } else { - background = getComputedStyle(lightEl).getPropertyValue('--background-primary'); + background = window.getComputedStyle(lightEl).getPropertyValue('--background-primary'); } return { @@ -61,6 +64,7 @@ export default class TagCloudPlugin extends Plugin { this.registerMarkdownCodeBlockProcessor('wordcloud', async (source, el, ctx) => { const options = this.parseCodeblockOptions(source); + if (options === undefined) return; const file = this.app.vault.getAbstractFileByPath(ctx.sourcePath); if (file === undefined) return; @@ -85,6 +89,7 @@ export default class TagCloudPlugin extends Plugin { this.registerMarkdownCodeBlockProcessor('tagcloud', (source, el, _) => { const options = this.parseCodeblockOptions(source); + if (options === undefined) return; const tags: string[] = []; diff --git a/versions.json b/versions.json index 1771c33..42a12a4 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,4 @@ -{ - "1.0.0": "0.12.0" -} +{ + "1.0.0": "0.12.0", + "1.0.1": "0.12.0" +} \ No newline at end of file