Add fromChecklist()

master
Skylar Ittner 5 years ago
parent 6cb23163bf
commit 1d6b6d3afd

@ -196,7 +196,7 @@ class Note {
$title = preg_replace([
"/^- \[ \] /m",
"/^- \[x\] /m"
], "", $title);
], "", $title);
return trim($title);
}
@ -326,6 +326,14 @@ class Note {
$this->setText(implode("\n", $text));
}
/**
* Remove checklist markup from the note.
*/
public function fromChecklist() {
$text = preg_replace("/^- \[[ x]\] /im", "", $this->getText());
$this->setText($text);
}
/**
* Toggle the checked status of a checklist item.
* @param string $item The text of the item to toggle.
@ -334,17 +342,17 @@ class Note {
$text = explode("\n", $this->getText());
$item = trim(str_replace("\n", "", $item));
for ($i = 0; $i < count($text); $i++) {
if (!preg_match("/^- \[[x ]\] .*/", $text[$i])) {
if (!preg_match("/^- \[[x ]\] .*/i", $text[$i])) {
continue;
}
$linecleaned = trim(preg_replace("/^- \[[x ]\] /", "", $text[$i]));
$linecleaned = trim(preg_replace("/^- \[[x ]\] /i", "", $text[$i]));
if ($item != $linecleaned) {
continue;
}
if (preg_match("/^- \[[x]\] .*/", $text[$i])) {
$text[$i] = preg_replace("/^- \[[x]\] /", "- [ ] ", $text[$i]);
} else if (preg_match("/^- \[ \] .*/", $text[$i])) {
$text[$i] = preg_replace("/^- \[ \] /", "- [x] ", $text[$i]);
if (preg_match("/^- \[[x]\] .*/i", $text[$i])) {
$text[$i] = preg_replace("/^- \[[x]\] /i", "- [ ] ", $text[$i]);
} else if (preg_match("/^- \[ \] .*/i", $text[$i])) {
$text[$i] = preg_replace("/^- \[ \] /i", "- [x] ", $text[$i]);
}
}
$this->setText(implode("\n", $text));

Loading…
Cancel
Save