From 1e6ae5bef7d79f8f58daa48a96d61ee1e89c9722 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic <philip.kaludercic@fau.de> Date: Mon, 15 Jan 2024 14:11:24 +0100 Subject: [PATCH] Allow folding questions and answers over multiple lines --- gen.pl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/gen.pl b/gen.pl index d7699f1..92da06e 100755 --- a/gen.pl +++ b/gen.pl @@ -50,9 +50,8 @@ while (<>) { my $any = 0; foreach my $opt (@options) { - # unless (defined $opt->{"correct"}) { - # die "undefined \"$question\" ($ARGV:$.)\n"; - # } + $opt->{"option"} = md($opt->{"option"}) + if $opt->{"option"}; $any = 1 if (not (defined $opt->{"correct"})) or ($opt->{"correct"} eq JSON::true); } die "no correct option at \"$question\" ($ARGV)\n" @@ -80,9 +79,12 @@ while (<>) { $question = $2; chomp $question; - - $source = $3; - chomp $source if $source; + } elsif (/^[|](.+)/) { + if ($last_option{"option"}) { + $last_option{"option"} .= $1; + } else { + $question .= $1; + } } elsif (/^@(.*)/) { $media = $1; chomp $media; @@ -90,7 +92,7 @@ while (<>) { add(); %last_option = ( - "option" => md($2), + "option" => $2, "correct" => $1 eq "+" ? JSON::true : $1 eq "-" ? JSON::false : JSON::null ); } elsif (/^.+$/) { # non-empty line -- GitLab