<commit_before>/*
 * Copyright 2014-2017 Hewlett-Packard Development Company, L.P.
 * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
 */

define([
    './widget'
], function(Widget) {
    'use strict';

    return Widget.extend({

        initialize: function(options) {
            Widget.prototype.initialize.apply(this, arguments);

            this.html = options.widgetSettings.html;
        },

        render: function() {
            Widget.prototype.render.apply(this, arguments);

            this.$content.html(this.html);
        },

        exportPPTData: function(){
            var text = this.$content.text();

            // Depending on how complicated we need to make this parser, we could also handle font, italics, etc.
            return {
                data: {
                    text: [ {
                        text: text,
                        fontSize: 10
                    } ]
                },
                type: 'text'
            };
        }
    });

});<commit_msg>Work through the node tree to try and get bold / italic / font size properties and linebreak correctly; all of which are lost if we use jQuery's .text() method. Reproduce the bold / italic / font size formatting on the exported PowerPoint.<commit_after>/*
 * Copyright 2014-2017 Hewlett-Packard Development Company, L.P.
 * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
 */

define([
    './widget'
], function(Widget) {
    'use strict';

    return Widget.extend({

        initialize: function(options) {
            Widget.prototype.initialize.apply(this, arguments);

            this.html = options.widgetSettings.html;
        },

        render: function() {
            Widget.prototype.render.apply(this, arguments);

            this.$content.html(this.html);
        },

        exportPPTData: function(){
            var nodes = [];

            var fontScale = 10 / 16;

            // Try to traverse the content in a similar way that HTML would parse it, making bold text etc.
            // We can't just use $el.text() since that loses all the formatting.
            function traverse($el) {
                _.each(_.filter($el.contents(), function(dom){
                    return dom.nodeType === Node.TEXT_NODE || dom.nodeType === Node.ELEMENT_NODE
                }), function(dom, idx, all){
                    if (dom.nodeType === Node.TEXT_NODE) {
                        var last = _.last(nodes);
                        if (last && last.text.slice(-1) !== '\n' && $el.css('display') !== 'inline') {
                            last.text += '\n';
                        }

                        var trimmedText = dom.nodeValue.trim();

                        if (trimmedText) {
                            // text node, add with the current CSS
                            var fontFamily = $el.css('font-family');
                            var fontWeight = $el.css('font-weight');
                            nodes.push({
                                text: dom.nodeValue.replace(/\s+/, ' '),
                                fontSize: Math.round(parseInt($el.css('font-size')) * fontScale),
                                // font weight might be a number > 400, bold/bolder etc. or built into font family
                                bold: fontWeight > 400 || /bold/.test(fontWeight) || /Bold/i.test(fontFamily),
                                // italic may be a property of the font style, font weight or font-family
                                italic: /italic/.test($el.css('font-style')) || /Italic/i.test(fontFamily)
                            })
                        }
                    }
                    else if (dom.nodeType === Node.ELEMENT_NODE) {
                        traverse($(dom))
                    }
                })
            }

            traverse(this.$content)

            return {
                data: {
                    text: nodes
                },
                type: 'text'
            };
        }
    });

});
{'fraction_non_alphanumeric': 0.11153938809925319, 'fraction_numerical': 0.006986268369067694, 'mean_word_length': 1.3208496366685298, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2375752', 'n_tokens_mistral': 1069, 'n_tokens_neox': 984, 'n_words': 291}