FIX: don't add diff classes more than once

This commit is contained in:
Régis Hanol 2018-04-16 15:41:45 +02:00
parent a4a0b8e922
commit 001b0710c7

View File

@ -184,8 +184,13 @@ class DiscourseDiff
# add it right before the ">" # add it right before the ">"
html_or_text.insert(index_of_next_chevron, " class=\"diff-#{klass}\"") html_or_text.insert(index_of_next_chevron, " class=\"diff-#{klass}\"")
else else
# we have a class, insert it at the beginning # we have a class, insert it at the beginning if not already present
html_or_text.insert(index_of_class + "class=".length + 1, "diff-#{klass} ") classes = html_or_text[/class=(["'])([^\1]*)\1/, 2]
if classes.include?("diff-#{klass}")
html_or_text
else
html_or_text.insert(index_of_class + "class=".length + 1, "diff-#{klass} ")
end
end end
else else
"<#{klass}>#{html_or_text}</#{klass}>" "<#{klass}>#{html_or_text}</#{klass}>"