Skip to content

Commit

Permalink
Merge pull request #50 from trevorgunn/smallfixes
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
jverzani authored Apr 21, 2024
2 parents 3a206a7 + 50547d2 commit 4e2fbef
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,5 @@ scriptq
fillblankq
hotspotq
plotlylightq
scorecard
```
11 changes: 7 additions & 4 deletions src/question_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@ abstract type Question end

mutable struct Stringq <: Question
re::Regex
filter::Regex
label
hint
explanation
placeholder
end

"""
stringq(re::Regex; label="", hint="", explanation="", placeholder="")
stringq(re::Regex; filter::Regex=r"", label="", hint="", explanation="", placeholder="")
Match string answer with regular expression
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
Expand All @@ -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)

##
mutable struct Scriptq <: Question
Expand Down Expand Up @@ -100,7 +103,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
Expand Down
2 changes: 1 addition & 1 deletion src/show_methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

0 comments on commit 4e2fbef

Please sign in to comment.