aboutsummaryrefslogtreecommitdiff
path: root/lib/docx/footnotes-reader.js
blob: a55b261cce0f6715d557dc8bfc36cb52443d548b (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
exports.readFootnotesXml = readFootnotesXml;

function Footnotes(footnotes) {
    function findFootnoteById(id) {
        return footnotes[id] || null;
    }
    
    return {
        findFootnoteById: findFootnoteById
    };
}

function readFootnotesXml(xml) {
    var footnotes = {};
    
    xml.root.getElementsByTagName("w:footnote").forEach(function(footnoteElement) {
        var id = footnoteElement.attributes["w:id"];
        footnotes[id] = readFootnoteElement(footnoteElement);
    });
    
    return new Footnotes(footnotes);
}

function readFootnoteElement(footnoteElement) {
    var body = footnoteElement.children;
    return {body: body};
}