import re


def sylsplit(child):
    """
    Function that puts every syllable on a newline
    and adds utterance boundaries after shads and the like.
    It takes child as its argument as these are the children of p (=tei:p);
    both the tei:milestone markup for line numbers and the text are children.
    """

    #add newlines after Tibetan
    child = re.sub(r"([ༀ-࿘])([^ༀ-࿘])",r"\1\n\2",child) 

    #add newlines before Tibetan
    child = re.sub(r"([^ༀ-࿘])([ༀ-࿘])",r"\1\n\2",child) 
    
    #Add newline & utt after shad and the like.
    child = re.sub(r"([།-༔])",r"\n\1\n<utt>\n",child) 

    #Add newline after tsheg and the like.
    child = re.sub(r"([་༌ཿ࿒])([ༀ-࿘])",r"\1\n\2",child) 

    #Put Tibetan brackets, etc. on a newline.
    child = re.sub(r"([༼༽《》༈])",r"\n\1\n",child)

    #Change unbreakable tsheg to breakable tsheg. 
    child = re.sub("\u0F0C","\u0F0B",child) 

    #Remove empty lines.
    child = re.sub(r"\n+",r"\n",child) 

    return child