diff --git a/manifest.json b/manifest.json index 87d819f..db88ee1 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-admonition", "name": "Admonition", - "version": "3.0.1", + "version": "3.1.1", "minAppVersion": "0.11.0", "description": "Admonition block-styled content for Obsidian.md", "author": "Jeremy Valentine", diff --git a/package.json b/package.json index e13fe0b..6129929 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-admonition", - "version": "3.0.1", + "version": "3.1.1", "description": "Admonition block-styled content for Obsidian.md", "main": "main.js", "scripts": { diff --git a/src/main.css b/src/main.css index 9078232..da05aab 100644 --- a/src/main.css +++ b/src/main.css @@ -108,3 +108,7 @@ input.is-invalid { font-size: 0.875em; color: #dc3545; } + +.admonition li.task-list-item.is-checked p { + text-decoration: line-through; +} diff --git a/src/main.ts b/src/main.ts index 0ebcf5b..c5c6169 100644 --- a/src/main.ts +++ b/src/main.ts @@ -222,7 +222,9 @@ export default class ObsidianAdmonition let admonitionContent = admonitionElement.createDiv({ cls: "admonition-content" }); - let markdownRenderChild = new MarkdownRenderChild(); + let markdownRenderChild = new MarkdownRenderChild( + admonitionElement + ); markdownRenderChild.containerEl = admonitionElement; /** @@ -235,6 +237,36 @@ export default class ObsidianAdmonition markdownRenderChild ); + const taskLists = admonitionContent.querySelectorAll( + ".contains-task-list" + ); + const splitContent = content.split("\n"); + + for (let i = 0; i < taskLists.length; i++) { + let tasks: NodeListOf = taskLists[ + i + ].querySelectorAll(".task-list-item"); + if (!tasks.length) continue; + for (let j = 0, task = tasks[j]; j < tasks.length; j++) { + if (!task.children.length) continue; + + let innerText = task.getText().replace(/\n/g, ""); + + const search = new RegExp( + `\\[\\s?[xX]?\\s?\\]\\s*${innerText}` + ); + + 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 + }`; + } + } + /** * Replace the
 tag with the new admonition.
              */
diff --git a/versions.json b/versions.json
index e22addc..5d64c08 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.0.1": "0.11.0"
+    "3.1.1": "0.11.0"
 }