summaryrefslogtreecommitdiff
path: root/lib/documents.js
blob: 86e070991b139431de014cf98e208d1bbe148ef4 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
var types = {
    document: "document",
    paragraph: "paragraph",
    run: "run",
    text: "text",
    tab: "tab",
    hyperlink: "hyperlink",
    footnoteReference: "footnoteReference",
    image: "image",
    footnote: "footnote"
};

function Document(children, options) {
    options = options || {};
    return {
        type: types.document,
        children: children,
        footnotes: options.footnotes || new Footnotes({})
    };
}

function Paragraph(children, properties) {
    properties = properties || {};
    return {
        type: types.paragraph,
        children: children,
        styleId: properties.styleId || null,
        styleName: properties.styleName || null,
        numbering: properties.numbering || null,
        alignment: properties.alignment || null
    };
}

function Run(children, properties) {
    properties = properties || {};
    return {
        type: types.run,
        children: children,
        styleId: properties.styleId || null,
        styleName: properties.styleName || null,
        isBold: properties.isBold,
        isItalic: properties.isItalic
    };
}

function Text(value) {
    return {
        type: types.text,
        value: value
    };
}

function Tab(value) {
    return {
        type: types.tab
    };
}

function Hyperlink(children, options) {
    return {
        type: types.hyperlink,
        children: children,
        href: options.href
    };
}

function FootnoteReference(options) {
    return {
        type: types.footnoteReference,
        footnoteId: options.footnoteId
    };
}

function Footnotes(footnotes) {
    this._footnotes = footnotes;
}

Footnotes.prototype.findFootnoteById = function(id) {
    return this._footnotes[id] || null;
}

function Footnote(options) {
    return {
        type: types.footnote,
        body: options.body,
        id: options.id
    };
};

function ElementWithChildren(type) {
    return function(children, properties) {
        return {
            type: type,
            children: children,
            properties: properties || {}
        };
    };
}

function Image(options) {
    return {
        type: types.image,
        read: options.readImage,
        altText: options.altText,
        contentType: options.contentType
    };
}

exports.Document = Document;
exports.Paragraph = Paragraph;
exports.Run = Run;
exports.Text = Text;
exports.Tab = Tab;
exports.Hyperlink = Hyperlink;
exports.FootnoteReference = FootnoteReference;
exports.Footnotes = Footnotes;
exports.Footnote = Footnote;
exports.Image = Image;