#!/usr/bin/env ruby require 'cgi' module DText def parse_inline(str, options = {}) str = str.gsub(/&/, "&") str.gsub!(//, ">") str.gsub!(/\[\[.+?\]\]/m) do |tag| tag = tag[2..-3] if tag =~ /^(.+?)\|(.+)$/ tag = $1 name = $2 '' + name + '' else '' + tag + '' end end str.gsub!(/\{\{.+?\}\}/m) do |tag| tag = tag[2..-3] '' + tag + '' end str.gsub!(/[Pp]ost #(\d+)/, 'post #\1') str.gsub!(/[Ff]orum #(\d+)/, 'forum #\1') str.gsub!(/[Cc]omment #(\d+)/, 'comment #\1') str.gsub!(/[Pp]ool #(\d+)/, 'pool #\1') str.gsub!(/\n/m, "
") str.gsub!(/\[b\](.+?)\[\/b\]/, '\1') str.gsub!(/\[i\](.+?)\[\/i\]/, '\1') str.gsub!(/\[spoilers?\](.+?)\[\/spoilers?\]/m, '\1') str.gsub!(/("[^"]+":(http:\/\/|\/)\S+|http:\/\/\S+)/m) do |link| if link =~ /^"([^"]+)":(.+)$/ text = $1 link = $2 else text = link end if link =~ /([;,.!?\)\]<>])$/ link.chop! ch = $1 else ch = "" end link.gsub!(/"/, '"') '' + text + '' + ch end str end def parse_list(str, options = {}) html = "" layout = [] nest = 0 str.split(/\n/).each do |line| if line =~ /^\s*(\*+) (.+)/ nest = $1.size content = parse_inline($2) else content = parse_inline(line) end if nest > layout.size html += "