i can''t find a good documentation for Hpricot and aunt google won''t help either. so how do you remove html comments with Hpricot? i tried things like (html/''!'').remove but that doesnt seem to work at all. does anyone know? thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Gregory Seidman
2006-Dec-22 00:03 UTC
Re: Hpricot how to remove all comments from a document?
On Thu, Dec 21, 2006 at 12:08:27PM +0100, Ralf Vitasek wrote: } i can''t find a good documentation for Hpricot and aunt google won''t help } either. } } so how do you remove html comments with Hpricot? } } i tried things like (html/''!'').remove but that doesnt seem to work at } all. } } does anyone know? } thanks! class Hpricot::Doc def select_nodes selected = [] queue = children.reverse while node = queue.pop selected << node if yield node queue.push(*node.children.reverse) if node.respond_to? :children end selected end end def Hpricot.orphan_node(node) list = node.parent.children node.parent = nil list.delete(node) end doc = Hpricot(open(''filename.html'')) doc.select_nodes { |n| n.comment? }.each { |c| Hpricot.orphan_node(c) } --Greg --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---