def append(text, to_append):
    """Appends text to a title string in a way that respects tags."""
    first_open = text.find("[")
    if first_open == -1:
        return text + to_append
    else:
        return "%s%s %s" % (text[:first_open].strip(),
                            to_append,
                            text[first_open:])