def METHOD_NAME(target_value: str, ranges: list) -> str:
    value = parse_target_value(target_value)
    value_origin_len = parse_target_value_length(target_value)
    if not value:
        return target_value.replace("<", "&lt;")
    sorted_ranges = sorted(ranges, key=lambda x: x["start"])
    for range_ in sorted_ranges:
        if range_["start"] > value_origin_len or range_["stop"] > value_origin_len:
            return f'<em style="color:red;">{value}</em>'
    if sorted_ranges and value and len(value) == value_origin_len:
        final_str = []
        str_dict = {ind: xss_prevent(str_) for ind, str_ in enumerate(value)}
        for range_ in sorted_ranges:
            str_dict[range_["start"]] = '<em style="color:red;">' + str_dict[range_["start"]]
            str_dict[range_["stop"] - 1] = str_dict[range_["stop"] - 1] + "</em>"
        final_str = [x[1] for x in sorted(str_dict.items(), key=lambda kv: kv[0])]
        return "".join(final_str)
    if len(value) != AGENT_DEFAULT_LENGTH:
        return f'<em style="color:red;">{value}</em>'
    try:
        if sorted_ranges and value and len(value) < value_origin_len:
            begin_part_length = ceil((AGENT_DEFAULT_LENGTH - 3) / 2)
            end_part_length = int((AGENT_DEFAULT_LENGTH - 3) / 2)
            str_dict_begin = {ind: xss_prevent(str_) for ind, str_ in enumerate(value[:begin_part_length])}
            str_dict_end = {
                ind + (value_origin_len - end_part_length) + 3: xss_prevent(str_)
                for ind, str_ in enumerate(value[-end_part_length:])
            }
            str_dict = {}
            str_dict.update(str_dict_begin)
            str_dict.update(str_dict_end)
            str_dict[begin_part_length + 2] = "..."
            for range_ in sorted_ranges:
                if range_["start"] in str_dict and (range_["stop"] - 1) in str_dict:
                    str_dict[range_["start"]] = '<em style="color:red;">' + str_dict[range_["start"]]
                    str_dict[range_["stop"] - 1] = str_dict[range_["stop"] - 1] + "</em>"
                if range_["start"] in str_dict and (range_["stop"] - 1) not in str_dict:
                    str_dict[range_["start"]] = '<em style="color:red;">' + str_dict[range_["start"]]
                    str_dict[begin_part_length] = "</em>" + str_dict[begin_part_length]
                    str_dict[begin_part_length] = "</em>" + str_dict[begin_part_length]
                if range_["start"] not in str_dict and (range_["stop"] - 1) in str_dict:
                    str_dict[value_origin_len - end_part_length] = (
                        '<em style="color:red;">' + str_dict[value_origin_len - end_part_length]
                    )
                    str_dict[range_["stop"] - 1] = str_dict[range_["stop"] - 1] + "</em>"
                if range_["start"] not in str_dict or (range_["stop"]) not in str_dict:
                    str_dict[begin_part_length + 2] = '<em style="color:red;">...</em>'
            final_str = [x[1] for x in sorted(str_dict.items(), key=lambda kv: kv[0])]
            return "".join(final_str)
    except KeyError as e:
        logger.warning(e, exc_info=e)
    return f'<em style="color:red;">{value}</em>'