wiki:TorWeeklyNews/Linkify
#!/usr/bin/ruby
# -*- coding: utf-8 -*-

lines = $stdin.readlines

refs = {}
lines.each do |line|
  next unless line =~ /^  *\[(\d+)\]:[  ](http.+)$/
  refs[$1] = $2.strip
end

lines.each do |line|
  next if line =~ /^  *\[(\d+)\]:[  ](http.+)$/
  line.gsub!(/\[(\d+)\]/) do
    "<a href=\"#{refs[$1]}\"></a>"
  end
  $stdout.write line
end
Last modified 4 years ago Last modified on Feb 19, 2014, 4:36:35 PM