Last active
May 26, 2020 03:48
-
-
Save kerotaa/5788650 to your computer and use it in GitHub Desktop.
A plugin that remove empty lines from HTML files on jekyll.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = /^[\s\t]*(\r\n|\r|\n)/ | |
tary.each_with_index { |e, i| | |
oary << ( i % 2 != 0 ? e : e.gsub(reg, '') ) | |
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