diff --git a/lib/quiz_math_data_fixup.rb b/lib/quiz_math_data_fixup.rb
index a6ce656b54e..230cb3d2974 100644
--- a/lib/quiz_math_data_fixup.rb
+++ b/lib/quiz_math_data_fixup.rb
@@ -25,7 +25,7 @@ module QuizMathDataFixup
else
questions = quiz_or_bank.quiz_questions
end
- questions = questions.where("updated_at>?", check_date) if check_date
+ questions = questions.where('updated_at>?', check_date) if check_date
questions.find_each do |quiz_question|
begin
old_data = quiz_question.question_data.to_hash
@@ -63,13 +63,21 @@ module QuizMathDataFixup
end
def fixup_question_data(data)
- %i(neutral_comments_html correct_comments_html incorrect_comments_html).each do |key|
- if data[key].present?
- data[key] = fixup_html(data[key])
- end
+ %i[neutral_comments_html correct_comments_html incorrect_comments_html].each do |key|
+ data[key] = fixup_html(data[key]) if data[key].present?
end
data[:answers].each_with_index do |answer, index|
- %i(html comments_html).each { |key| answer[key] = fixup_html(answer[key]) if answer[key].present? }
+ %i[html comments_html].each do |key|
+ # if there's html, the text field is used as the title attribute/tooltip
+ # clear it out if we updated the html because it's probably hosed.
+
+ if answer[key].present?
+ answer[key] = fixup_html(answer[key])
+
+ text_key = key.to_s.sub(/html/, 'text')
+ answer[text_key] = '' if answer[text_key].present?
+ end
+ end
data[:answers][index] = answer
end
data
@@ -78,17 +86,28 @@ module QuizMathDataFixup
def fixup_html(html)
return html unless html
html = Nokogiri::HTML::DocumentFragment.parse(html)
- html.search('[id^="MathJax"]').each(&:remove)
if html.children.length == 1 && html.children[0].node_type == Nokogiri::XML::Node::TEXT_NODE
+ # look for an equation_images URL in the text and extract the latex
m = %r{equation_images\/([^\s]+)}.match(html.content)
if m && m[1]
code = URI.unescape(URI.unescape(m[1]))
html =
- ""
+ }' data-equation-content='#{code}'/>"
+ else
+ # look for \(inline latex\) and extract it
+ m = html.content.match(/\\\(((?!\\\)).+)\\\)/)
+ if m && m[1]
+ code = URI.unescape(URI.unescape(m[1]))
+ html =
+ ""
+ end
end
- return html
+ html.search('[id^="MathJax"]').each(&:remove)
+ return html.to_s
end
html.search('.math_equation_latex').each do |latex|
# find MathJax generated children, extract the eq's mathml
@@ -107,17 +126,16 @@ module QuizMathDataFixup
latex.replace(
""
)
elsif mml
latex.replace(
- ""
+ ""
)
end
end
+ html.search('[id^="MathJax"]').each(&:remove)
html.search('span.hidden-readable').each(&:remove)
html.to_s
@@ -128,6 +146,8 @@ module QuizMathDataFixup
end
def check_or_fix_question_banks(batch_of_ids)
- AssessmentQuestionBank.where(id: batch_of_ids).find_each { |q| fixup_quiz_questions_with_bad_math(q, question_bank: true) }
+ AssessmentQuestionBank.where(id: batch_of_ids).find_each do |q|
+ fixup_quiz_questions_with_bad_math(q, question_bank: true)
+ end
end
end
diff --git a/lib/user_content.rb b/lib/user_content.rb
index bbed9d5baad..2040eb3b71a 100644
--- a/lib/user_content.rb
+++ b/lib/user_content.rb
@@ -67,7 +67,7 @@ module UserContent
# inadvertently saved the hidden-readable span, causing
# them to multiply everytime the entity is edited.
# Strip the ones that shouldn't be there before adding a new one
- node.next.remove while node.next && node.next['class'] == 'hidden-readable'
+ node.next_element.remove while node.next_element && node.next_element['class'] == 'hidden-readable'
if !use_updated_math_rendering
mathml = UserContent.latex_to_mathml(equation)