<commit_before>var mustache = require('mustache');
var input = "Apps\nBooks\nDev's blog\n  Test.md\n  Foo.txt";
var fs = require('fs-extra');
var cheerio = require('cheerio');
var template = fs.readFileSync(__dirname + '/window.mustache', 'utf8');
var texteditor_template = fs.readFileSync(__dirname + '/texteditor.mustache', 'utf8');
var codeeditor_template = fs.readFileSync(__dirname + '/codeeditor.mustache', 'utf8');
var wrapper = fs.readFileSync(__dirname + '/wrapper.mustache', 'utf8');
var highlight = require('highlight.js');

// console.log(highlight.highlight('html','<html>\n\t<head>\n\t\t<title>{{title}}</title>\n\t</head>\n\t<body>\n\t\t{{#posts}}\n\t\t<a href="{{url}}">{{title}}</a>\n\t\t{{/posts}}\n\t</body>\n</html>').value);

function extension (filename) {
  var extension = ''; 

  if (filename.indexOf('.') === -1) return 'folder';

  extension = filename.slice(filename.lastIndexOf('.') + 1);

  if (['jpg', 'jpeg', 'gif', 'png'].indexOf(extension) > -1)
    extension = 'img';

  if (['css', 'js'].indexOf(extension) > -1)
    extension = 'md';

  return extension;
}

function main (input) {

  input = input.trim();

  var files = input.split('\n');

  for (var i = 0;i < files.length;i++) {

    var file = {};

    file.name = files[i].trim();
    file.nested = files[i][0] !== files[i].trim()[0];
    file.open = false;

    // Indicate the parent folder for this file
    // we use this info to rotate the arrow next to the
    // folder icon in the finder.
    if (file.nested && !files[i - 1].nested)
      files[i - 1].open = 'open';

    file.file = file.name.indexOf('.') > -1;
    file.folder = !file.file;

    if (file.file)
      file.extension = extension(file.name);

    if (file.open)
      file.open = 'open';
    else 
      file.open = '';

    if (file.nested)
      file.nested = 'nested';
    else 
      file.nested = '';

    if (file.folder)
      file.folder = 'folder';
    else 
      file.folder = '';

    if (file.file)
      file.file = 'file';
    else 
      file.file = '';


    files[i] = file;
  }

  var output = mustache.render(template, {contents: files, title: 'Your blog'});


  return output;
}

function texteditor(text) {
  return mustache.render(texteditor_template, {text: text, title: 'Your post.txt'});
}

function codeeditor(lang, code) {
  code = highlight.highlight(lang,code).value;
  console.log(code);
  return mustache.render(codeeditor_template, {code: code, title: 'Your post.txt'});
}

function exports (html, callback) {

  var $ = cheerio.load(html);

  $('pre.folder').each(function(i, el){<commit_msg>Fixed issues with code highlighting<commit_after>var mustache = require('mustache');
var input = "Apps\nBooks\nDev's blog\n  Test.md\n  Foo.txt";
var fs = require('fs-extra');
var cheerio = require('cheerio');
var template = fs.readFileSync(__dirname + '/window.mustache', 'utf8');
var texteditor_template = fs.readFileSync(__dirname + '/texteditor.mustache', 'utf8');
var codeeditor_template = fs.readFileSync(__dirname + '/codeeditor.mustache', 'utf8');
var wrapper = fs.readFileSync(__dirname + '/wrapper.mustache', 'utf8');
var highlight = require('highlight.js');

// console.log(highlight.highlight('html','<html>\n\t<head>\n\t\t<title>{{title}}</title>\n\t</head>\n\t<body>\n\t\t{{#posts}}\n\t\t<a href="{{url}}">{{title}}</a>\n\t\t{{/posts}}\n\t</body>\n</html>').value);

function extension (filename) {
  var extension = ''; 

  if (filename.indexOf('.') === -1) return 'folder';

  extension = filename.slice(filename.lastIndexOf('.') + 1);

  if (['jpg', 'jpeg', 'gif', 'png'].indexOf(extension) > -1)
    extension = 'img';

  if (['css', 'js'].indexOf(extension) > -1)
    extension = 'md';

  return extension;
}

function main (input) {

  input = input.trim();

  var files = input.split('\n');

  for (var i = 0;i < files.length;i++) {

    var file = {};

    file.name = files[i].trim();
    file.nested = files[i][0] !== files[i].trim()[0];
    file.open = false;

    // Indicate the parent folder for this file
    // we use this info to rotate the arrow next to the
    // folder icon in the finder.
    if (file.nested && !files[i - 1].nested)
      files[i - 1].open = 'open';

    file.file = file.name.indexOf('.') > -1;
    file.folder = !file.file;

    if (file.file)
      file.extension = extension(file.name);

    if (file.open)
      file.open = 'open';
    else 
      file.open = '';

    if (file.nested)
      file.nested = 'nested';
    else 
      file.nested = '';

    if (file.folder)
      file.folder = 'folder';
    else 
      file.folder = '';

    if (file.file)
      file.file = 'file';
    else 
      file.file = '';


    files[i] = file;
  }

  var output = mustache.render(template, {contents: files, title: 'Your blog'});


  return output;
}

function texteditor(text) {
  return mustache.render(texteditor_template, {text: text, title: 'Your post.txt'});
}

function codeeditor(lang, code) {
  console.log(lang, code);
  code = code.split('&quot;').join('"');

  code = highlight.highlight(lang,code).value;
  code = code.split('&amp;apos;').join("'");
  console.log(lang, code);
  return mustache.render(codeeditor_template, {code: code, title: 'Your post.txt'});
}

function exports (html, callback) {

  var $ = cheerio.load(html);

  $('pre.folder').each(function(i, el){
{'fraction_non_alphanumeric': 0.19643527204502814, 'fraction_numerical': 0.00525328330206379, 'mean_word_length': 3.320097244732577, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 29, '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': '4129379', 'n_tokens_mistral': 1887, 'n_tokens_neox': 1801, 'n_words': 402}