import re


def preprocess(text, to_lower=True, remove_tags=True, digits=True, special_chars=True):
    """
    Takes a text object as input and performs a sequence of processing
    operations: lowercases , removes html tags and special characters

    Parameters
    ----------
    text: str
        Text to be cleaned.

    to_lower: bool (default=True)
        Whether to convert text to lower case.

    remove_tags: bool (default=True)
        Whether to remove content form within html <> tags.

    digits: bool (default=True)
        Whether to remove numbers.

    special_chars: bool (default=True)
        Whether to remove special characters.

    Returns
    -------
    text: str
        cleaned text
    """
    if to_lower:
        text = text.lower()

    if remove_tags:
        text = re.sub("</?.*?>", " <> ", text)

    if digits:
        text = re.sub('\\d+', '', text)

    if special_chars:
        text = re.sub('\\W+', ' ', text)

    text = text.strip()

    return text