YUI编辑器:摆脱< html>内容标签 [英] YUI Editor: Getting rid of <html> tags in content
问题描述
我实现了 YUI富文本编辑器,我想摆脱保存编辑器中的内容后,<html>
,<body>
和DOCTYPE
标记就会出现.我知道以后可以通过解析HTML来做到这一点,但是必须有一个更好的解决方案.
I implemented the YUI rich text editor and I would like to get rid of the <html>
, <body>
and DOCTYPE
tags as soon as I save the content from the editor. I know I could do this afterwards by parsing the HTML, but there must be a better solution.
现在,当我在YUI编辑器中编辑文本时,将保存该文件:
Right now this is saved when I edit a text in the YUI editor:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<body>
<p>foo</p>
</body>
</html>
...但是我只想保存:
...but I would like to just save this:
<p>foo</p>
有什么主意吗?
PS:我使用 yui_editor插件实现了YUI编辑器 ,但是也欢迎使用YUI编辑器的通用答案!
P.S.: I implemented the YUI editor using the yui_editor plugin for ruby on rails, but a YUI editor generic answer would be welcome too!
推荐答案
同时,我自己通过解析提交的html来解决了这个问题.是的,我知道,我最初并不是在寻找这种解决方案,但最终我得出的结论是,这是解决该问题的最简单方法.我使用 Nokogiri RubyGem 进行Rails解析:
In the meantime I solved the problem myself by parsing the html on submit. Yes I know, I wasn't looking for this solution at first, but finally I came to the conclusion that it is the easiest way to solve it. I used the Nokogiri RubyGem for Rails to do the parsing:
value = Nokogiri::HTML(yui_content).css('body').to_html
value.gsub!(/<body>/,'')
value.gsub!(/<\/body>/,'')
这篇关于YUI编辑器:摆脱< html>内容标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!