<commit_before>'use strict';

var sanitizer = require('sanitizer');
var MarkdownIt = require('markdown-it');
var uriPolicy = require('./uriPolicy').uriPolicy;

var plugins = [
  require('markdown-it-sup'),
  require('markdown-it-sub'),
  require('markdown-it-lazy-headers'),
  require('./plugins/alignedTable.js')
];

var defaultOptions = {
  'linkify': true,
  'html': true,
  'langPrefix': '',
  'xhtmlOut': false,
  'breaks': false
};


function rendererFactory() {
  var md = new MarkdownIt('commonmark', defaultOptions);

  // "linkify" plugin must be enabled separately
  // even though it is set in the config. But /shrug
  md.enable('linkify', true);

  plugins.forEach(function pluginLoader(pluginFn) {
    md.use(pluginFn);
  });
  md.linkify.set({ fuzzyLink: false, fuzzyEmail: false });

  md.enable(['sup', 'sub', 'link', 'autolink'], true);

  return md;
}

var commonmarkRenderer = rendererFactory();

function renderHtml(markdownString, options, cb) {
  var usedRenderer, cleanRenderer, result;

  usedRenderer = commonmarkRenderer;
  cleanRenderer = false;

  if (markdownString == null) {
    markdownString = '';
  }

  if (typeof(options) === 'function') {
    cb = options;
    options = null;
  }
  else {
    usedRenderer = rendererFactory();
    cleanRenderer = true;
  }

  if (options == null) {
    options = {
      'sanitize': true
    };
  }

  result = usedRenderer.render(markdownString);

  if (result.substr(-1, 1) !== '\n') {
    result = result + '\n';
  }

  if (options.sanitize) {
    result = sanitizer.sanitize(result, uriPolicy);
  }

  if (cleanRenderer) {
    usedRenderer = null;
  }

  if (!cb) {
    return result;
  }

  cb(null, result);
}

function parse(markdownString, cb) {
  try {
    cb(null, commonmarkRenderer.parse(markdownString, {}));
  } catch(ex) {
    cb(ex)
  }
};

// API
module.exports = {
  rendererFactory: rendererFactory,
  renderHtml: renderHtml,
  parse: parse,
};
<commit_msg>refactor(commonmark): Default renderer variable renamed<commit_after>'use strict';

var sanitizer = require('sanitizer');
var MarkdownIt = require('markdown-it');
var uriPolicy = require('./uriPolicy').uriPolicy;

var plugins = [
  require('markdown-it-sup'),
  require('markdown-it-sub'),
  require('markdown-it-lazy-headers'),
  require('./plugins/alignedTable.js')
];

var defaultOptions = {
  'linkify': true,
  'html': true,
  'langPrefix': '',
  'xhtmlOut': false,
  'breaks': false
};


function rendererFactory() {
  var md = new MarkdownIt('commonmark', defaultOptions);

  // "linkify" plugin must be enabled separately
  // even though it is set in the config. But /shrug
  md.enable('linkify', true);

  plugins.forEach(function pluginLoader(pluginFn) {
    md.use(pluginFn);
  });
  md.linkify.set({ fuzzyLink: false, fuzzyEmail: false });

  md.enable(['sup', 'sub', 'link', 'autolink'], true);

  return md;
}

var defaultRenderer = rendererFactory();

function renderHtml(markdownString, options, cb) {
  var usedRenderer, cleanRenderer, result;

  usedRenderer = defaultRenderer;
  cleanRenderer = false;

  if (markdownString == null) {
    markdownString = '';
  }

  if (typeof(options) === 'function') {
    cb = options;
    options = null;
  }
  else {
    usedRenderer = rendererFactory();
    cleanRenderer = true;
  }

  if (options == null) {
    options = {
      'sanitize': true
    };
  }

  result = usedRenderer.render(markdownString);

  if (result.substr(-1, 1) !== '\n') {
    result = result + '\n';
  }

  if (options.sanitize) {
    result = sanitizer.sanitize(result, uriPolicy);
  }

  if (cleanRenderer) {
    usedRenderer = null;
  }

  if (!cb) {
    return result;
  }

  cb(null, result);
}

function parse(markdownString, cb) {
  try {
    cb(null, defaultRenderer.parse(markdownString, {}));
  } catch(ex) {
    cb(ex)
  }
};

// API
module.exports = {
  rendererFactory: rendererFactory,
  renderHtml: renderHtml,
  parse: parse,
};

{'fraction_non_alphanumeric': 0.15695751717120326, 'fraction_numerical': 0.0010175527855507504, 'mean_word_length': 3.588098016336056, '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': '3346205', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1277, 'n_words': 294}