<commit_before>module Markdownplus
  class Handler
    def execute(input, parameters, variables, warnings, errors)
    end
  end

  class IncludeHandler < Handler
    def execute(input, parameters, variables, warnings, errors)
      output = nil
      warnings << "Include handler ignores input" if(input!=nil && !input.strip.empty?)
      if parameters==nil
        errors << "No url given"
      elsif parameters.count == 0
        errors << "No url given"
      else
        begin
          output = IncludeHandler.cached(parameters.first.to_s)
        rescue => e
          errors << "Error opening [#{parameters.first}] [#{e.message}]"
        end
      end
      output
    end

    @@cache = {}
    def self.cached(url)
      return @@cache[url] if @@cache[url]
      @@cache[url] = open(url).read
      @@cache[url]
    end
  end
  HandlerRegistry.register("include", IncludeHandler)

  class Csv2HtmlHandler < Handler
    def execute(input, parameters, variables, warnings, errors)
      output = "<table class='table table-striped'>"
      row_num = 0
      CSV.parse(input) do |row|
        if row_num == 0
          output += "<thead><tr>#{row.collect { |c| "<th>#{c}</th>"}.join}</tr></thead>\n<tbody>\n"
        else
          output += "<tr>#{row.collect { |c| "<td>#{c}</td>"}.join}</tr>\n"
        end
        row_num += 1
      end
      output += "</tbody></table>"
      output<commit_msg>Handle nil inputs more gracefully in the csv2html handler<commit_after>module Markdownplus
  class Handler
    def execute(input, parameters, variables, warnings, errors)
    end
  end

  class IncludeHandler < Handler
    def execute(input, parameters, variables, warnings, errors)
      output = nil
      warnings << "Include handler ignores input" if(input!=nil && !input.strip.empty?)
      if parameters==nil
        errors << "No url given"
      elsif parameters.count == 0
        errors << "No url given"
      else
        begin
          output = IncludeHandler.cached(parameters.first.to_s)
        rescue => e
          errors << "Error opening [#{parameters.first}] [#{e.message}]"
        end
      end
      output
    end

    @@cache = {}
    def self.cached(url)
      return @@cache[url] if @@cache[url]
      @@cache[url] = open(url).read
      @@cache[url]
    end
  end
  HandlerRegistry.register("include", IncludeHandler)

  class Csv2HtmlHandler < Handler
    def execute(input, parameters, variables, warnings, errors)
      if input
        output = "<table class='table table-striped'>"
        row_num = 0
        CSV.parse(input) do |row|
          if row_num == 0
            output += "<thead><tr>#{row.collect { |c| "<th>#{c}</th>"}.join}</tr></thead>\n<tbody>\n"
          else
            output += "<tr>#{row.collect { |c| "<td>#{c}</td>"}.join}</tr>\n"
          end
          row_num += 1
        end
        output += "</tbody></table>"
        output
      else
        errors << "No input given"
        ""
      end
{'fraction_non_alphanumeric': 0.13948787061994608, 'fraction_numerical': 0.003706199460916442, 'mean_word_length': 2.2879291251384273, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 33, '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': '2238231', 'n_tokens_mistral': 901, 'n_tokens_neox': 867, 'n_words': 233}