"""
Macro for a centering environment

{{{
[[Center(begin)]]
}}}
starts the centered environment

{{{
[[Center(end)]]
}}}
ends the centered environment

"""
from StringIO import StringIO

def execute(hdf, args, env):
    buf = StringIO()
    if args:
        if args == 'begin':
            buf.write("<center>")
        elif args == 'end':
            buf.write("</center>")
        else:
            buf.write("<p style='font-weight:bold; color:red;'>[[Center()]] macro unknown keyword %s</p>\n" % (args))

    else:
        buf.write("<p style='font-weight:bold; color:red;'>[[Center()]] macro requires keyword 'begin' or 'end'</p>\n")

    return buf.getvalue()

