mirror of
https://github.com/anareaty/html-checkboxes.git
synced 2026-07-22 05:37:43 +00:00
changed modify to process
This commit is contained in:
parent
ccbbf3c9e7
commit
23a2526fc4
2 changed files with 87 additions and 78 deletions
161
main.ts
161
main.ts
|
|
@ -54,46 +54,52 @@ export default class HTMLCheckboxPlugin extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file instanceof TFile) {
|
if (file instanceof TFile) {
|
||||||
let content = await this.app.vault.cachedRead(file)
|
|
||||||
|
|
||||||
let id = target.id
|
await this.app.vault.process(file, (content) => {
|
||||||
let checkboxRE = new RegExp("<input[^>]*?id=\"" + id + "\"[^>]*?>")
|
|
||||||
|
|
||||||
if (file.extension == "canvas") {
|
let id = target.id
|
||||||
checkboxRE = new RegExp("<input[^>]*?id=\\\\\"" + id + "\\\\\"[^>]*?>")
|
let checkboxRE = new RegExp("<input[^>]*?id=\"" + id + "\"[^>]*?>")
|
||||||
}
|
|
||||||
|
|
||||||
let checkboxMatch = content.match(checkboxRE)
|
if (file && file.extension == "canvas") {
|
||||||
|
checkboxRE = new RegExp("<input[^>]*?id=\\\\\"" + id + "\\\\\"[^>]*?>")
|
||||||
if (checkboxMatch) {
|
|
||||||
let checkboxString = checkboxMatch[0]
|
|
||||||
let dataTaskMatch = checkboxString.match(/data-task="."/)
|
|
||||||
|
|
||||||
let newCheckboxString = checkboxString
|
|
||||||
|
|
||||||
if ((target as HTMLInputElement).checked) {
|
|
||||||
newCheckboxString = newCheckboxString.replace(">", " checked>")
|
|
||||||
} else {
|
|
||||||
newCheckboxString = newCheckboxString.replace(" checked>", ">").replace(" >", ">")
|
|
||||||
|
|
||||||
if (dataTaskMatch) {
|
|
||||||
newCheckboxString = newCheckboxString.replace(dataTaskMatch[0], "")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let newContent = content.replace(checkboxString, newCheckboxString)
|
|
||||||
await this.app.vault.modify(file, newContent)
|
|
||||||
|
|
||||||
let inCanvas = target.closest(".canvas-node-content")
|
let checkboxMatch = content.match(checkboxRE)
|
||||||
|
let newContent = content
|
||||||
|
|
||||||
if (file.extension != "canvas" && inCanvas) {
|
if (checkboxMatch) {
|
||||||
let leaf = this.app.workspace.getMostRecentLeaf()
|
let checkboxString = checkboxMatch[0]
|
||||||
if (leaf instanceof WorkspaceLeaf) {
|
let dataTaskMatch = checkboxString.match(/data-task="."/)
|
||||||
//@ts-ignore
|
let newCheckboxString = checkboxString
|
||||||
await leaf.rebuildView()
|
|
||||||
|
if (!(target as HTMLInputElement).checked) {
|
||||||
|
newCheckboxString = newCheckboxString.replace(">", " checked>")
|
||||||
|
|
||||||
|
} else {
|
||||||
|
newCheckboxString = newCheckboxString.replace(" checked>", ">").replace(" >", ">")
|
||||||
|
if (dataTaskMatch) {
|
||||||
|
newCheckboxString = newCheckboxString.replace(dataTaskMatch[0], "")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
newContent = content.replace(checkboxString, newCheckboxString)
|
||||||
|
}
|
||||||
|
return newContent
|
||||||
|
})
|
||||||
|
|
||||||
|
let inCanvas = target.closest(".canvas-node-content")
|
||||||
|
|
||||||
|
|
||||||
|
if (file.extension != "canvas" && inCanvas) {
|
||||||
|
let leaf = this.app.workspace.getMostRecentLeaf()
|
||||||
|
if (leaf instanceof WorkspaceLeaf) {
|
||||||
|
//@ts-ignore
|
||||||
|
await leaf.rebuildView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -224,56 +230,59 @@ export default class HTMLCheckboxPlugin extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file instanceof TFile) {
|
if (file instanceof TFile) {
|
||||||
let content = await this.app.vault.cachedRead(file)
|
|
||||||
let id = target.id
|
|
||||||
let checkboxRE = new RegExp("<input[^>]*?id=\"" + id + "\"[^>]*?>")
|
|
||||||
|
|
||||||
if (file.extension == "canvas") {
|
await this.app.vault.process(file, (content) => {
|
||||||
checkboxRE = new RegExp("<input[^>]*?id=\\\\\"" + id + "\\\\\"[^>]*?>")
|
let id = target.id
|
||||||
}
|
let checkboxRE = new RegExp("<input[^>]*?id=\"" + id + "\"[^>]*?>")
|
||||||
|
|
||||||
let checkboxString = content.match(checkboxRE)![0]
|
if (file && file.extension == "canvas") {
|
||||||
let newCheckboxString = checkboxString
|
checkboxRE = new RegExp("<input[^>]*?id=\\\\\"" + id + "\\\\\"[^>]*?>")
|
||||||
let statusRe = new RegExp("data-task=\"" + status + "\"")
|
|
||||||
let dataTaskMatch = checkboxString.match(/data-task="."/)
|
|
||||||
|
|
||||||
if (file.extension == "canvas") {
|
|
||||||
dataTaskMatch = checkboxString.match(/data-task=\\".\\"/)
|
|
||||||
}
|
|
||||||
|
|
||||||
let dataTaskMatchFirst = ""
|
|
||||||
if (dataTaskMatch) {
|
|
||||||
dataTaskMatchFirst = dataTaskMatch[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
let statusMatch = checkboxString.match(statusRe)
|
|
||||||
let dataTaskString = "data-task=\"" + status + "\""
|
|
||||||
|
|
||||||
if (file.extension == "canvas") {
|
|
||||||
dataTaskString = 'data-task=\\\"' + status + '\\\"'
|
|
||||||
}
|
|
||||||
|
|
||||||
if (status == " ") {
|
|
||||||
newCheckboxString = newCheckboxString
|
|
||||||
.replace(dataTaskMatchFirst, "")
|
|
||||||
.replace(" checked>", ">").replace(" >", ">")
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if (dataTaskMatch && !statusMatch) {
|
|
||||||
newCheckboxString = newCheckboxString.replace(dataTaskMatchFirst, dataTaskString)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dataTaskMatch && (target as HTMLInputElement).checked) {
|
let checkboxString = content.match(checkboxRE)![0]
|
||||||
newCheckboxString = newCheckboxString.replace("checked", dataTaskString + " checked")
|
let newCheckboxString = checkboxString
|
||||||
}
|
let statusRe = new RegExp("data-task=\"" + status + "\"")
|
||||||
|
let dataTaskMatch = checkboxString.match(/data-task="."/)
|
||||||
if (!dataTaskMatch && !(target as HTMLInputElement).checked) {
|
|
||||||
newCheckboxString = newCheckboxString.replace(">", " " + dataTaskString + " checked>")
|
if (file && file.extension == "canvas") {
|
||||||
}
|
dataTaskMatch = checkboxString.match(/data-task=\\".\\"/)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let dataTaskMatchFirst = ""
|
||||||
|
if (dataTaskMatch) {
|
||||||
|
dataTaskMatchFirst = dataTaskMatch[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
let statusMatch = checkboxString.match(statusRe)
|
||||||
|
let dataTaskString = "data-task=\"" + status + "\""
|
||||||
|
|
||||||
|
if (file && file.extension == "canvas") {
|
||||||
|
dataTaskString = 'data-task=\\\"' + status + '\\\"'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status == " ") {
|
||||||
|
newCheckboxString = newCheckboxString
|
||||||
|
.replace(dataTaskMatchFirst, "")
|
||||||
|
.replace(" checked>", ">").replace(" >", ">")
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (dataTaskMatch && !statusMatch) {
|
||||||
|
newCheckboxString = newCheckboxString.replace(dataTaskMatchFirst, dataTaskString)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dataTaskMatch && (target as HTMLInputElement).checked) {
|
||||||
|
newCheckboxString = newCheckboxString.replace("checked", dataTaskString + " checked")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dataTaskMatch && !(target as HTMLInputElement).checked) {
|
||||||
|
newCheckboxString = newCheckboxString.replace(">", " " + dataTaskString + " checked>")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let newContent = content.replace(checkboxString, newCheckboxString)
|
||||||
|
return newContent
|
||||||
|
})
|
||||||
|
|
||||||
let newContent = content.replace(checkboxString, newCheckboxString)
|
|
||||||
await this.app.vault.modify(file, newContent)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
{
|
{
|
||||||
"id": "html-checkboxes",
|
"id": "html-checkboxes",
|
||||||
"name": "HTML checkboxes",
|
"name": "HTML checkboxes",
|
||||||
"version": "1.0.4",
|
"version": "1.0.5",
|
||||||
"minAppVersion": "0.15.0",
|
"minAppVersion": "1.1.0",
|
||||||
"description": "Allows to quickly add HTML checkboxes to your notes and makes them clickable.",
|
"description": "Allows to quickly add HTML checkboxes to your notes and makes them clickable.",
|
||||||
"author": "Anareaty",
|
"author": "Anareaty",
|
||||||
"authorUrl": "https://github.com/anareaty",
|
"authorUrl": "https://github.com/anareaty",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue