<commit_before><?php namespace OParl\Spec;

use Illuminate\Contracts\Cache\Repository as CacheRepository;
use Illuminate\Contracts\Filesystem\Filesystem;
use Pandoc\Pandoc;
use Symfony\Component\DomCrawler\Crawler;

class LiveCopyRepository
{
  const CHAPTER_PATH = 'livecopy/';
  const IMAGE_PATH = 'livecopy/images/';

  /**
   * @var \Illuminate\Support\Collection
   **/
  protected $chapters = null;

  protected $content = '';
  protected $nav = '';

  public function __construct(Filesystem $fs, CacheRepository $cache)
  {
    $this->chapters = $cache->rememberForever('livecopy:chapters',
      function () use ($fs) {
        $files = collect($fs->allFiles(static::CHAPTER_PATH))->sort();

        return $files->filter(function ($file) {
          return ends_with($file, '.md');
        })->map(function ($chapterFile) use ($fs) {
          return new Chapter($fs, $chapterFile);
        });
      }
    );

    $this->parse($cache);
  }

  public function getRaw()
  {
    return $this->chapters->reduce(function ($carry, Chapter $chapter) {
      return $carry . "\n" . $chapter->getRaw();
    }, '');
  }

  /**
   * @return string
   */
  public function getContent()
  {
    return $this->content;
  }

  /**
   * @return string
   */
  public function getNav()
  {
    return $this->nav;
  }

  protected function parseMarkdown($markdown)
  {
    // transform with pandoc
    $pandoc = new Pandoc();

    $html = $pandoc->runWith($markdown, [
      'number-sections' => null,
      'section-divs' => null,
      'table-of-contents' => null,
      'standalone' => null,
      'from' => 'markdown+header_attributes',
      'to' => 'html5',
      'toc-depth' => 2,
    ]);

    return $html;
  }

  /**<commit_msg>Removed unneeded first 'chapter' from output.<commit_after><?php namespace OParl\Spec;

use Illuminate\Contracts\Cache\Repository as CacheRepository;
use Illuminate\Contracts\Filesystem\Filesystem;
use Pandoc\Pandoc;
use Symfony\Component\DomCrawler\Crawler;

class LiveCopyRepository
{
  const CHAPTER_PATH = 'livecopy/';
  const IMAGE_PATH = 'livecopy/images/';

  /**
   * @var \Illuminate\Support\Collection
   **/
  protected $chapters = null;

  protected $content = '';
  protected $nav = '';

  public function __construct(Filesystem $fs, CacheRepository $cache)
  {
    $this->chapters = $cache->rememberForever('livecopy:chapters',
      function () use ($fs) {
        $files = collect($fs->allFiles(static::CHAPTER_PATH))->sort();
        $files->forget(0);

        return $files->filter(function ($file) {
          return ends_with($file, '.md');
        })->map(function ($chapterFile) use ($fs) {
          return new Chapter($fs, $chapterFile);
        });
      }
    );

    $this->parse($cache);
  }

  public function getRaw()
  {
    return $this->chapters->reduce(function ($carry, Chapter $chapter) {
      return $carry . "\n" . $chapter->getRaw();
    }, '');
  }

  /**
   * @return string
   */
  public function getContent()
  {
    return $this->content;
  }

  /**
   * @return string
   */
  public function getNav()
  {
    return $this->nav;
  }

  protected function parseMarkdown($markdown)
  {
    // transform with pandoc
    $pandoc = new Pandoc();

    $html = $pandoc->runWith($markdown, [
      'number-sections' => null,
      'section-divs' => null,
      'table-of-contents' => null,
      'standalone' => null,
      'from' => 'markdown',
      'to' => 'html5',
      'toc-depth' => 2,
    ]);

    return $html;
  }

  /**
{'fraction_non_alphanumeric': 0.16404687053443842, 'fraction_numerical': 0.0014289797084881394, 'mean_word_length': 2.800217155266015, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 44, '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': '1859020', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1129, 'n_words': 228}