diff --git a/lib/Note.lib.php b/lib/Note.lib.php index bb51a8a..c490278 100644 --- a/lib/Note.lib.php +++ b/lib/Note.lib.php @@ -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));