Skip to content

Instantly share code, notes, and snippets.

@kivikakk
Created August 10, 2017 03:11
Show Gist options
  • Select an option

  • Save kivikakk/f166e359ad5bed29ed2a4a1365f3f7b6 to your computer and use it in GitHub Desktop.

Select an option

Save kivikakk/f166e359ad5bed29ed2a4a1365f3f7b6 to your computer and use it in GitHub Desktop.
sourcepos verifier
#!/usr/bin/env ruby
require 'nokogiri'
doc = File.read(ARGV[0]).split("\n")
xml = Nokogiri::XML(`build/src/cmark-gfm -t xml --sourcepos #{ARGV[0]}`)
xml.css('text, code').each do |el|
from, to = el['sourcepos'].split('-').map {|r| r.split(':').map(&:to_i)}
if from[0] != to[0]
puts "Cannot verify #{[from, to].inspect}"
next
end
comp = doc[from[0] - 1].b[from[1] - 1..to[1] - 1].force_encoding('utf-8')
if comp.nil?
puts "#{[from, to].inspect}: got nil"
next
end
if el.name == 'text'
comp = comp.gsub(/\\(.)/, '\1')
else
comp = comp.strip
end
if el.inner_text != comp
puts "#{[from, to].inspect}: Expecting #{el.inner_text.inspect}, actual doc has #{comp.inspect}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment