Forum: Ruby on Rails Hpricot how to remove all comments from a document?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
neongrau _. (Guest)
on 2006-12-21 13:08
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!
Gregory S. (Guest)
on 2006-12-22 02:04
(Received via mailing list)
On Thu, Dec 21, 2006 at 12:08:27PM +0100, Ralf V. 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
This topic is locked and can not be replied to.