Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Add in my validate script for posterity
Browse files Browse the repository at this point in the history
If you can figure out how to use it, good for you!
  • Loading branch information
sophiebits committed Feb 7, 2012
1 parent 04a2ad0 commit cefb84f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions build/validate.rb
@@ -0,0 +1,27 @@
require 'rubygems'
require 'validator.nu'
require 'json'
require 'pp'

files = Dir[File.join(File.dirname(__FILE__), '../exercises/*.html')]

files.each do |file|
name = File.basename(file, ".html")
if name =~ /^khan-(?:exercise|site)$/
puts "skipping #{name}"
next
end

doc = File.read(file)
doc.gsub!(/<(?!(?:\/?[a-z]+|!DOCTYPE|!--))/, '&lt;')
# doc.gsub!(/< /, '&lt;')
doc.gsub!(/&(?![a-z])/, '&amp;')
doc.gsub!(/ id=".+?"/, "")

output = JSON.parse(Validator.nu(doc, :host => '127.0.0.1', :port => 8888))

puts "#{name}" if output["messages"].length > 2
output["messages"][2..-1].each do |message|
puts "#{message["type"]} on line #{message["lastLine"]}: #{message["message"]}"[0..79]
end
end

0 comments on commit cefb84f

Please sign in to comment.