我正在使用HTML来清理Sanitize https://github.com/rgrove/sanitize,但我想允许一些自定义的自关闭标记。当我运行Sanitize.fragment方法时,我得到一个带有结束标记的html。例如:
Sanitize.fragment("<custom-tag> Text after tag", :elements => ['custom-tag'])
=> "<custom-tag> Text after tag</custom-tag>"我希望输出结果为"<custom-tag> Text after tag"
发布于 2014-07-07 00:47:06
Sanitize没有办法知道自定义标记是自动关闭的。
或者尝试使用<custom-tag />使标签自动关闭,或者直接gsub关闭结束标签:
str = Sanitize.fragment("<custom-tag> Text after tag", :elements => ['custom-tag'])
str.gsub(/<\/custom-tag>/,'')https://stackoverflow.com/questions/24598080
复制相似问题