changeset 531:bd8e88710547

span macro - see MoinMoin:MacroMarket/span
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 22 Jun 2010 13:54:17 +0200
parents 78ca2464edf9
children 942f9b55773e
files data/plugin/macro/span.py
diffstat 1 files changed, 49 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/plugin/macro/span.py	Tue Jun 22 13:54:17 2010 +0200
@@ -0,0 +1,49 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - span generating macro
+
+    Supported attrs: css_class, id, lang, dir, title, align
+
+    Unsupported attrs: style - can contain javascript, XSS danger
+                       event attrs - same reason
+
+    Usage:
+    <<span(red)>>some text contained in a span with css class red<<span>>
+    <<span(css_class=red)>>same as above<<span>>
+    <<span(id=foobar)>>some text in a span with id foobar<<span>>
+    <<span(title="read this!")>>some text with a mouseover title<<span>>
+
+    @copyright: 2010 MoinMoin:ThomasWaldmann
+    @license: GNU GPL, see COPYING for details.
+"""
+
+Dependencies = []
+
+from MoinMoin.wikiutil import required_arg
+
+def macro_span(macro,
+               # first the stuff we can directly give to span formatter:
+               css_class=u'',
+               id=u'',
+               lang=u'',
+               dir=u'',
+               title=u'',
+               align=u'',
+               # dangerous, see docstring:
+               #style=u'',
+              ):
+    attrs = {}
+    for key, value in [
+        ('css_class', css_class), ('id', id),
+        ('lang', lang), ('dir', dir),
+        ('title', title), ('align', align),
+        #('style', style),
+        ]:
+        if value:
+            attrs[key] = value
+    span = macro.formatter.span
+    if attrs:
+        return span(True, **attrs)
+    else:
+        return span(False)
+