Mailing List Archive

Macros: ThumbNail and Headings
Hi,

I've written two macros that I needed to make some of the wikis,
perhaps they could be included in the MacroBazaar. I didn't want to add
them directly before someone who knows trac and python well can tell me
if there should be any changes made.

I haven't figured out how the hdf works, nor what I'm supposed to do
with it.

-- kent

---
# ThumbNail macro by Kent Karlsson, kent@popwire.com

def execute(hdf, txt, env):
# Currently hdf is set only when the macro is called
# From a wiki page
if hdf:
hdf.setValue('wiki.macro.thumbnail', 'ThumbNail')

# args will be null if the macro is called without parentesis.
if not txt:
return 'ThumbNail needs two arguments'

data = txt.split(' ', 1)
if len(data) == 2:
return '<a href="' + data[0] + '" target="_blank"><img src="' +
data[1] + '"></a>'
else:
return 'ThumbNail needs two arguments'
---
# Heading macro by Kent Karlsson, kent@popwire.com

def execute(hdf, txt, env):
# Currently hdf is set only when the macro is called
# From a wiki page
if hdf:
hdf.setValue('wiki.macro.heading', 'Heading')

# args will be null if the macro is called without parentesis.
if not txt:
return '<h2>Empty Heading</h2>'

data = txt.split(' ', 1)
if len(data) == 2 and data[0].isdigit():
return '<h%s>%s</h%s>' % (data[0], data[1], data[0])
else:
return '<h2>' + txt + '</h2>'
---