diff --git a/GIFT.pegjs b/GIFT.pegjs index 0665326..d5e13ce 100644 --- a/GIFT.pegjs +++ b/GIFT.pegjs @@ -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 @@ -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())}