<commit_before>var cheerio = require('cheerio');
var path = require('path');
var fs = require('fs');
var url = require('url');
var es = require('event-stream');
var iconv = require('iconv-lite');

module.exports = function(filePath) {

    var go = function(file, callback) {

        var markup = iconv.decode(file.contents, 'utf-8');

        if(markup.indexOf('�') > -1){
            markup = iconv.decode(file.contents, 'gbk');
            markup = iconv.encode(markup, 'utf-8');
        }

        var dom = cheerio.load(markup, { decodeEntities: false });
        injectSvg(dom);
        file.contents = iconv.encode(dom.html(), 'utf-8');
        return callback(null, file);
    };

    return es.map(go);

    function injectSvg(dom) {

        // Regexp for checking if the file ending has .svg
        var testSvg = /^.*.(svg)$/i;

        dom('img').each(function(idx, el) {
            el = dom(el)
            var src = el.attr('src');

            if (testSvg.test(src) && isLocal(src)) {

                var dir = path.dirname(src);

                var svg;

                try {

                  var inlineTag = fs.readFileSync("./" + src).toString();
                  var className = el.attr('class');
                  var styles = el.attr('style');

                  svg = dom(inlineTag);

                  if(className !== undefined) {
                    svg.addClass(className);
                  }

                  if(styles !== undefined) {
                    svg.attr('style', styles);
                  }


                } catch (e) {

                  svg = "<!-- File "+ src + " was not found by gulp-inject-svg  -->";

                }

                el.replaceWith(svg)
            }
        })
    }

    function isLocal(href) {
        return href && !url.parse(href).hostname;
    }
}<commit_msg>Adds support to "filePath" setting<commit_after>var cheerio = require('cheerio');
var path = require('path');
var fs = require('fs');
var url = require('url');
var es = require('event-stream');
var iconv = require('iconv-lite');

module.exports = function (filePath) {

    var go = function (file, callback) {

        var markup = iconv.decode(file.contents, 'utf-8');

        if (markup.indexOf('�') > -1) {
            markup = iconv.decode(file.contents, 'gbk');
            markup = iconv.encode(markup, 'utf-8');
        }

        var dom = cheerio.load(markup, { decodeEntities: false });
        injectSvg(dom);
        file.contents = iconv.encode(dom.html(), 'utf-8');
        return callback(null, file);
    };

    return es.map(go);

    function injectSvg(dom) {
        // Regexp for checking if the file ending has .svg
        var testSvg = /^.*.(svg)$/i;

        dom('img').each(function (idx, el) {
            el = dom(el)
            var src = el.attr('src');

            if (testSvg.test(src) && isLocal(src)) {

                var dir = path.dirname(src);

                var svg;

                try {

                    filePath = ( filePath.slice(-1) == '/' ) ? filePath : filePath + '/';

                    var inlineTag = fs.readFileSync("./" + filePath + src).toString();
                    var className = el.attr('class');
                    var styles = el.attr('style');

                    svg = dom(inlineTag);

                    if (className !== undefined) {
                        svg.addClass(className);
                    }

                    if (styles !== undefined) {
                        svg.attr('style', styles);
                    }


                } catch (e) {

                    svg = "<!-- File " + src + " was not found by gulp-inject-svg  -->";

                }

                el.replaceWith(svg)
            }
        })
    }

    function isLocal(href) {
        return href && !url.parse(href).hostname;
    }
}
{'fraction_non_alphanumeric': 0.15012987012987014, 'fraction_numerical': 0.0023376623376623377, 'mean_word_length': 1.4877260981912144, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2024779', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1076, 'n_words': 245}