开发者

nokogiri and video tags

some pieces of HTML structure are stored on server. Before saving, they will be preprocessed.

Preprocessing inserts HTML 5 video tags to certain places.

I trying to do it, but, everytime i deal with video tags, i get following:

Tag video invalid

I think, they this is because of the HTML 4.0 DOCTYPE, that i saw in debugger:

< !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"

I also开发者_如何学编程 tried to use XML as a parser, but, i cannot figure out, how to obtain clean HTML code from Nokogiri::XML object.

Any ideas ?


First, you can use #to_html (or #to_xhtml) on an XML document. However, I'm not sure that's necessary here. I don't get any 'Tag video invalid' errors when creating elements. Here's a sample program showing how to parse existing HTML4, inject a video element, and get HTML out again:

require 'nokogiri'

html = Nokogiri::HTML <<ENDHTML
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
  <html><head><title>Sauceome</title></head>
  <body><p class="video" id="foo"><!-- put vid here--></p></body></html>
ENDHTML
wrap = html.at('.video')
wrap.inner_html="<video src='#{wrap['id']}.mov'></video>"

puts html.to_html
#=> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
#=> <html>
#=> <head>
#=> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
#=> <title>Sauceome</title>
#=> </head>
#=> <body><p class="video" id="foo"><video src="foo.mov"></video></p></body>
#=> </html>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜