Index: lib/tasks/migrate_from_trac.rake
===================================================================
--- lib/tasks/migrate_from_trac.rake	(revision 3555)
+++ lib/tasks/migrate_from_trac.rake	(working copy)
@@ -241,7 +241,7 @@
           if name_attr = TracSessionAttribute.find_by_sid_and_name(username, 'name')
             name = name_attr.value
           end
-          name =~ (/(.*)(\s+\w+)?/)
+          name =~ (/(.+?)(?:[\ \t]+(.+)?|[\ \t]+|)$/)
           fn = $1.strip
           ln = ($2 || '-').strip
 
@@ -271,13 +271,20 @@
 
       # Basic wiki syntax conversion
       def self.convert_wiki_text(text)
-        # Titles
-        text = text.gsub(/^(\=+)\s(.+)\s(\=+)/) {|s| "\nh#{$1.length}. #{$2}\n"}
-        # External Links
-        text = text.gsub(/\[(http[^\s]+)\s+([^\]]+)\]/) {|s| "\"#{$2}\":#{$1}"}
+        # New line
+        text = text.gsub(/\[\[BR\]\]/, "\n") # This has to go before the rules below
+        # Titles (only h1. to h6.)
+        text = text.gsub(/(?:^|^\ +)(\={1,6})\ (.+)\ (\={1,6})/) {|s| "\nh#{$1.length}. #{$2}\n"}
+        # External Links:
+        #      [http://example.com/]
+        text = text.gsub(/\[((?:https?|ftp)\:\S+)\]/, '\1')
+        #      [http://example.com/ Example],[http://example.com/ "Example"]
+        text = text.gsub(/\[((?:https?|ftp)\:\S+)[\ \t]+(\")?(.+?)\2?\]/, '"\3":\1')
+        #      [mailto:some@example.com]
+        text = text.gsub(/\[mailto\:(\")?(.+?)(\1)?\]/, '\2')
         # Ticket links:
-        #      [ticket:234 Text],[ticket:234 This is a test]
-        text = text.gsub(/\[ticket\:([^\ ]+)\ (.+?)\]/, '"\2":/issues/show/\1')
+        #      [ticket:234 Text],[ticket:234 This is a test],[ticket:234 "This is a test"]
+        text = text.gsub(/\[ticket\:([^\ ]+)[\ \t]+(\")?(.+?)\2?\]/, '"\3":/issues/show/\1')
         #      ticket:1234
         #      #1 is working cause Redmine uses the same syntax.
         text = text.gsub(/ticket\:([^\ ]+)/, '#\1')
@@ -292,19 +299,24 @@
         #      milestone:0.1.0
         text = text.gsub(/\[milestone\:([^\ ]+)\]/, 'version:\1')
         text = text.gsub(/milestone\:([^\ ]+)/, 'version:\1')
-        # Internal Links
-        text = text.gsub(/\[\[BR\]\]/, "\n") # This has to go before the rules below
-        text = text.gsub(/\[\"(.+)\".*\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
-        text = text.gsub(/\[wiki:\"(.+)\".*\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
-        text = text.gsub(/\[wiki:\"(.+)\".*\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
-        text = text.gsub(/\[wiki:([^\s\]]+)\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
-        text = text.gsub(/\[wiki:([^\s\]]+)\s(.*)\]/) {|s| "[[#{$1.delete(',./?;|:')}|#{$2.delete(',./?;|:')}]]"}
+        # Internal Links:
+        #      ["Some Link"]
+        text = text.gsub(/\[\"(.+?)\"\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
+        #      [wiki:"Some Link" "Link description"],[wiki:"Some Link" Link description]
+        text = text.gsub(/\[wiki\:\"([^\]\"]+)\"[\ \t]+\"?(.+?)\"?\]/) {|s| "[[#{$1.delete(',./?;|:')}|#{$2}]]"}
+        #      [wiki:"Some Link"]
+        text = text.gsub(/\[wiki\:\"(.+?)\"\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
+        #text = text.gsub(/\[wiki:\"(.+?)\"\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"} # dublicate??
+        #      [wiki:SomeLink]
+        text = text.gsub(/\[wiki\:([^\s\]]+)\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
+        #      [wiki:SomeLink Link description],[wiki:SomeLink "Link description"]
+        text = text.gsub(/\[wiki\:([^\s\]\"]+)[\ \t]+\"?(.+?)\"?\]/) {|s| "[[#{$1.delete(',./?;|:')}|#{$2}]]"}
 
-  # Links to pages UsingJustWikiCaps
-  text = text.gsub(/([^!]|^)(^| )([A-Z][a-z]+[A-Z][a-zA-Z]+)/, '\\1\\2[[\3]]')
-  # Normalize things that were supposed to not be links
-  # like !NotALink
-  text = text.gsub(/(^| )!([A-Z][A-Za-z]+)/, '\1\2')
+        # Links to pages UsingJustWikiCaps (not work for unicode)
+        text = text.gsub(/([^!]|^)(^| )([A-Z][a-z]+[A-Z][a-zA-Z]+)/, '\\1\\2[[\3]]')
+        # Normalize things that were supposed to not be links
+        # like !NotALink
+        text = text.gsub(/(^| )!([A-Z][A-Za-z]+)/, '\1\2')
         # Revisions links
         text = text.gsub(/\[(\d+)\]/, 'r\1')
         # Ticket number re-writing
@@ -316,6 +328,11 @@
             s
           end
         end
+        
+        # Before convert Code highlighting, need procing inline code
+        # like {{{hello world}}}
+        text = text.gsub(/\{\{\{(.+?)\}\}\}/, '@\1@')
+        
         # We would like to convert the Code highlighting too
         # This will go into the next line.
         shebang_line = false
@@ -357,9 +374,20 @@
         text = text.gsub(/~~/, '-')
         text = text.gsub(/`/, '@')
         text = text.gsub(/,,/, '~')
-        # Lists
-        text = text.gsub(/^([ ]+)\* /) {|s| '*' * $1.length + " "}
-
+        # Tables
+        text = text.gsub(/\|\|/, '|')
+        # Lists:
+        #      bullet
+        text = text.gsub(/^(\ +)\* /) {|s| '*' * $1.length + " "}
+        #      numbered
+        text = text.gsub(/^(\ +)\d+\. /) {|s| '#' * $1.length + " "}
+        # Images (work for only attached in current page [[Image(picture.gif)]])
+        # need rules for:  * [[Image(wiki:WikiFormatting:picture.gif)]] (referring to attachment on another page)
+        #                  * [[Image(ticket:1:picture.gif)]] (file attached to a ticket)
+        #                  * [[Image(htdocs:picture.gif)]] (referring to a file inside project htdocs)
+        #                  * [[Image(source:/trunk/trac/htdocs/trac_logo_mini.png)]] (a file in repository) 
+        text = text.gsub(/\[\[image\((.+?)(?:,.+?)?\)\]\]/i, '!\1!')
+        
         text
       end
 
@@ -746,7 +774,7 @@
     DEFAULT_PORTS = {'mysql' => 3306, 'postgresql' => 5432}
 
     prompt('Trac directory') {|directory| TracMigrate.set_trac_directory directory.strip}
-    prompt('Trac database adapter (sqlite, sqlite3, mysql, postgresql)', :default => 'sqlite') {|adapter| TracMigrate.set_trac_adapter adapter}
+    prompt('Trac database adapter (sqlite, sqlite3, mysql, postgresql)', :default => 'sqlite3') {|adapter| TracMigrate.set_trac_adapter adapter}
     unless %w(sqlite sqlite3).include?(TracMigrate.trac_adapter)
       prompt('Trac database host', :default => 'localhost') {|host| TracMigrate.set_trac_db_host host}
       prompt('Trac database port', :default => DEFAULT_PORTS[TracMigrate.trac_adapter]) {|port| TracMigrate.set_trac_db_port port}
