aboutsummaryrefslogtreecommitdiff
path: root/mammoth/docx/document_xml.py
blob: 7288dc238a1c9ff683a063d68513f76fe0b7bdae (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
26
27
28
29
30
31
32
from .. import documents
from .. import results
from . import body_xml


def read_document_xml_element(element,
        numbering=None,
        content_types=None,
        relationships=None,
        styles=None,
        footnote_elements=None,
        endnote_elements=None,
        docx_file=None):
    
    note_elements = (footnote_elements or []) + (endnote_elements or [])
    
    body_reader = body_xml.reader(
        numbering=numbering,
        content_types=content_types,
        relationships=relationships,
        styles=styles,
        docx_file=docx_file,
    )
    
    def _read_note(element):
        return body_reader.read_all(element.body).map(
            lambda body: documents.note(element.note_type, element.id, body))

    body_element = element.find_child("w:body")
    children_result = body_reader.read_all(body_element.children)
    notes_result = results.combine(map(_read_note, note_elements)).map(documents.notes)
    return results.map(documents.document, children_result, notes_result)