mirror of
https://github.com/discourse/discourse.git
synced 2025-04-09 10:10:49 +08:00
This reverts commit 20d4093a673f45d7efa7f00dbbe6f563c1ca4598.
This commit is contained in:
parent
cf99431c18
commit
9adfd66a8b
@ -176,25 +176,24 @@ class DiscourseDiff
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_class_or_wrap_in_tags(html_or_text, klass)
|
def add_class_or_wrap_in_tags(html_or_text, klass)
|
||||||
dupped_html_or_text = html_or_text.dup
|
index_of_next_chevron = html_or_text.index(">")
|
||||||
index_of_next_chevron = dupped_html_or_text.index(">")
|
if html_or_text.length > 0 && html_or_text[0] == '<' && index_of_next_chevron
|
||||||
if dupped_html_or_text.length > 0 && dupped_html_or_text[0] == '<' && index_of_next_chevron
|
index_of_class = html_or_text.index("class=")
|
||||||
index_of_class = dupped_html_or_text.index("class=")
|
|
||||||
if index_of_class.nil? || index_of_class > index_of_next_chevron
|
if index_of_class.nil? || index_of_class > index_of_next_chevron
|
||||||
# we do not have a class for the current tag
|
# we do not have a class for the current tag
|
||||||
# add it right before the ">"
|
# add it right before the ">"
|
||||||
dupped_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 if not already present
|
# we have a class, insert it at the beginning if not already present
|
||||||
classes = dupped_html_or_text[/class=(["'])([^\1]*)\1/, 2]
|
classes = html_or_text[/class=(["'])([^\1]*)\1/, 2]
|
||||||
if classes.include?("diff-#{klass}")
|
if classes.include?("diff-#{klass}")
|
||||||
dupped_html_or_text
|
html_or_text
|
||||||
else
|
else
|
||||||
dupped_html_or_text.insert(index_of_class + "class=".length + 1, "diff-#{klass} ")
|
html_or_text.insert(index_of_class + "class=".length + 1, "diff-#{klass} ")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
"<#{klass}>#{dupped_html_or_text}</#{klass}>"
|
"<#{klass}>#{html_or_text}</#{klass}>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user