HTML cleanup task

Hi all.

Sorry, if the question seems dumb.

My task is: I have some HTML fragment; no limitations on it correctness,
except of there can’t be tag cutted:
This is possible: […] (fragment starts with closing tag)
This is not: [tr>…]

I need to do tasks:

  • Cut some tags with those contents, for ex., all tables
    [beforeinside
    after] => [before after]
  • cut some tags, leaving content:
    [before
    after] => [before after]
  • other tags to make “consistent”:
    [beforeafter] => [before after]
    [

    before

    after] => [

    before

    after]
  • Can it be done with Hpricot? Or any other options?

    Thanks.

    V.