diff --git a/docs/src/index.md b/docs/src/index.md index 473f6d7..61b91fa 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -238,4 +238,5 @@ stringq fillblankq hotspotq plotlylightq +scorecard ``` diff --git a/src/question_types.jl b/src/question_types.jl index f56c5ea..8b6725f 100644 --- a/src/question_types.jl +++ b/src/question_types.jl @@ -2,6 +2,7 @@ abstract type Question end mutable struct Stringq <: Question re::Regex + filter::Regex label hint explanation @@ -9,7 +10,7 @@ mutable struct Stringq <: Question end """ - stringq(re::Regex; label="", hint="", explanation="", placeholder="") + stringq(re::Regex; filter::Regex=r"", label="", hint="", explanation="", placeholder="") Match string answer with regular expression @@ -17,6 +18,8 @@ Arguments: * `re`: a regular expression for grading +* `filter`: a regular expression for what to remove from the string before matching (e.g. `r"\\s"` to remove whitespace) + * `label`: optional label for the form element * `hint`: optional plain-text hint that can be seen on hover @@ -33,8 +36,8 @@ stringq(re, label="First 3 letters...") ``` """ -stringq(re::Regex; label="", hint="", explanation="", placeholder=nothing) = - Stringq(re, label, hint, explanation, placeholder) +stringq(re::Regex; filter::Regex=r"", label="", hint="", explanation="", placeholder=nothing) = + Stringq(re, filter, label, hint, explanation, placeholder) ## @@ -57,7 +60,7 @@ Arguments: * `value`: the numeric answer -* `atol`: ``|answer - value| \\le atol`` is used to determine correctness +* `atol`: ``|\\mathrm{answer} - \\mathrm{value}| \\le \\mathrm{atol}`` is used to determine correctness * `label`: optional label for the form element diff --git a/src/show_methods.jl b/src/show_methods.jl index a4068e0..7cbf149 100644 --- a/src/show_methods.jl +++ b/src/show_methods.jl @@ -81,7 +81,7 @@ function prepare_question(x::Stringq, ID) GRADING_SCRIPT = Mustache.render(html_templates["input_grading_script"]; ID = ID, - CORRECT_ANSWER = """RegExp('$(x.re.pattern)').test(this.value)""", + CORRECT_ANSWER = """RegExp('$(x.re.pattern)').test(this.value.replaceAll(RegExp('$(x.filter.pattern)', 'g'), ''))""", INCORRECT = "Incorrect", CORRECT = "Correct" )