wiki:TorWeeklyNews/Numerize
#!/usr/bin/ruby
# -*- encoding: utf-8 -*-
#
# numerize.rb: number TWN references
#
# Copyright © 2013 Lunar <lunar@torproject.org>
# Licensed under WTFPL — http://www.wtfpl.net/txt/copying/

ref_index = 1
note_index = 1
$stdin.readlines.each do |line|
  case line
  when /^ *\[XXX\]\:[  ]/
    line.gsub!(/ *\[XXX\]\:[  ]/, '%6s ' % "[#{note_index}]:")
    note_index += 1
  else
    line.gsub!(/[  ]*\[([^\]]+)\]/) do
      ' [%s]' % $1.gsub(/XXX/) do
        s = "#{ref_index}"
        ref_index += 1
        s
      end
    end
  end
  $stdout.write line
end
Last modified 4 years ago Last modified on Feb 19, 2014, 1:16:54 PM