I need to remove newlines from any object / attachment tags. I am currently trying to do this using Nokogiri by following these steps:
s = "<div>
<object height='450' width='600'>
<param name='allowfullscreen' value='true'>
<param name='allowscriptaccess' value='always'>
<param name='movie' value='http://vimeo.com/moogaloop.swf?clip_id=3317924&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1'>
<embed src='http://vimeo.com/moogaloop.swf?clip_id=3317924&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1' type='application/x-shockwave-flash' allowfullscreen='true' allowscriptaccess='always' height='450' width='600'>
</embed>
</object>
</div>"
doc = Nokogiri::HTML(s)
doc.css('object').each { |o| o.inner_html.gsub!(/\n/, ""); puts o.inner_html }
Note that the example is for object tags only.
Printing o.inner_html at the end of the block indicates that no replacement has occurred, although the gsub text is displayed correctly. In addition, once this part is resolved, I need to make sure that the actual node object in the doc object is saved with the updated values.
Any help is most appreciated. Thank.
source
share