def escape_text(bb):
    """Convert a bytestring to a raw Text property value that represents it.

    bb -- bytes-like object, in the desired output encoding.

    Returns a bytes object which passes is_valid_property_value().

    Normally text_value(escape_text(bb)) == bb, but there are the following
    exceptions:
     - all linebreaks are are normalised to 

     - whitespace other than line breaks is converted to a single space

    """
    return bb.replace(b'\\', b'\\\\').replace(b']', b'\\]')
