<commit_before>var util = require('util');

var TEMPLATE = 'angular.module(\'%s\', []).run(function($templateCache) {\n' +
    '  $templateCache.put(\'%s\',\n    \'%s\');\n' +
    '});\n';

var SINGLE_MODULE_TPL_START = '(function(module) {\n' +
    'try {\n' +
    '  module = angular.module(\'%s\');\n' +
    '} catch (e) {\n' +
    '  module = angular.module(\'%s\', []);\n' +
    '}\n';
var SINGLE_MODULE_TPL = 'module.run(function($templateCache) {\n' +
    '  $templateCache.put(\'%s\',\n    \'%s\');\n' +
    '});\n';
var SINGLE_MODULE_TPL_END = '})();\n';

// Regular Expressions that match <script type="text/ng-template" id="templateId">...</script>
var SCRIPT_RES = [
  new RegExp('<script[^>]*?\\bid="([^"]+)"[^>]*?\\btype="text/ng-template"[^>]*?>((.|\\n)*?)</script>', 'im'),
  new RegExp('<script[^>]*?\\btype="text/ng-template"[^>]*?\\bid="([^"]+)"[^>]*?>((.|\\n)*?)</script>', 'im')
];

var escapeContent = function(content) {
  return content.replace(/\\/g, '\\\\').replace(/'/g, '\\\'').replace(/\r?\n/g, '\\n\' +\n    \'');
};

var createHtml2JsPreprocessor = function(logger, basePath, config) {
  config = typeof config === 'object' ? config : {};

  var log = logger.create('preprocessor.html2js');
  var moduleName = config.moduleName;
  var stripPrefix = new RegExp('^' + (config.stripPrefix || ''));
  var prependPrefix = config.prependPrefix || '';
  var cacheIdFromPath = config && config.cacheIdFromPath || function(filepath) {
    return prependPrefix + filepath.replace(stripPrefix, '');
  };

  return function(content, file, done) {
    log.debug('Processing "%s".', file.originalPath);

    var htmlPath = cacheIdFromPath(file.originalPath.replace(basePath + '/', ''));

    file.path = file.path + '.js';

    var templates = [];

    // Strip out ng-template stuff here...
    for (var i = 0; i < SCRIPT_RES.length; i++) {
      var re = SCRIPT_RES[i];
      var match;
      while (match = content.match(re)) {
        templates.push([match[1], match[2]]);
        content = content.replace(re, '');
      }
    }

    if (content.trim()) {
      templates.push([htmlPath, content]);
    }


    for (i = 0; i < templates.length; i++) {
      htmlPath = templates[i][0];
      content = templates[i][1];
      if (moduleName) {
        templates[i] = util.format(SINGLE_MODULE_TPL, htmlPath, escapeContent(content));
      } else {
        templates[i] = util.format(TEMPLATE, htmlPath, htmlPath, escapeContent(content));
      }
    }
    if (moduleName) {
      done(util.format(SINGLE_MODULE_TPL_START, moduleName, moduleName) +
           templates.join('\n') +
           SINGLE_MODULE_TPL_END);

    } else {
      done(templates.join('\n'));
    }
  };
};

createHtml2JsPreprocessor.$inject = ['logger', 'config.basePath', 'config.ngHtml2JsPreprocessor'];

module.exports = createHtml2JsPreprocessor;
<commit_msg>Added support for Windows New Line Characters (\r\n)<commit_after>var util = require('util');

var TEMPLATE = 'angular.module(\'%s\', []).run(function($templateCache) {\n' +
    '  $templateCache.put(\'%s\',\n    \'%s\');\n' +
    '});\n';

var SINGLE_MODULE_TPL_START = '(function(module) {\n' +
    'try {\n' +
    '  module = angular.module(\'%s\');\n' +
    '} catch (e) {\n' +
    '  module = angular.module(\'%s\', []);\n' +
    '}\n';
var SINGLE_MODULE_TPL = 'module.run(function($templateCache) {\n' +
    '  $templateCache.put(\'%s\',\n    \'%s\');\n' +
    '});\n';
var SINGLE_MODULE_TPL_END = '})();\n';

// Regular Expressions that match <script type="text/ng-template" id="templateId">...</script>
var SCRIPT_RES = [
  new RegExp('<script[^>]*?\\bid="([^"]+)"[^>]*?\\btype="text/ng-template"[^>]*?>((.|\\r|\\n)*?)</script>', 'im'),
  new RegExp('<script[^>]*?\\btype="text/ng-template"[^>]*?\\bid="([^"]+)"[^>]*?>((.|\\r|\\n)*?)</script>', 'im')
];

var escapeContent = function(content) {
  return content.replace(/\\/g, '\\\\').replace(/'/g, '\\\'').replace(/\r?\n/g, '\\n\' +\n    \'');
};

var createHtml2JsPreprocessor = function(logger, basePath, config) {
  config = typeof config === 'object' ? config : {};

  var log = logger.create('preprocessor.html2js');
  var moduleName = config.moduleName;
  var stripPrefix = new RegExp('^' + (config.stripPrefix || ''));
  var prependPrefix = config.prependPrefix || '';
  var cacheIdFromPath = config && config.cacheIdFromPath || function(filepath) {
    return prependPrefix + filepath.replace(stripPrefix, '');
  };

  return function(content, file, done) {
    log.debug('Processing "%s".', file.originalPath);

    var htmlPath = cacheIdFromPath(file.originalPath.replace(basePath + '/', ''));

    file.path = file.path + '.js';

    var templates = [];

    // Strip out ng-template stuff here...
    for (var i = 0; i < SCRIPT_RES.length; i++) {
      var re = SCRIPT_RES[i];
      var match;
      while (match = content.match(re)) {
        templates.push([match[1], match[2]]);
        content = content.replace(re, '');
      }
    }

    if (content.trim()) {
      templates.push([htmlPath, content]);
    }


    for (i = 0; i < templates.length; i++) {
      htmlPath = templates[i][0];
      content = templates[i][1];
      if (moduleName) {
        templates[i] = util.format(SINGLE_MODULE_TPL, htmlPath, escapeContent(content));
      } else {
        templates[i] = util.format(TEMPLATE, htmlPath, htmlPath, escapeContent(content));
      }
    }
    if (moduleName) {
      done(util.format(SINGLE_MODULE_TPL_START, moduleName, moduleName) +
           templates.join('\n') +
           SINGLE_MODULE_TPL_END);

    } else {
      done(templates.join('\n'));
    }
  };
};

createHtml2JsPreprocessor.$inject = ['logger', 'config.basePath', 'config.ngHtml2JsPreprocessor'];

module.exports = createHtml2JsPreprocessor;

{'fraction_non_alphanumeric': 0.2246137823294567, 'fraction_numerical': 0.003818781461551814, 'mean_word_length': 3.236764705882353, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 27, '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': '55399', 'n_tokens_mistral': 2075, 'n_tokens_neox': 2003, 'n_words': 351}