Skip to content

Commit

Permalink
guard against some undefined values
Browse files Browse the repository at this point in the history
  • Loading branch information
joethei committed Jan 30, 2022
1 parent 0cc491b commit 0c3027d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
20 changes: 10 additions & 10 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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
}
17 changes: 11 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, ''));
Expand All @@ -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 {
Expand All @@ -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;
Expand All @@ -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[] = [];

Expand Down
7 changes: 4 additions & 3 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"1.0.0": "0.12.0"
}
{
"1.0.0": "0.12.0",
"1.0.1": "0.12.0"
}

0 comments on commit 0c3027d

Please sign in to comment.