from typing import OrderedDict


def build_paragraph_marker_layer(root):
    """
    Build the paragraph marker layer from the provided root of the XML tree.

    :param root: The root element of the XML tree.
    :type root: :class:`etree.Element`

    :return: An OrderedDict containing the locations of markers, suitable for direct
        transformation into JSON for use with the eRegs frontend.
    :rtype: :class:`collections.OrderedDict`:
    """
    paragraphs = root.findall('.//{eregs}paragraph') # + root.findall('.//{eregs}interpParagraph')
    paragraph_dict = OrderedDict()

    for paragraph in paragraphs:

        marker = paragraph.get('marker')
        label = paragraph.get('label')
        if marker != '':
            marker_dict = {'locations': [0],
                           'text': marker}
            paragraph_dict[label] = [marker_dict]

    return paragraph_dict