Skip to content

Commit

Permalink
Merge pull request #63 from livinNector/true-false-disambiguity
Browse files Browse the repository at this point in the history
fix: refactored incorrectFeedback and correctFeedback to TrueFeedback…
  • Loading branch information
fuhrmanator authored Aug 16, 2024
2 parents af55489 + 9bd5925 commit 7b088e2
Show file tree
Hide file tree
Showing 28 changed files with 6,725 additions and 5,319 deletions.
8 changes: 4 additions & 4 deletions GIFT.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
switch(question.type) {
case "TF":
question.isTrue = answers.isTrue;
question.incorrectFeedback = answers.feedback[1];
question.correctFeedback = answers.feedback[2];
question.trueFeedback = answers.feedback[0];
question.falseFeedback = answers.feedback[1];
break;
case "MC":
case "Numerical":
Expand Down Expand Up @@ -148,7 +148,7 @@ Match "match"
///////////
TrueFalseAnswer "{T} or {F} or {TRUE} or {FALSE}"
= isTrue:TrueOrFalseType _
feedback:(_ Feedback? Feedback?) _
feedback:(Feedback? Feedback?) _
globalFeedback:GlobalFeedback?
{ return { type:"TF", isTrue: isTrue, feedback:feedback, globalFeedback:globalFeedback}; }

Expand Down Expand Up @@ -367,4 +367,4 @@ Space "(space)"
EndOfLine "(end of line)"
= '\r\n' / '\n' / '\r'
EndOfFile
= !. { return "EOF"; }
= !. { return "EOF"; }
6 changes: 5 additions & 1 deletion docs/editor/giftPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ function giftPreviewHTML(qArray, theDiv) {
break;
case "TF":
html += makeTitle("True/False", q.title);
html += pStemOpen + "<em class='d-print-none'>(" + (q.isTrue ? "True" : "False") + ") </em>" + applyFormat(q.stem) + " (✓ ✘)" + pStemClose;
html += pStemOpen + "<em class='d-print-none'>(" +
(q.isTrue ? "True" : "False") + ") " +
(q.trueFeedback ? " True feedback: " + applyFormat(q.trueFeedback, false) + "</div>" : "") +
(q.falseFeedback ? " False feedback: " + applyFormat(q.falseFeedback, false) + "</div>" : "") +
"</em>" + pStemOpen + applyFormat(q.stem) + " (✓ ✘)" + pStemClose;
html += formatFeedback(q.globalFeedback) + "</div>";
theDiv.append(html); html = "";
break;
Expand Down
38 changes: 20 additions & 18 deletions docs/editor/lib/GIFT.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
switch(question.type) {
case "TF":
question.isTrue = answers.isTrue;
question.incorrectFeedback = answers.feedback[1];
question.correctFeedback = answers.feedback[2];
question.trueFeedback = answers.feedback[0];
question.falseFeedback = answers.feedback[1];
break;
case "MC":
case "Numerical":
Expand Down Expand Up @@ -70,6 +70,20 @@
function resetLastQuestionTextFormat() {
format = defaultFormat;
}
function formattedText(format, txt) {
let inferredFormat = (format !== null ? format : getLastQuestionTextFormat());
let joinedText = txt.join('')
.replace(/\r\n/g, '\n') // replace Windows newlines with Unix newlines
.trim();
return {
format:(inferredFormat),
text:(
((inferredFormat == "html") || (inferredFormat == "markdown")) ?
// keep whitespace and newlines for html and markdown
escapedCharacterDecode(joinedText) :
escapedCharacterDecode(removeNewLinesDuplicateSpaces(joinedText))
)}
}
}

GIFTQuestions
Expand Down Expand Up @@ -134,7 +148,7 @@ Match "match"
///////////
TrueFalseAnswer "{T} or {F} or {TRUE} or {FALSE}"
= isTrue:TrueOrFalseType _
feedback:(_ Feedback? Feedback?) _
feedback:(Feedback? Feedback?) _
globalFeedback:GlobalFeedback?
{ return { type:"TF", isTrue: isTrue, feedback:feedback, globalFeedback:globalFeedback}; }

Expand Down Expand Up @@ -286,22 +300,10 @@ ControlChar
= '=' / '~' / "#" / '{' / '}' / '\\' / ':'

MatchRichText "(formatted text excluding '->')"
= format:Format? _ txt:MatchTextChar+ { return {
format:(format!==null ? format : getLastQuestionTextFormat()),
text:(
(format !== "html" && format !== "markdown") ?
escapedCharacterDecode(removeNewLinesDuplicateSpaces(txt.join('').trim())) :
escapedCharacterDecode(txt.join('')).replace(/\r\n/g,'\n').trim()
)}} // avoid failing tests because of Windows line breaks
= format:Format? _ txt:MatchTextChar+ { return formattedText(format, txt) }

RichText "(formatted text)"
= format:Format? _ txt:TextChar+ { return {
format:(format!==null ? format : getLastQuestionTextFormat()),
text:(
(format !== "html" && format !== "markdown") ?
escapedCharacterDecode(removeNewLinesDuplicateSpaces(txt.join('').trim())) :
escapedCharacterDecode(txt.join('')).replace(/\r\n/g,'\n').trim() // avoid failing tests because of Windows line breaks
)}}
= format:Format? _ txt:TextChar+ { return formattedText(format, txt) }

PlainText "(unformatted text)"
= txt:TextChar+ { return removeNewLinesDuplicateSpaces(txt.join('').trim())}
Expand Down Expand Up @@ -365,4 +367,4 @@ Space "(space)"
EndOfLine "(end of line)"
= '\r\n' / '\n' / '\r'
EndOfFile
= !. { return "EOF"; }
= !. { return "EOF"; }
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ export interface Essay extends Question {
export interface TrueFalse extends Question {
type: Extract<QuestionType, "TF">;
isTrue: boolean;
incorrectFeedback: TextFormat | null;
correctFeedback: TextFormat | null;
trueFeedback: TextFormat | null;
falseFeedback: TextFormat | null;
}

export interface Matching extends Question {
Expand Down
Loading

0 comments on commit 7b088e2

Please sign in to comment.