<commit_before>use v6;
use HTML::Entity;

module Cantilever::Page::Types {
  class Cantilever::Page::CustomTag is export {
    has &.matches-fn is required;
    has &.render-fn is required;
    has Bool $.block = False;
    method matches($x) { &!matches-fn($x); }
    method render($x, %options) { &!render-fn($x, %options); }
  }

  role Cantilever::Page::SourceNode is export {
    method to-html(%options) { ... }
  }

  class Cantilever::Page::PageSource does Cantilever::Page::SourceNode is export {
    has @.content = [];
    has %.meta = {}; 
    method to-html(%options) {
      @.content.map(*.to-html(%options)).join("\n");
    }
  }

  class Cantilever::Page::Text does Cantilever::Page::SourceNode is export {
    has Str $.txt is required;
    method to-html(%options) { $.txt.subst(/'%root%'/, %options<root>); }
  }

  class Cantilever::Page::SourceCode does Cantilever::Page::SourceNode is export {
    has Str $.src = "";
    method to-html(%options) {
      encode-entities($.src);
    }
  }

  class Cantilever::Page::Comment does Cantilever::Page::SourceNode is export {
    has Str $.content = "";
    method to-html(%options) {
      $.content;
    }
  }<commit_msg>Support for inline YouTube videos<commit_after>use v6;
use HTML::Entity;

module Cantilever::Page::Types {
  class Cantilever::Page::CustomTag is export {
    has &.matches-fn is required;
    has &.render-fn is required;
    has Bool $.block = False;
    method matches($x) { &!matches-fn($x); }
    method render($x, %options) { &!render-fn($x, %options); }
  }

  role Cantilever::Page::SourceNode is export {
    method to-html(%options) { ... }
  }

  class Cantilever::Page::PageSource does Cantilever::Page::SourceNode is export {
    has @.content = [];
    has %.meta = {}; 
    method to-html(%options) {
      @.content.map(*.to-html(%options)).join("\n");
    }
  }

  class Cantilever::Page::Text does Cantilever::Page::SourceNode is export {
    has Str $.txt is required;
    method to-html(%options) {
      my $replaced = $.txt.subst(/'%root%'/, %options<root>);
      $replaced ~~ s/[['http' 's'? '://']? 'www.']? 'youtube.com/watch?v=' (\w+) '/'?/<iframe class="youtube embed" width="560" height="315" src="http:\/\/www.youtube.com\/embed\/$0?rel=0" frameborder="0" allowfullscreen><\/iframe>/;
      return $replaced;
    }
  }

  class Cantilever::Page::SourceCode does Cantilever::Page::SourceNode is export {
    has Str $.src = "";
    method to-html(%options) {
      encode-entities($.src);
    }
  }

  class Cantilever::Page::Comment does Cantilever::Page::SourceNode is export {
    has Str $.content = "";
    method to-html(%options) {
      $.content;
    }
  }
{'fraction_non_alphanumeric': 0.18374953410361536, 'fraction_numerical': 0.004099888184867686, 'mean_word_length': 3.2875399361022364, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3601471', 'n_tokens_mistral': 913, 'n_tokens_neox': 887, 'n_words': 198}