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 ">"
html_or_text.insert(index_of_next_chevron, " class=\"diff-#{klass}\"")
else
# we have a class, insert it at the beginning
html_or_text.insert(index_of_class + "class=".length + 1, "diff-#{klass} ")
# we have a class, insert it at the beginning if not already present
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
else
"<#{klass}>#{html_or_text}</#{klass}>"