Skip to content

Instantly share code, notes, and snippets.

@fracai
Created July 19, 2014 02:44
Show Gist options
  • Save fracai/498031ea6f6dbb8fa243 to your computer and use it in GitHub Desktop.
Save fracai/498031ea6f6dbb8fa243 to your computer and use it in GitHub Desktop.
A nanoc filter for stripping blank lines.
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