changeset 377:aa2cd6639e00

Bridge Constructor: added anchor link in mediawiki constructor
author Goffi <goffi@goffi.org>
date Fri, 12 Aug 2011 14:07:55 +0200
parents 9ffae6abdb05
children 3646f6b9adb6
files src/bridge/bridge_constructor/bridge_contructor.py
diffstat 1 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/bridge/bridge_constructor/bridge_contructor.py	Thu Aug 11 18:36:22 2011 +0200
+++ b/src/bridge/bridge_constructor/bridge_contructor.py	Fri Aug 12 14:07:55 2011 +0200
@@ -226,6 +226,19 @@
         self.core_template="mediawiki_template.tpl" 
         self.core_dest="mediawiki.wiki" 
 
+    def _addTextDecorations(self, text):
+        """Add text decorations like coloration or shortcuts"""
+
+        def anchor_link(match):
+            link = match.group(1)
+            #we add anchor_link for [method_name] syntax:
+            if link in self.bridge_template.sections():
+                return "[[#%s|%s]]" % (link, link)
+            print ("WARNING: found an anchor link to an unknown method")
+            return link
+
+        return re.sub(r"\[(\w+)\]", anchor_link, text)
+
     def _wikiParameter(self, name, sig_in):
         """Format parameters with the wiki syntax
         @param name: name of the function
@@ -240,7 +253,7 @@
             if arg_doc.has_key(i):
                 name,doc=arg_doc[i]
                 doc='\n:'.join(doc.rstrip('\n').split('\n'))
-                wiki.append("; %s: %s" % (name, doc))
+                wiki.append("; %s: %s" % (name, self._addTextDecorations(doc)))
             else:
                 wiki.append("; arg_%d: " % i)
             if arg_default.has_key(i):
@@ -255,7 +268,7 @@
         wiki=[]
         if arg_doc.has_key('return'):
             wiki.append('\n|-\n! scope=row | return value\n|')
-            wiki.append('<br />\n'.join(arg_doc['return'].rstrip('\n').split('\n')))
+            wiki.append('<br />\n'.join(self._addTextDecorations(arg_doc['return']).rstrip('\n').split('\n')))
         return "\n".join(wiki)
 
     def generateCoreSide(self):