Skip to content

Commit

Permalink
3.1.1
Browse files Browse the repository at this point in the history
- Fixed issue where checkboxes in admonitions were not updating when clicked (closes #9)
- Fixed issue where some checked checkboxes in admonitions would not show crossed out
  • Loading branch information
valentine195 committed Apr 19, 2021
1 parent 51198cd commit 5b7d0f5
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 4 additions & 0 deletions src/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
34 changes: 33 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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<HTMLLIElement> = 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 <pre> tag with the new admonition.
*/
Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 5b7d0f5

Please sign in to comment.