From 99855b2a45b6d3eecb040ab6c442a2c9e63cb92a Mon Sep 17 00:00:00 2001 From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de> Date: Thu, 16 May 2024 15:55:06 +0200 Subject: [PATCH] allow `]]` in cloze_exercise, fixes #138 --- exercises/cloze_exercise.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/cloze_exercise.php b/exercises/cloze_exercise.php index b2852d5..9843971 100644 --- a/exercises/cloze_exercise.php +++ b/exercises/cloze_exercise.php @@ -369,7 +369,7 @@ class cloze_exercise extends Exercise foreach ($this->task['answers'][$blank] as $answer) { $answer_text = $answer['text']; - if (preg_match('/^([":*~]|$|.*\|)/', $answer_text)) { + if (preg_match('/^$|^[":*~]|\||\]\]/', $answer_text)) { $answer_text = '"' . $answer_text . '"'; } @@ -406,7 +406,7 @@ class cloze_exercise extends Exercise $question = Studip\Markup::purifyHtml($question); // $question_array contains text elements and blanks (surrounded by [[ and ]]). - $parts = preg_split('/(\[\[.*?\]\])/s', $question, -1, PREG_SPLIT_DELIM_CAPTURE); + $parts = preg_split('/(\[\[(?:".*?"|.)*?\]\])/s', $question, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ($parts as $part) { if (preg_match('/^\[\[(.*)\]\]$/s', $part, $matches)) { @@ -424,7 +424,7 @@ class cloze_exercise extends Exercise } if ($part !== '') { - preg_match_all('/( *[*~]?".*?" *|[^|]*)\|/', $part . '|', $matches); + preg_match_all('/((?:".*?"|[^|])*)\|/', $part . '|', $matches); foreach ($matches[1] as $answer) { $answer = trim($answer); -- GitLab