<commit_before>'use strict';

var assert = require('assert'),
    extractCss = require('extract-css'),
    inlineCss = require('./lib/inline-css'),
    Promise = require('bluebird');

function extend(obj, src) {
    var own = {}.hasOwnProperty;

    for (var key in src) {
        if (own.call(src, key)) {
            obj[key] = src[key];
        }
    }
    return obj;
}

function inlineCssWithCb(html, css, options) {
    return new Promise(function(resolve, reject) {
        var content;

        try {
            content = inlineCss(html, css, options);
            resolve(content);
        } catch (err) {
            reject(err);
        }
    });

}

function inlineContent(src, options) {
    return new Promise(function(resolve, reject) {
        if (!options.url) {
            reject('options.url is required');
        }

        extractCss(src, options, function (err, html, css) {
            if (err) {
                return reject(err);
            }

            css += '\n' + options.extraCss;
            inlineCssWithCb(html, css, options)
                .then(function(out) {
                    resolve(out);
                })
        });
    });

}

module.exports = function (html, options) {
    return new Promise(function(resolve, reject) {
        var opt = extend({
                extraCss: '',
                applyStyleTags: true,
                removeStyleTags: true,
                applyLinkTags: true,
                removeLinkTags: true,
                preserveMediaQueries: false,
                applyWidthAttributes: false,
            }, options);

        inlineContent(html, opt)
            .then(function(data) { resolve(data); })
            .catch(function(err) { reject(err); })
        });

};<commit_msg>remove now superflous inlineCssWithCb function<commit_after>'use strict';

var assert = require('assert'),
    extractCss = require('extract-css'),
    inlineCss = require('./lib/inline-css'),
    Promise = require('bluebird');

function extend(obj, src) {
    var own = {}.hasOwnProperty;

    for (var key in src) {
        if (own.call(src, key)) {
            obj[key] = src[key];
        }
    }
    return obj;
}

function inlineContent(src, options) {
    return new Promise(function(resolve, reject) {
        var content;
        if (!options.url) {
            reject('options.url is required');
        }

        extractCss(src, options, function (err, html, css) {
            if (err) {
                return reject(err);
            }

            css += '\n' + options.extraCss;
            content = inlineCss(html, css, options);
            resolve(content);
        });
    });

}

module.exports = function (html, options) {
    return new Promise(function(resolve, reject) {
        var opt = extend({
                extraCss: '',
                applyStyleTags: true,
                removeStyleTags: true,
                applyLinkTags: true,
                removeLinkTags: true,
                preserveMediaQueries: false,
                applyWidthAttributes: false,
            }, options);

        inlineContent(html, opt)
            .then(function(data) { resolve(data); })
            .catch(function(err) { reject(err); })
        });

};
{'fraction_non_alphanumeric': 0.12685185185185185, 'fraction_numerical': 0.0, 'mean_word_length': 1.7373310810810811, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2570480', 'n_tokens_mistral': 913, 'n_tokens_neox': 886, 'n_words': 205}