seven1m / trac_wiki_to_github

A rough start of a Ruby script to help convert Trac wiki syntax to GitHub friendly syntax.

This URL has Read+Write access

trac_wiki_to_github / convert.rb
031cba14 » seven1m 2008-03-30 initial import 1 #!/usr/bin/env ruby
2
3 TRAC_DB_PATH = 'trac.db'
4 OUT_PATH = 'wiki'
5 GITHUB_WIKI_URL = '/seven1m/onebody/wikis/'
6
7 require 'sqlite3'
8
9 db = SQLite3::Database.new(TRAC_DB_PATH)
10 pages = db.execute('select name, text from wiki w2 where version = (select max(version) from wiki where name = w2.name);')
11
12 pages.each do |title, body|
13 File.open(File.join(OUT_PATH, title.gsub(/\s/, '')), 'w') do |file|
14 body.gsub!(/\{\{\{([^\n]+?)\}\}\}/, '<code>\1</code>')
15 body.gsub!(/\{\{\{(.+?)\}\}\}/m, '<pre><code>\1</code></pre>')
16 body.gsub!(/====\s(.+?)\s====/, 'h4. \1')
17 body.gsub!(/===\s(.+?)\s===/, 'h3. \1')
18 body.gsub!(/==\s(.+?)\s==/, 'h2. \1')
19 body.gsub!(/=\s(.+?)\s=[\s\n]*/, '')
20 body.gsub!(/\[(http[^\s\[\]]+)\s([^\[\]]+)\]/, '"\2":\1')
21 body.gsub!(/\[([^\s]+)\s(.+)\]/, '"\2":' + GITHUB_WIKI_URL + '\1')
22 body.gsub!(/([^"\/\!])(([A-Z][a-z0-9]+){2,})/, '\1[[\2]]')
23 body.gsub!(/\!(([A-Z][a-z0-9]+){2,})/, '\1')
24 body.gsub!(/'''(.+)'''/, '*\1*')
25 body.gsub!(/''(.+)''/, '_\1_')
26 body.gsub!(/^\s\*/, '*')
27 body.gsub!(/^\s\d\./, '#')
28 file.write(body)
29 end
30 end