<commit_before>const hljs = require('highlight.js');
const fs = require('fs');
const css = require('css');
const he = require('he');
const getInstalledPath = require('get-installed-path');
const parse = require('parse-color');

const sourceFile = fs.readFileSync('index.js', 'utf8');
var htmlString = hljs.highlight('js', sourceFile).value;

const cssObject = loadStyle('darcula');
const conversionTable = generateHTMLToConsoleConversionTable(cssObject);

conversionTable.forEach(({ name, value }) => {
  const rgbArray = parse(value).rgb;
  const fixedRgbArray = rgbArray == undefined ? [255, 255, 255] : rgbArray;
  //'\x1b' +
  htmlString = htmlString
    .split(name)
    .join(
      '\x1b' +
        '[38;2;' +
        `${fixedRgbArray[0]};${fixedRgbArray[1]};${fixedRgbArray[2]}m`
    );
});
htmlString = htmlString.split('</span>').join('\x1b[0m');
htmlString = htmlString.replace(/<span class="[a-z,-]*">/gm, '');
const unescapedHtmlString = he.unescape(htmlString);

console.log(unescapedHtmlString);

function generateHTMLToConsoleConversionTable(cssObject) {
  var lookupObject = [];
  cssObject.stylesheet.rules.forEach(rule => {
    if (rule.type == 'rule') {
      rule.declarations.forEach(declaration => {
        if (declaration.property == 'color') {
          rule.selectors.forEach(cssName => {
            const splitNames = cssName.split(' ');
            splitNames.forEach(splitCssName => {
              lookupObject.push({
                name: `<span class="${splitCssName.substr(1)}">`,
                value: `${declaration.value}`
              });
            });
          });<commit_msg>Moved colour logic into table builder<commit_after>const hljs = require('highlight.js');
const fs = require('fs');
const css = require('css');
const he = require('he');
const getInstalledPath = require('get-installed-path');
const parse = require('parse-color');

const sourceFile = fs.readFileSync('index.js', 'utf8');
var htmlString = hljs.highlight('js', sourceFile).value;

const cssObject = loadStyle('darcula');
const conversionTable = generateHTMLToConsoleConversionTable(cssObject);

conversionTable.forEach(({ name, value }) => {
  htmlString = htmlString
    .split(name)
    .join('\x1b' + '[38;2;' + `${value[0]};${value[1]};${value[2]}m`);
});
htmlString = htmlString.split('</span>').join('\x1b[0m');
htmlString = htmlString.replace(/<span class="[a-z,-]*">/gm, '');
const unescapedHtmlString = he.unescape(htmlString);

console.log(unescapedHtmlString);

function generateHTMLToConsoleConversionTable(cssObject) {
  var lookupObject = [];
  cssObject.stylesheet.rules.forEach(rule => {
    if (rule.type == 'rule') {
      rule.declarations.forEach(declaration => {
        if (declaration.property == 'color') {
          rule.selectors.forEach(cssName => {
            const splitNames = cssName.split(' ');
            splitNames.forEach(splitCssName => {
              const rgbArray = parse(declaration.value).rgb;
              const fixedRgbArray = rgbArray == undefined
                ? [255, 255, 255]
                : rgbArray;
              lookupObject.push({
                name: `<span class="${splitCssName.substr(1)}">`,
                value: rgbArray
              });
            });
          });
{'fraction_non_alphanumeric': 0.16804915514592933, 'fraction_numerical': 0.012596006144393242, 'mean_word_length': 3.370469798657718, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '2506385', 'n_tokens_mistral': 1025, 'n_tokens_neox': 992, 'n_words': 175}