import re


def clean_context(text: str, replace_linebreaks: bool=True) -> str:
    """Cleans a SQuAD context"""
    if replace_linebreaks:
        text = re.sub('[\r\n]+', ' ', text)  # remove linebreaks
    text = re.sub('\s+', ' ', text)  # fix multiple spaces
    return text.strip()