diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2026-10-17 21:41:18 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2026-10-17 22:23:21 +0200 |
| commit | deea01db9a5116376dde8343e4f406bbea4e3507 (patch) | |
| tree | 0072fa4b3e245bc052c621e813abd7dba51661aa | |
| parent | 0ab311f66d6f3cb0b4d87c47e082d53fd67bb502 (diff) | |
| download | unterricht-deea01db9a5116376dde8343e4f406bbea4e3507.tar.gz unterricht-deea01db9a5116376dde8343e4f406bbea4e3507.zip | |
moodle-quiz: add support for multichoice questions
| -rw-r--r-- | pandoc/filters/moodle-quiz.lua | 66 |
1 files changed, 55 insertions, 11 deletions
diff --git a/pandoc/filters/moodle-quiz.lua b/pandoc/filters/moodle-quiz.lua index ab26f93c..92a4e893 100644 --- a/pandoc/filters/moodle-quiz.lua +++ b/pandoc/filters/moodle-quiz.lua @@ -15,6 +15,19 @@ local concat = function(inlines) return s end +local function find_answer_attributes(answer) + local attributes = {} + answer:walk({Span=function(s) + if #s.classes > 0 then -- this is not the attribute span + return + end + for k, v in pairs(s.attributes) do + attributes[k] = v + end + end}) + return attributes +end + local function detect_question_type(question) local ret = "" if question.header.classes:includes("shortanswer") then @@ -27,12 +40,11 @@ local function detect_question_type(question) return ret end -local function write_shortanwser_answers(question) - local ret = "" - local a = function(s) ret = ret .. s end - +local function write_answers(question, default_fraction, a) for _, answer in ipairs(question.answers) do - a(' <answer fraction="100" format="html">\n') + local answer_attributes = find_answer_attributes(answer) + local frac = answer_attributes.fraction or default_fraction + a(' <answer fraction="'..frac..'" format="html">\n') a(' <text><![CDATA['); a(pandoc.write(pandoc.Pandoc(answer), "html")) a(']]></text>\n') @@ -44,11 +56,43 @@ local function write_shortanwser_answers(question) end a(' </answer>\n') end - return ret end -local write_answers_for = { - shortanswer = write_shortanwser_answers, +local function write_shortanwser(question, a) + a(' <usecase>0</usecase>\n') + write_answers(question, 100, a) +end + +local function write_multichoice(question, a) + local fractions = 0 + for _, answ in ipairs(question.answers) do + local answer_attributes = find_answer_attributes(answ) + if answer_attributes.fraction and tonumber(answer_attributes.fraction) > 0 then + fractions = fractions + 1 + end + end + + a(' <single>'..(fractions == 1 and "true" or "false")..'</single>') + a(' <shuffleanswers>true</shuffleanswers>') + a(' <answernumbering>none</answernumbering>') + a(' <showstandardinstruction>0</showstandardinstruction>') + a(' <correctfeedback format="html">') + a(' <text><![CDATA[<p>Die Antwort ist richtig.</p>]]></text>') + a(' </correctfeedback>') + a(' <partiallycorrectfeedback format="html">') + a(' <text><![CDATA[<p>Die Antwort ist teilweise richtig.</p>]]></text>') + a(' </partiallycorrectfeedback>') + a(' <incorrectfeedback format="html">') + a(' <text><![CDATA[<p>Die Antwort ist falsch.</p>]]></text>') + a(' </incorrectfeedback>') + a(' <shownumcorrect/>') + + write_answers(question, 0, a) +end + +local write_question_for = { + shortanswer = write_shortanwser, + multichoice = write_multichoice, } local function write_questions() @@ -79,10 +123,10 @@ local function write_questions() a(' <penalty>0.3333333</penalty>\n') a(' <hidden>0</hidden>\n') a(' <idnumber></idnumber>\n') - a(' <usecase>0</usecase>\n') - local answer_fn = write_answers_for[question_type] - a(answer_fn(question)) + -- questiontype specific tags + local question_type_fn = write_question_for[question_type] + question_type_fn(question, a) a('</question>\n') end |
