Skip to content

Instantly share code, notes, and snippets.

@mislav
Created June 27, 2009 13:57
Show Gist options
  • Save mislav/137005 to your computer and use it in GitHub Desktop.
Save mislav/137005 to your computer and use it in GitHub Desktop.
monkeypatch for Haml to skip certain closing tags
require 'haml'
Haml::Engine.class_eval do
HTML_SKIP_CLOSING = %(body br col colgroup dd dt head hr html img input li link
meta option p param tbody td tfoot th thead tr)
def push_merged_text(text, tab_change = 0, indent = true)
if @options[:ugly] and html4? and text =~ %r{(.*)</([a-zA-Z])>(\s*)\Z}
content, tag, padding = $1, $2.downcase, $3
if HTML_SKIP_CLOSING.include?(tag)
text = (content.nil? or content.empty?) ? '' : content + padding
end
end
super(text, tab_change, indent)
end
end
puts Haml::Engine.new(<<-HAML, :ugly => true, :format => :html4).to_html
%div
%p Foo
%p
Bar
HAML
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment