[cpif] r427 - branches/alvaro/frontend-web

svn at argo.es svn at argo.es
Thu Oct 25 17:51:40 CEST 2007


Author: alvaro
Date: Thu Oct 25 17:51:39 2007
New Revision: 427

Log:
Minor changes


Modified:
   branches/alvaro/frontend-web/parser_bbcode.py

Modified: branches/alvaro/frontend-web/parser_bbcode.py
==============================================================================
--- branches/alvaro/frontend-web/parser_bbcode.py	(original)
+++ branches/alvaro/frontend-web/parser_bbcode.py	Thu Oct 25 17:51:39 2007
@@ -5,33 +5,19 @@
 
 import re
 
-# Allow BBCode syntax errors?
-allow_errors = False
-
-allowed_tags = {
-#   "bbcode": (start tag, end tag (if needed), True if allows arguments, context where ir is NOT permitted)
-    "b": ('<strong>', '</strong>', False, 'strong'), 
-    "u": ('<span style="text-decoration:underline">', '</span>', False, None), 
-    "s": ('<strike>', '</strike>', False, 'strike'), 
-    "size": ('<span style="font-size:%(arg)s">', '</span>', True, None), 
-    "code": ('<code>', '</code>', False, 'code'), 
-    "i": ('<em>', '</em>', False, 'em'), 
-    "url": ('<a href="%(arg)s">', '</a>', True, 'a'), 
-    "quote*": ('<blockquote>', '</blockquote>', False, None), 
-    "quote": ('<blockquote title="%(arg)s"><h4>%(arg)s escribi&oacute;:</h4>', '</blockquote>', True, None), 
-    "img": ('<img src="%(arg)s" />', None, True, None)
-}
-
 tags = {
         'b': ['b','b'],
+        'i': ['i','i'],
+        's': ['s','s'],
         'u': ['u','u'],
-        'size': ['size', 'size'],
-#        'quote*': ['quote','quote'],
+        'code': ['code','code'], 
+        'size': ['size(?:=(?:"([^"]+)")|=([^"]+))?', 'size'],
         'quote': ['quote(?:=(?:"([^"]+)")|=([^"]+))?','quote'],
         'url': ['url(?:=(?:"([^"]+)")|=([^"]+))?', 'url'],
         'img': ['img', 'img'],
     }
 
+# The tags are supossed to fall under this regexp
 regexp_tag = re.compile("(\[.*?\])")
 
 for key, value in tags.iteritems():
@@ -50,9 +36,7 @@
     import xml.sax.saxutils
     return xml.sax.saxutils.escape(text, entities)
 
-
 def parse(text):
-
     before = []
     control = True
     
@@ -61,13 +45,15 @@
         tag = None
         args = None
         after = None
-        if len(ret) != 3:
+        if len(ret) != 3: # Don't have a tag
             before.append(text)
             break
+
         before.append(ret[0])
         tag = ret[1]
         after = ret[2]
         args = None
+
         for key,value in tags.iteritems():
             if value[0].match(tag):
                 args =  value[0].match(tag).groups()
@@ -78,7 +64,6 @@
                         args = escape(args[1])
                     else:
                         args = None
-#                args = escape(args[0]) if len(args) > 0 and args[0] else None
                 tag = ('BBCODE', True, key)
                 control = False
                 break



More information about the cpif mailing list