<commit_before>module Jekyll
  class IncludeCodeTag < Liquid::Tag
    include Liquid::StandardFilters

    # This is the base domain we will link to for samples.
    sample_link_base = "https://google-developers.appspot.com/"

    def initialize(tag_name, markup, tokens)
      super
      @file, @section = markup.strip.split(' ', 2)
    end

    def render(context)
        page = context.environments.first["page"]
        path = context.registers[:site].source;
        String filepath = File.join(File.dirname(page["path"]), @file)
        String file = File.join(path, filepath)
        contents = File.read(file)
        snippet = contents.match(/<!-- \/\/ \[START #{@section}\] -->(.*)<!-- \/\/ \[END #{@section}\] -->/im)[1];
        render_codehighlighter(context, snippet, filepath)
    end

    def render_codehighlighter(context, code, filepath)
      # TODO(ianbarber): Auto indent
      # TODO(ianbarber): Syntax highlighting goes here.
      # TODO(ianbarber): Include sample link base once testing.
        <<-HTML
  <div>
    <pre><code class='html'>#{h(code).strip}</code></pre>
    <a href="/_samples/#{filepath}">View full sample</a>
  </div>
        HTML
      end
  end
end

Liquid::Template.register_tag('include_code', Jekyll::IncludeCodeTag)<commit_msg>Moving to pygments for highlighting<commit_after>module Jekyll
  class IncludeCodeTag < Liquid::Tag
    include Liquid::StandardFilters

    # This is the base domain we will link to for samples.
    sample_link_base = "https://google-developers.appspot.com/"

    def initialize(tag_name, markup, tokens)
      super
      @options = {}
      @lang = 'html'
      @file, @section = markup.strip.split(' ', 2)
    end

    def render(context)
        page = context.environments.first["page"]
        path = context.registers[:site].source;
        String filepath = File.join(File.dirname(page["path"]), @file)
        String file = File.join(path, filepath)
        contents = File.read(file)
        snippet = contents.match(/<!-- \/\/ \[START #{@section}\] -->(.*)<!-- \/\/ \[END #{@section}\] -->/im)[1];
        render_codehighlighter(context, snippet, filepath)
    end

    def render_codehighlighter(context, code, filepath)
      require 'pygments'
      @options[:encoding] = 'utf-8'
      highlighted_code = Pygments.highlight(code, :lexer => @lang, :options => @options)
      if highlighted_code.nil?
          Jekyll.logger.error "There was an error highlighting your code."
      end
      # TODO(ianbarber): Auto indent
      # TODO(ianbarber): Syntax highlighting goes here.
      # TODO(ianbarber): Include sample link base once testing.
      # snippet.each_line {|s| output += "    " + s}
        <<-HTML
  <div>
    <pre><code class='html'>#{highlighted_code.strip}</code></pre>
    <a href="/_samples/#{filepath}">View full sample</a>
  </div>
        HTML
      end
  end
end

Liquid::Template.register_tag('include_code', Jekyll::IncludeCodeTag)
{'fraction_non_alphanumeric': 0.14920311970159375, 'fraction_numerical': 0.00169548999660902, 'mean_word_length': 2.9176626826029217, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 25, 'https://': 2, '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': '5304623', 'n_tokens_mistral': 936, 'n_tokens_neox': 898, 'n_words': 213}