From c236997c0a9648d597a479894420862ef098e589 Mon Sep 17 00:00:00 2001 From: valentine195 <38669521+valentine195@users.noreply.github.com> Date: Mon, 19 Apr 2021 12:10:13 -0400 Subject: [PATCH] 3.1.2 - Fixed issue related to multiple checkboxes in admonitions (#9) --- README.md | 2 ++ manifest.json | 2 +- package.json | 2 +- src/main.ts | 22 ++++++++++++++-------- versions.json | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index be4afdc..cbaf5d6 100644 --- a/README.md +++ b/README.md @@ -234,6 +234,8 @@ An icon without a title will have this CSS: # Version History +## 3.1.0 +- Fixed issue where checkboxes in admonitions were not toggleable ## 3.0.0 - Added ability to create custom admonitions via Settings diff --git a/manifest.json b/manifest.json index db88ee1..a14aaf3 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-admonition", "name": "Admonition", - "version": "3.1.1", + "version": "3.1.2", "minAppVersion": "0.11.0", "description": "Admonition block-styled content for Obsidian.md", "author": "Jeremy Valentine", diff --git a/package.json b/package.json index 6129929..64c8751 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-admonition", - "version": "3.1.1", + "version": "3.1.2", "description": "Admonition block-styled content for Obsidian.md", "main": "main.js", "scripts": { diff --git a/src/main.ts b/src/main.ts index c5c6169..8a48cb9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -247,10 +247,21 @@ export default class ObsidianAdmonition i ].querySelectorAll(".task-list-item"); if (!tasks.length) continue; - for (let j = 0, task = tasks[j]; j < tasks.length; j++) { + for (let j = 0; j < tasks.length; j++) { + let task = tasks[j]; if (!task.children.length) continue; + const inputs = task.querySelectorAll( + "input[type='checkbox']" + ) as NodeListOf; + if (!inputs.length) continue; + const input = inputs[0]; - let innerText = task.getText().replace(/\n/g, ""); + if ( + !input.nextSibling || + input.nextSibling.nodeName != "#text" + ) + continue; + const innerText = input.nextSibling.textContent; const search = new RegExp( `\\[\\s?[xX]?\\s?\\]\\s*${innerText}` @@ -258,12 +269,7 @@ export default class ObsidianAdmonition const line = splitContent.find((l) => search.test(l)); - let inputs = task.getElementsByTagName("input"); - if (!inputs.length) continue; - - inputs[0].dataset["line"] = `${ - splitContent.indexOf(line) + 1 - }`; + input.dataset["line"] = `${splitContent.indexOf(line) + 1}`; } } diff --git a/versions.json b/versions.json index 5d64c08..379f85d 100644 --- a/versions.json +++ b/versions.json @@ -2,5 +2,5 @@ "0.2.3": "0.11.0", "1.0.1": "0.11.0", "2.0.1": "0.11.0", - "3.1.1": "0.11.0" + "3.1.2": "0.11.0" }