summaryrefslogtreecommitdiff
path: root/mammoth/docx/document_xml.py
blob: 45905c6c9720dceabc5940a535f56bd898eb3edd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from .. import documents


def read_document_xml_element(
        element,
        body_reader,
        notes=None,
        comments=None):

    if notes is None:
        notes = []
    if comments is None:
        comments = []

    body_element = element.find_child("w:body")

    if body_element is None:
        raise ValueError("Could not find the body element: are you sure this is a docx file?")

    return body_reader.read_all(body_element.children) \
        .map(lambda children: documents.document(
            children,
            notes=documents.notes(notes),
            comments=comments
        ))