aboutsummaryrefslogtreecommitdiff
path: root/lib/style-applicator.js
blob: d6d909d0117d9346ecd20598126254981527fea6 (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
exports.StyleApplicator = StyleApplicator;

function StyleApplicator(options) {
    styleApplicatorOptions = options.styleApplicator || {};

    function processDocumentStyles(document) {
        for (var i = 0; i < document.value.children.length; i++) {
            var element = document.value.children[i];
            switch (element.type) {
                case 'paragraph':
                    document.value.children[i] = processParagraphStyles(document.value.children[i]);
                    break;
            }
        }
        return document;
    }

    function processParagraphStyles(element) {
        if (!element.styleName) {
            if (styleApplicatorOptions.alignment && element.alignment) {
                element.styleName = element.alignment+"Aligned";
            }
        }
        return element;
    }

    return {
        processDocumentStyles: processDocumentStyles
    }
}