Created
September 15, 2017 18:24
-
-
Save elliottwilliams/c672bc822d7a527868d1c590016887f6 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'set' | |
# Searches through the given markdown files to find reference-style links that | |
# are not defined. | |
abort "Usage: unlinked.rb [files...]" if ARGV.empty? | |
ARGV.each do |filename| | |
defs = Set.new | |
reqs = Set.new | |
open(filename) do |file| | |
contents = file.read | |
contents.scan(/^\[(\w+)\]:/) { |l| defs << l } | |
contents.scan(/\[[^\]]+\]\[([^\]]+)\]/) { |l| reqs << l } | |
end | |
diff = reqs - defs | |
abort "#{filename} does not define: #{diff.to_a.join(', ')}" unless diff.empty? | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment