Posted By

tonic on 07/22/09


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

webstic


Expresiones regulares para borrar saltos de línea en código HTML


 / Published in: Ruby
 

URL: http://gist.github.com/151875

  1. # Borramos los párrafos en blanco
  2. text.gsub!(/<p(.)*>(\s)*(<br(\s)*(\/)*>)*(\s)*(&nbsp;)*<\/p>/) { |match| match = ""}
  3. # Luego borramos los divs que se hayan quedado vacíos
  4. text.gsub!(/<div(.)*>(\s)*(<br(\s)*(\/)*>)*(\s)*(&nbsp;)*<\/div>/) { |match| match = ""}
  5. # Y terminamos borrando todo lo que sobra entre etiquetas
  6. text.gsub!(/>(\s)*(<br(\s)*(\/)*>)*(\s)*(&nbsp;)*</) { |match| match = ">\n<"}

Report this snippet  

You need to login to post a comment.