Skip to content

Instantly share code, notes, and snippets.

@cameronelliott
Forked from kerotaa/remove-empty-lines-html.rb
Last active August 29, 2015 14:09
Show Gist options
  • Save cameronelliott/15604673eabc10e006fe to your computer and use it in GitHub Desktop.
Save cameronelliott/15604673eabc10e006fe to your computer and use it in GitHub Desktop.
module Jekyll
module Convertible
def write(dest)
path = destination(dest)
FileUtils.mkdir_p(File.dirname(path))
if File.extname(path).downcase == '.html' then
self.output.strip!
reg = /<\/?pre[^>]*>/i
pres = self.output.scan(reg)
tary = self.output.split(reg)
oary = []
reg = /\n/
tary.each_with_index { |e, i|
oary << ( i % 2 != 0 ? e : e.gsub(reg, '\r\n') )
oary << pres[i] if pres.size > i
}
self.output = oary.join('')
end
File.open(path, 'w') do |f|
f.write( self.output )
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment