From the Rails console:
> content = "Lorem ipsum dolor sit <span class='class'>amet</span>."
> helper.highlight(content, "dolor")
=> "Lorem ipsum <strong class=\"highlight\">dolor</strong> sit <span class=\"class\">amet</span>."
However:
> content = "Lorem ipsum dolor sit <span id='id'>amet</span>."
> helper.highlight(content, "dolor")
=> "Lorem ipsum <strong class=\"highlight\">dolor</strong> sit <span>amet</span>."
As a matter of fact:
> content = "Lorem ipsum dolor sit <a href='http://127.0.0.1' class='class' id='id' style='color: #ffffff;' target='_blank' name='name' title='title'>amet</a>."
> helper.highlight(content, "dolor")
=> "Lorem ipsum <strong class=\"highlight\">dolor</strong> sit <a href=\"http://127.0.0.1\" class=\"class\" name=\"name\" title=\"title\">amet</a>."
So the highlight helper seems to selectively wipe some HTML-attributes in its process, but not all. Not that I care so much for target
or style
, but losing id
s is rather unfortunate.
Are there options I can pass into highlight
to prevent this from happening?