Created
July 19, 2014 02:44
-
-
Save fracai/498031ea6f6dbb8fa243 to your computer and use it in GitHub Desktop.
A nanoc filter for stripping blank lines.
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 Nanoc::Filters | |
class StripBlankLines < Nanoc::Filter | |
identifier :strip_blank_lines | |
def run(content, params={}) | |
count_pre = 0 | |
content.split("\n").each do |line| | |
line << "\n" | |
line.match('<pre>') { |m| count_pre +=1 } | |
line.match('</pre>') { |m| count_pre -=1 } | |
line.match('<code>') { |m| count_pre +=1 } | |
line.match('</code>') { |m| count_pre -=1 } | |
# if we're inside any number of <pre> blocks, skip the reduction | |
if 0 == count_pre | |
line.gsub!(/^\s*$/,'') # zap empty lines | |
end | |
end.join('') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment