Index: trac/wiki/macros.py
===================================================================
--- trac/wiki/macros.py	(revision 2500)
+++ trac/wiki/macros.py	(working copy)
@@ -357,6 +357,54 @@
         return result
 
 
+class DivSpanMacro(Component):
+    """
+    Begin (`div` or `span`) or end (`/div` or `/span`) a division or a span,
+    using the first argument as the class name.
+    
+    The remaining arguments are optional and allow configuring directly
+    the style of the rendered element. Each argument is a `key:value` pair.
+    """
+    implements(IWikiMacroProvider)
+
+    def get_macros(self):
+        for name in ('div', '/div', 'span', '/span'):
+            yield name
+
+    def get_macro_description(self, name):
+        common = inspect.getdoc(DivSpanMacro).split('\n')
+        end = name[0] == '/' 
+        return '%s a %s%s' % (end and 'End' or 'Begin',
+                              end and name[1:] or name,
+                              end and '.' or ',\n' + '\n'.join(common[1:]))
+
+    def render_macro(self, req, name, content):
+        # /div or /span: end the block
+        if name[0] == '/':
+            return '<%s>' % name
+        args = content.split(',')
+        # div or span: we expect the 1st argument to be a class name
+        if len(args) == 0:
+            raise Exception("Missing class name.")
+        html_class = args[0]
+        keyval_re = re.compile('^([-a-z0-9]+):(.*)')
+        quoted_re = re.compile("^(?:\"|')(.*)(?:\"|')$")
+        style = {}
+        for arg in args[1:]:
+            arg = arg.strip()
+            match = keyval_re.search(arg)
+            if match:
+                key = match.group(1)
+                val = match.group(2)
+                m = quoted_re.search(val) # unquote "..." and '...'
+                if m:
+                    val = m.group(1)
+                style[key] = val
+        styles = '; '.join(['%s:%s' % x for x in style.iteritems()])
+        style_attr = styles and ' style="%s"' % styles or ''
+        return '<%s class="%s"%s>' % (name, html_class, style_attr)
+
+
 class MacroListMacro(Component):
     """Displays a list of all installed Wiki macros, including documentation if
     available.

