def BGG_wrap(code, contents, code_value=None):
    """
    Return the given contents surrounded by the given BGG markup code.

    The output is the following BGG markup construct:

    [<code>=<code_value>]<contents>[/<code>], where the "=…" part is not
    included if code_value is None. The contents is converted to its string
    representation, if needed.
    """
    return f"[{code}{{}}]{contents}[/{code}]".format(
        "" if code_value is None else f"={code_value}")