Index: lams_common/src/java/org/lamsfoundation/lams/questions/QuestionWordParser.java =================================================================== diff -u -r66f5fedfc2d2bd00ed1889b62378782365ba2719 -r313df184c7e7f788cca5c101e266e39f1a543449 --- lams_common/src/java/org/lamsfoundation/lams/questions/QuestionWordParser.java (.../QuestionWordParser.java) (revision 66f5fedfc2d2bd00ed1889b62378782365ba2719) +++ lams_common/src/java/org/lamsfoundation/lams/questions/QuestionWordParser.java (.../QuestionWordParser.java) (revision 313df184c7e7f788cca5c101e266e39f1a543449) @@ -147,6 +147,7 @@ List learningOutcomes = new ArrayList<>(); boolean optionsStarted = false; + boolean feedbackStarted = false; boolean isMultipleResponse = false; boolean answerTagFound = false; for (Node questionParagraph : questionParagraphs) { @@ -156,8 +157,13 @@ String text = questionParagraph.getTextContent().strip().toLowerCase(); boolean isTypeParagraph = "p".equals(questionParagraph.getNodeName()); + if (StringUtils.isBlank(text) && !questionParagraph.hasChildNodes()) { + //skip empty paragraphs + continue; + } + // check if answers section started - if (isTypeParagraph && text.matches("^[a-z]\\).*")) { + if (!feedbackStarted && isTypeParagraph && text.matches("^[a-z]\\).*")) { optionsStarted = true; //process a-z) answers @@ -174,9 +180,10 @@ // check if correct answer line is found if (text.startsWith(ANSWER_TAG)) { optionsStarted = true; + feedbackStarted = false; answerTagFound = true; - String correctAnswerLetters = text.substring(ANSWER_TAG.length()).replaceAll("\\s", ""); + String correctAnswerLetters = text.replaceAll("(?i)" + ANSWER_TAG, "").replaceAll("\\s", ""); String[] correctAnswersTable = correctAnswerLetters.split(","); for (String correctAnswerLetter : correctAnswersTable) { @@ -195,30 +202,36 @@ continue; } - if (text.startsWith(FEEDBACK_TAG)) { + if (text.startsWith(LEARNING_OUTCOME_TAG)) { optionsStarted = true; + feedbackStarted = false; - feedback = feedback == null - ? WebUtil.removeHTMLtags(formattedText).strip().substring(FEEDBACK_TAG.length()).strip() - : feedback + formattedText; + String learningOutcome = WebUtil.removeHTMLtags(formattedText) + .replaceAll("(?i)" + LEARNING_OUTCOME_TAG + "\\s*", "").strip(); + learningOutcomes.add(learningOutcome); + continue; } - if (text.startsWith(LEARNING_OUTCOME_TAG)) { + if (text.startsWith(FEEDBACK_TAG)) { optionsStarted = true; + feedbackStarted = true; + } - String learningOutcome = WebUtil.removeHTMLtags(formattedText).strip() - .substring(LEARNING_OUTCOME_TAG.length()).strip(); - learningOutcomes.add(learningOutcome); + if (feedbackStarted) { + String strippedFormattedText = formattedText.replaceAll("(?i)" + FEEDBACK_TAG + "\\s*", "").strip(); + feedback = feedback == null ? strippedFormattedText : feedback + strippedFormattedText; + continue; } - // if we are still before all options and no answers section started, - // then interpret it as question title or description if (!optionsStarted) { + // if we are still before all options and no answers section started, + // then interpret it as question title or description if (text.startsWith(QUESTION_TAG)) { - title = text.substring(QUESTION_TAG.length()).strip(); + title = WebUtil.removeHTMLtags(formattedText).replaceAll("(?i)" + QUESTION_TAG + "\\s*", "") + .strip(); continue; } - description = description == null ? formattedText : description + formattedText; + description = description == null ? formattedText.strip() : description + formattedText.strip(); } }