Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes #50

Merged
merged 2 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,5 @@ stringq
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)


##
Expand All @@ -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

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
Loading