[英]Highlight helper wipes HTML attributes
From the Rails console: 在Rails控制台中:
> 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. 因此,突出显示助手似乎在其过程中选择性地擦除了一些HTML属性,但不是全部。 Not that I care so much for
target
or style
, but losing id
s is rather unfortunate. 我并不是很在乎
target
或style
,但是不幸的是丢失id
。
Are there options I can pass into highlight
to prevent this from happening? 是否有选择,我可以传递到
highlight
,以防止这种情况发生?
You need to pass sanitize: false
as an option: 您需要通过
sanitize: false
选项:
2.0.0-p247 :001 > content = "Lorem ipsum dolor sit <span id='id'>amet</span>."
=> "Lorem ipsum dolor sit <span id='id'>amet</span>."
2.0.0-p247 :002 > helper.highlight(content, 'dolor', sanitize: false)
=> "Lorem ipsum <mark>dolor</mark> sit <span id='id'>amet</span>."
The sanitize helper is documented here and most of the text helpers will sanitize the content by default. 此处记录了清理助手,默认情况下,大多数文本助手将清理内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.