<commit_before>var officegen = require('officegen');
var fs = require('fs');
var doc = officegen('pptx');
var out = fs.createWriteStream('out.pptx');

liedbase.controller('PreviewController', function ($sce, $scope, log, Liturgie) {
  $scope.liturgie = Liturgie;

  $scope.getHtml = function (data) {
    return $sce.trustAsHtml(data)
  }

  $scope.generate = function () {
    $scope.liturgie.forEach(function (element) {
      element.documents.forEach(function (document) {
        makeSongSlide(element.regel, document.verse, document.text)
      }, this);
    }, this);
    doc.generate(out, {
      'finalize': function (written) {
        console.log('Finish to create a PowerPoint file.\nTotal bytes created: ' + written + '\n');
      },
      'error': function (err) {
        console.log(err);
      }
    });
  }

  out.on('close', function () {
    console.log('Finished to create the PPTX file!');
  });

  var makeSongSlide = function (title, highlight, text) {
    var slide = doc.makeNewSlide();
    var titleInParts = getTitleParts(title, highlight)
    console.log(titleInParts)
    slide.addText([
      { text: titleInParts[0], options: { bold: false, font_size: 24 } },
      { text: titleInParts[1].toString(), options: { bold: true, font_size: 24 } },
      { text: titleInParts[2], options: { bold: false, font_size: 24 } }
    ], { cx: "90%" });
  }

  var getTitleParts = function (title, highlight) {

    if (title.search(':') == -1)
      return title

    // start by replacing *whitespaces with a single whitespace
    title = title.replace(/ +/g, " ")
    // split on ':'
    var titleParts = title.split(':')
    // remove whitespaces from second part 
    titleParts[1] = titleParts[1].replace(/ /g, '')
    // reassemble, replace comma's in second part by comma+whitespace
    title = titleParts[0] + ': ' + titleParts[1].replace(/,/g, ', ')

    // extract the verse being displayed
    var regex = new RegExp("(.*[^\d])(" + highlight + ")((?:[^\d]|$)(?:[0-9, ]*))")
    var match = regex.exec(title)
    var titleInParts = []
    titleInParts.push(match[1])
    titleInParts.push(highlight)
    if (match[3] != '')
      titleInParts.push(match[3])
    else
      titleInParts.push('')
    return titleInParts
  }

})<commit_msg>updated some<commit_after>var fs = require('fs');
var out = fs.createWriteStream('out.pptx');
var officegen = require('officegen');

liedbase.controller('PreviewController', function ($sce, $scope, log, Liturgie) {
  $scope.liturgie = Liturgie;
  var doc = officegen('pptx');

  $scope.getHtml = function (data) {
    return $sce.trustAsHtml(data)
  }

  $scope.generate = function () {
    $scope.liturgie.forEach(function (element) {
      element.documents.forEach(function (document) {
        makeSongSlide(doc, element.regel, document.verse, document.text)
      }, this);
    }, this);
    doc.generate(out, {
      'finalize': function (written) {
        console.log('Finish to create a PowerPoint file.\nTotal bytes created: ' + written + '\n');
      },
      'error': function (err) {
        console.log(err);
      }
    });
  }

  out.on('close', function () {
    console.log('Finished to create the PPTX file!');
  });

  var makeSongSlide = function (doc, title, highlight, text) {
    var slide = doc.makeNewSlide();
    var titleInParts = getTitleParts(title, highlight)
    if(titleInParts.length == 3) {
      slide.addText([
        { text: titleInParts[0], options: { bold: false, font_size: 24 } },
        { text: titleInParts[1].toString(), options: { bold: true, font_size: 24 } },
        { text: titleInParts[2], options: { bold: false, font_size: 24 } }
      ], { cx: "90%" });
    } else {
      slide.addText([
        { text: titleInParts, options: { bold: false, font_size: 24 } }
      ], { cx: "90%" });
    }
  }

  var getTitleParts = function (title, highlight) {

    if (title.search(':') == -1)
      return title

    // start by replacing *whitespaces with a single whitespace
    title = title.replace(/ +/g, " ")
    // split on ':'
    var titleParts = title.split(':')
    // remove whitespaces from second part 
    titleParts[1] = titleParts[1].replace(/ /g, '')
    // reassemble, replace comma's in second part by comma+whitespace
    title = titleParts[0] + ': ' + titleParts[1].replace(/,/g, ', ')

    // extract the verse being displayed
    var regex = new RegExp("(.*[^\d])(" + highlight + ")((?:[^\d]|$)(?:[0-9, ]*))")
    var match = regex.exec(title)
    var titleInParts = []
    titleInParts.push(match[1])
    titleInParts.push(highlight)
    if (match[3] != '')
      titleInParts.push(match[3])
    else
      titleInParts.push('')
    return titleInParts
  }

})
{'fraction_non_alphanumeric': 0.16922094508301405, 'fraction_numerical': 0.010004257130693913, 'mean_word_length': 2.999148936170213, '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': '4793783', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1517, 'n_words': 355}