Skip to content

Commit

Permalink
fixes #64
Browse files Browse the repository at this point in the history
  • Loading branch information
fuhrmanator committed Jun 9, 2024
1 parent e072447 commit 0ce1e74
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions GIFT.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@
function resetLastQuestionTextFormat() {
format = defaultFormat;
}
function formattedText(format, txt) {
let inferredFormat = (format !== null ? format : getLastQuestionTextFormat());
let joinedText = txt.join('').trim();
console.log("format: " + inferredFormat + " text: " + joinedText);
return {
format:(inferredFormat),
text:(
((inferredFormat !== "html") && (inferredFormat !== "markdown")) ?
escapedCharacterDecode(removeNewLinesDuplicateSpaces(joinedText)) :
// trim and remove newlines for html and markdown
escapedCharacterDecode(joinedText)
)}
}
}

GIFTQuestions
Expand Down Expand Up @@ -286,22 +299,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

0 comments on commit 0ce1e74

Please sign in to comment.