<commit_before>var repeat = require('string-repeater');

/**
 *  Print an HTML list.
 */
function Html(opts) {
  this.opts = opts;
  this.indent = typeof opts.indent === 'number' ? opts.indent : 0;
  this.stdout = opts.stdout;
  this.link = opts.link;
  this.description = opts.description;
  this.entered = false;
}

function newline() {
  if(this.indent) {
    this.stdout.write('\n'); 
  }
}

function open(key, node) {
  var indent = this.indent ? repeat(' ', this.indent * (node.depth + 1)) : '';
  this.stdout.write('<ul>');
  this.item(node);

  // close root element
  this.newline();
  this.stdout.write(indent + '</li>');
}

function enter(node) {
  var indent = this.indent ? repeat(' ', this.indent * (node.depth + 2)) : '';
  this.newline();
  this.stdout.write(indent + '<ul>');
  this.entered = true;
}

function exit(node) {
  var indent = this.indent ? repeat(' ', this.indent * (node.depth + 1)) : ''
    , child = this.indent ? repeat(' ', this.indent * (node.depth + 2)) : '';

  this.newline();
  this.stdout.write(child + '</ul>');

  this.newline();
  this.stdout.write(indent + '</li>');
  this.entered = false;
}

function item(node) {
  var depth = this.entered ? node.depth + 1 : node.depth
    , indent = this.indent ? repeat(' ', this.indent * (depth + 1)) : ''
    , child = this.indent ? repeat(' ', this.indent * (depth + 2)) : ''
    , link = child + '<span>' + node.label + '</span>'
    , href = node.path;

  if(this.link === 'absolute') {
    href = node.url;
  }

  // NOTE: href might not be valid when crawling a deep url 
  // NOTE: with no parents
  if(href && this.link !== 'none') {
    link = child + '<a href="' + href + '">' + node.label + '</a>';
  }

  this.newline();
  this.stdout.write(indent + '<li>');

  this.newline();
  this.stdout.write(link);

  if(this.description !== false && node.meta && node.meta.description) {
    this.newline();
    this.stdout.write(child + '<span>' + node.meta.description + '</span>');
  }

  if(!node.nodes.length) {
    this.newline();
    this.stdout.write(indent + '</li>');
  }
}

function close() {
  this.newline();
  this.stdout.write('</ul>');
}

Html.prototype.open = open;
Html.prototype.item = item;
Html.prototype.close = close;

Html.prototype.newline = newline;
Html.prototype.enter = enter;
Html.prototype.exit = exit;

module.exports = Html;<commit_msg>Improve HTML output padding.<commit_after>var repeat = require('string-repeater');

/**
 *  Print an HTML list.
 */
function Html(opts) {
  this.opts = opts;
  this.indent = typeof opts.indent === 'number' ? opts.indent : 0;
  this.stdout = opts.stdout;
  this.link = opts.link;
  this.description = opts.description;
  this.depth = 0;
}

/**
 *  Write out a newline.
 */
function newline() {
  if(this.indent) {
    this.stdout.write('\n'); 
  }
}

/**
 *  Helper to retrieve padding string.
 */
function pad(depth) {
  if(depth === undefined) {
    depth = this.depth; 
  }
  return this.indent ? repeat(' ', this.indent * depth) : '';
}

/**
 *  Open the root list.
 */
function open(key, node) {
  // open the root list
  this.stdout.write('<ul>');

  this.depth++;

  // primary node (index)
  this.item(node);

  // close root element
  this.newline();
  this.stdout.write(this.pad() + '</li>');
}

/**
 *  Enter child nodes.
 */
function enter(/*node*/) {
  this.depth++;
  this.newline();
  this.stdout.write(this.pad() + '<ul>');
  this.depth++;
}

/**
 *  Exit child nodes.
 */
function exit(/*node*/) {
  this.depth--;
  this.newline();
  this.stdout.write(this.pad() + '</ul>');

  this.depth--;
  this.newline();
  this.stdout.write(this.pad() + '</li>');
}

/**
 *  Render a list item.
 */
function item(node) {
  var indent = this.pad()
    , child = this.pad(this.depth + 1)
    , link = child + '<span>' + node.label + '</span>'
    , href = node.path;

  if(this.link === 'absolute') {
    href = node.url;
  }

  // NOTE: href might not be valid when crawling a deep url 
  // NOTE: with no parents
  if(href && this.link !== 'none') {
    link = child + '<a href="' + href + '">' + node.label + '</a>';
  }

  this.newline();
  this.stdout.write(indent + '<li>');

  this.newline();
  this.stdout.write(link);

  if(this.description !== false && node.meta && node.meta.description) {
    this.newline();
    this.stdout.write(child + '<span>' + node.meta.description + '</span>');
  }

  if(!node.nodes.length) {
    this.newline();
    this.stdout.write(indent + '</li>');
  }
}

/**
 *  Close the root list.
 */
function close() {
  this.depth--;
  this.newline();
  this.stdout.write('</ul>');
}

Html.prototype.open = open;
Html.prototype.item = item;
Html.prototype.close = close;

Html.prototype.enter = enter;
Html.prototype.exit = exit;

Html.prototype.newline = newline;
Html.prototype.pad = pad;

module.exports = Html;
{'fraction_non_alphanumeric': 0.2037037037037037, 'fraction_numerical': 0.0022888056595921765, 'mean_word_length': 2.9925249169435215, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '4116955', 'n_tokens_mistral': 1718, 'n_tokens_neox': 1672, 'n_words': 364}