require 'find'
require 'nokogiri'
def check_indent(file)
doc = Nokogiri::HTML(File.open(file))
ec = false
doc.css('div.language-plaintext.highlighter-rouge div.highlight pre.highlight code').each do |pre|
content = pre.text
lines = content.split("\n")
if lines.all? { |line| line =~ %r{://} }
lines.each do |line|
if line =~ /^\s+/
puts "#{file}: Indentation error: #{line}"
ec = true
end
end
end
end
ec
end
should_exit = false
Find.find('./_site/training-material/topics/') do |path|
if path =~ (/tutorial.*\.html$/) && check_indent(path)
should_exit = true
end
end
if should_exit
exit 1
end