require 'commonmarker'
HELP = "$ comrak --help\n"
CONTRIBUTORS = "<table id='contributors'></table>"
readme = File.read File.join(File.dirname(__FILE__), '../README.md')
contributors = File.read File.join(File.dirname(__FILE__), '../CONTRIBUTORS.txt')
contributors = contributors.split("\n").reject(&:empty?).sort_by(&:downcase).map do |login|
"<a class='contributors' title='#{login}' href='https://github.com/#{login}'><img width='64' src='https://github.com/#{login}.png' alt='#{login}'></a>"
end.join(' ')
doc = CommonMarker.render_doc(readme)
doc.walk do |node|
if node.type == :code_block && node.string_content.start_with?(HELP)
node.string_content = "#{HELP}#{`cargo run -- --help`}"
end
if node.type == :html && node.string_content.start_with?("<table id='contributors'>")
node.string_content = "#{CONTRIBUTORS}#{contributors}"
end
end
File.open(File.join(File.dirname(__FILE__), '../README.md'), 'w') do |f|
f.write doc.to_commonmark
end