Index: trac/wikimacros/rst.py
===================================================================
--- trac/wikimacros/rst.py	(revision 926)
+++ trac/wikimacros/rst.py	(working copy)
@@ -43,16 +43,20 @@
     raise EnvironmentError, 'Docutils version >= %s required, %s found' % (docutils_required, __version__)
 
 from trac.Href import Href
+from trac.WikiFormatter import Formatter
 
 __docformat__ = 'reStructuredText'
 
-WIKI_LINK = re.compile(r'(?:wiki:)?(?P<w>[A-Za-z][\w\#\?]*[^\w\#\?]*)') # Links must begin with Letters, \# ? so we can link inside pages.
-#WIKI_LINK = re.compile(r'(?:wiki:)?(?P<w>(^|(?<=[^A-Za-z]))[!]?[A-Z][a-z/]+(?:[A-Z][a-z/]+)+)')
+WIKI_LINK = re.compile(r'(?:wiki:)?(.+)')
+#WIKI_LINK = re.compile(r'(?:wiki:)?(?P<wikilink>[A-Za-z][\w\-]*[^\w\#\?]*)')
 TICKET_LINK = re.compile(r'(?:#(\d+))|(?:ticket:(\d+))')
 REPORT_LINK = re.compile(r'(?:{(\d+)})|(?:report:(\d+))')
 CHANGESET_LINK = re.compile(r'(?:\[(\d+)\])|(?:changeset:(\d+))')
 FILE_LINK = re.compile(r'(?:browser|repos|source):([^#]+)#?(.*)')
 
+#import trac.Logging
+#log = trac.Logging.logger_factory(logtype='file', logfile="/tmp/debug_rst.txt", level='ALL')
+
 def _wikipage(href, args):
     return href.wiki(args[0])
 
@@ -71,29 +75,34 @@
     return href.browser(path, rev)
 
 # TracLink REs and callback functions
-LINKS = [(WIKI_LINK, _wikipage),
-         (TICKET_LINK, _ticket),
+LINKS = [(TICKET_LINK, _ticket),
          (REPORT_LINK, _report),
          (CHANGESET_LINK, _changeset),
-         (FILE_LINK, _browser)]
+         (FILE_LINK, _browser),
+         (WIKI_LINK, _wikipage)]
 
 
-def trac_get_reference(env, rawtext, text):
+def trac_get_reference(env, rawtext, link, text):
+
     for (pattern, function) in LINKS:
-        m = pattern.match(text)
+        m = pattern.match(link)
         if m:
             g = filter(None, m.groups())
             missing = False
+            if not text:
+                text = g[0]
             if pattern == WIKI_LINK:
-                if not (env._wiki_pages.has_key(g[0])):
+                pagename = re.search(r'^[^\#]+',g[0])
+                if not (env._wiki_pages.has_key(pagename.group())):
                         missing = True
-                        text = text + "?"
+                        text = text + "?"            
             uri = function(env.href, g)
             reference = nodes.reference(rawtext, text)
             reference['refuri']= uri
             if missing:
                 reference.set_class('missing')
             return reference
+        
     return None
 
 def trac(env, name, arguments, options, content, lineno,
@@ -119,8 +128,12 @@
 
     .. _TracLink: http://projects.edgewall.com/trac/wiki/TracLinks
     """
-    text = arguments[int(len(arguments) == 2)]
-    reference = trac_get_reference(env, block_text, text)
+    link = arguments[0]
+    if len(arguments) == 2:
+        text = arguments[1]
+    else:
+        text = None
+    reference = trac_get_reference(env, block_text, link, text)
     if reference:
         return reference
     # didn't find a match (invalid TracLink),
@@ -133,7 +146,13 @@
 
 
 def trac_role(env, name, rawtext, text, lineno, inliner, options={}, content=[]):
-    reference = trac_get_reference(env, rawtext, text)
+    args  = text.split(" ",1)
+    link = args[0]
+    if len(args)==2:
+        text = args[1]
+    else:
+        text = None
+    reference = trac_get_reference(env, rawtext, link, text)
     if reference:
         return [reference], []
     warning = nodes.warning(None,
@@ -159,6 +178,29 @@
     rst.roles.register_local_role('trac', do_trac_role)
 
     # The code_block could is taken from the leo plugin rst2
+    def code_formatter(language, text):
+        #log.debug("language '%s' args '%s'", % (language, arguments))
+        Format = Formatter(hdf, env, None)
+        Format.set_code_processor(language)
+
+        html = Format.code_processor(hdf, text, env)        
+        #log.debug("language '%s' htmltext '%s'" % (language, html))
+        raw = nodes.raw('',html, format='html') #(self, rawsource='', text='', *children, **attributes):
+        return raw
+        
+    def code_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
+        args  = text.split(":",1)
+        language = args[0]
+        if len(args)==2:
+            text = args[1]
+        else:
+            text = ""
+        #log.debug("coderole '%s' text '%s'" % (language, text))
+        reference = code_formatter(language, text)
+        return [reference], []
+        
+
+      
     def code_block(name,arguments,options,content,lineno,content_offset,block_text,state,state_machine):
 
         """Create a code-block directive for docutils.
@@ -166,24 +208,11 @@
         Usage: .. code-block:: language
 
         If the language can be syntax highlighted it will be."""
-
-
-        
-        from trac.WikiFormatter import Formatter
-        
         language = arguments[0]
+        text = '\n'.join(content)        
+        reference = code_formatter(language, text)
+        return [reference]
 
-        code_processor = None
-        if  Formatter.builtin_processors.has_key(language):
-            code_processor = Formatter.builtin_processors[language]
-        else:
-            code_processor = Formatter.builtin_processors['default']
-
-
-        html = code_processor(hdf, '\n'.join(content), env)        
-        raw = nodes.raw('',html, format='html') #(self, rawsource='', text='', *children, **attributes):
-        return [raw]
-
     # These are documented at http://docutils.sourceforge.net/spec/howto/rst-directives.html.
     code_block.arguments = (
         1, # Number of required arguments.
@@ -199,6 +228,7 @@
     code_block.content = 1 # True if content is allowed.
     # Register the directive with docutils.
     rst.directives.register_directive('code-block',code_block)
+    rst.roles.register_local_role('code-block', code_role)
     
     
 
Index: trac/WikiFormatter.py
===================================================================
--- trac/WikiFormatter.py	(revision 926)
+++ trac/WikiFormatter.py	(working copy)
@@ -487,26 +487,31 @@
             match = Formatter._processor_re.search(line)
             if match:
                 name = match.group(1)
-                if  Formatter.builtin_processors.has_key(name):
-                    self.code_processor = Formatter.builtin_processors[name]
-                else:
-                    try:
-                        self.code_processor = self.load_macro(name)
-                    except Exception, e:
-                        mimeviewer, exists = self.env.mimeview.get_viewer(name)
-                        if exists != -1:
-                            self.mime_type = name
-                            self.code_processor = self.mime_processor
-                        else:
-                            self.code_text += line + os.linesep
-                            self.code_processor = Formatter.builtin_processors['default']
-                            self.out.write('<div class="system-message">Failed to load processor macro %s: %s t %s</div>' % (name, line, e))
+                self.set_code_processor(name, line)
             else:
                 self.code_text += line + os.linesep 
                 self.code_processor = Formatter.builtin_processors['default']
         else:
             self.code_text += line + os.linesep
 
+    def set_code_processor(self, name, line=""):
+        if  Formatter.builtin_processors.has_key(name):
+            self.code_processor = Formatter.builtin_processors[name]
+        else:
+            try:
+                self.code_processor = self.load_macro(name)
+            except Exception, e:
+                mimeviewer, exists = self.env.mimeview.get_viewer(name)
+                if exists != -1:
+                    self.mime_type = name
+                    self.code_processor = self.mime_processor
+                else:
+                    self.code_processor = Formatter.builtin_processors['default']
+                    self.out.write("<div class='system-message'>Failed to load processor macro '%s': '%s' '%s'</div>" % (name, line, e))
+                    self.code_text += line + os.linesep
+
+
+
     def format(self, text, out):
         self.out = out
         self._open_tags = []

