<commit_before>require "html_inline_css/version"
require "nokogiri"

module InlineCssString
  class CSS

    def self.get_all_class_and_ids
      @html_tags.each do |tag|
        @doc_to.css("#{tag}").each do |y|
          unless y.nil? 
            if @classes.empty?
              @classes << y["class"].to_s;
            else
              @classes.each do |css_class|; unless css_class == y["class"] || y["class"].nil?; @classes << y["class"].to_s; break; end; end;
            end
            if @ids.empty?
              @ids << y["id"].to_s;
            else
              @ids.each do |css_id|; unless css_id == y["id"] || y["id"].nil?; @ids << y["id"].to_s; break; end; end;
            end
          end
        end
      end
    end

    def self.add_style_tag_to_html(html)
      @html_tags.each do |tag|
        html.css("#{tag}").each do |x| 
          unless x.nil? 
            unless x.to_s.match(/<#{Regexp.escape(tag)}\s(.*?)style=('|")(.*?)('|")(.*?)>/)
              x['style'] = ''
            end
          end
        end
      end
    end

    def self.add_style(tag, arr)
      unless arr.nil?; 
      	no_newline_arr = arr.gsub(/\n|\r/,"")
        @doc_to.css("#{tag}").each do |y|
          unless y.nil? 
            y.to_s.scan(/style="([^"]*)"|style='([^"]*)'/).flatten.select{ |i| !i.nil?; unless i.nil?; y['style'] = "#{no_newline_arr}#{i}" end }				
          end
        end
      end
    end

    def self.add_style_by_id_or_class(id_or_class_name, arr, id_or_class)
      unless arr.nil?; 
      	no_newline_arr = arr.gsub(/\n|\r/,"")
        if id_or_class == "class"
          @html_tags.each do |tag|
            @doc_to.xpath("#{tag}[@class = '#{id_or_class_name}']").each do |y|
              unless y.nil? 
                y.to_s.scan(/style="([^"]*)"|style='([^"]*)'/).flatten.select{ |i| !i.nil?; unless i.nil?; y['style'] = "#{no_newline_arr}#{i}" end }				
              end
            end
          end
        else
          @html_tags.each do |tag|
            @doc_to.xpath("#{tag}[@class = '#{id_or_class_name}']").each do |y|
              unless y.nil? 
                y.to_s.scan(/style="([^"]*)"|style='([^"]*)'/).flatten.select{ |i| !i.nil?; unless i.nil?; y['style'] = "#{arr}#{i}" end }				
               end
            end
          end
        end
      end
    end

    def self.add_style_by_id_or_class_to_child(id_or_class_name, arr, id_or_class)
      unless arr.nil?; 
      	no_newline_arr = arr.gsub(/\n|\r/,"")
        if id_or_class == "class"
          @html_tags.each do |tag|
            @doc_to.xpath("#{tag}[@class = '#{id_or_class_name}']").each do |y|
              unless y.nil? 
                y.xpath("#{tag}").each do |c|
                  c.to_s.scan(/style="([^"]*)"|style='([^"]*)'/).flatten.select{ |i| !i.nil?; unless i.nil?; c['style'] = "#{no_newline_arr}#{i}" end }				
                end
              end
            end
          end
        else
          @html_tags.each do |tag|
            @doc_to.xpath("#{tag}[@id = '#{id_or_class_name}']").each do |y|
              unless y.nil? 
                y.xpath("#{tag}").each do |c|
                  c.to_s.scan(/style="([^"]*)"|style='([^"]*)'/).flatten.select{ |i| !i.nil?; unless i.nil?; c['style'] = "#{arr}#{i}" end }				
                end
              end
            end
          end
        end
      end
    end

    def self.inline_css_with_class_and_html(html)
      style_tags = html.search('style').map { |n| n.inner_text }
      style_tags.each do |tag|
        # CLASS<commit_msg>removing tabs from style<commit_after>require "html_inline_css/version"
require "nokogiri"

module InlineCssString
  class CSS

    def self.get_all_class_and_ids
      @html_tags.each do |tag|
        @doc_to.css("#{tag}").each do |y|
          unless y.nil? 
            if @classes.empty?
              @classes << y["class"].to_s;
            else
              @classes.each do |css_class|; unless css_class == y["class"] || y["class"].nil?; @classes << y["class"].to_s; break; end; end;
            end
            if @ids.empty?
              @ids << y["id"].to_s;
            else
              @ids.each do |css_id|; unless css_id == y["id"] || y["id"].nil?; @ids << y["id"].to_s; break; end; end;
            end
          end
        end
      end
    end

    def self.add_style_tag_to_html(html)
      @html_tags.each do |tag|
        html.css("#{tag}").each do |x| 
          unless x.nil? 
            unless x.to_s.match(/<#{Regexp.escape(tag)}\s(.*?)style=('|")(.*?)('|")(.*?)>/)
              x['style'] = ''
            end
          end
        end
      end
    end

    def self.add_style(tag, arr)
      unless arr.nil?; 
      	no_newline_arr = arr.gsub(/\n|\r|\t/,"")
        @doc_to.css("#{tag}").each do |y|
          unless y.nil? 
            y.to_s.scan(/style="([^"]*)"|style='([^"]*)'/).flatten.select{ |i| !i.nil?; unless i.nil?; y['style'] = "#{no_newline_arr}#{i}" end }				
          end
        end
      end
    end

    def self.add_style_by_id_or_class(id_or_class_name, arr, id_or_class)
      unless arr.nil?; 
      	no_newline_arr = arr.gsub(/\n|\r|\t/,"")
        if id_or_class == "class"
          @html_tags.each do |tag|
            @doc_to.xpath("#{tag}[@class = '#{id_or_class_name}']").each do |y|
              unless y.nil? 
                y.to_s.scan(/style="([^"]*)"|style='([^"]*)'/).flatten.select{ |i| !i.nil?; unless i.nil?; y['style'] = "#{no_newline_arr}#{i}" end }				
              end
            end
          end
        else
          @html_tags.each do |tag|
            @doc_to.xpath("#{tag}[@class = '#{id_or_class_name}']").each do |y|
              unless y.nil? 
                y.to_s.scan(/style="([^"]*)"|style='([^"]*)'/).flatten.select{ |i| !i.nil?; unless i.nil?; y['style'] = "#{arr}#{i}" end }				
               end
            end
          end
        end
      end
    end

    def self.add_style_by_id_or_class_to_child(id_or_class_name, arr, id_or_class)
      unless arr.nil?; 
      	no_newline_arr = arr.gsub(/\n|\r|\t/,"")
        if id_or_class == "class"
          @html_tags.each do |tag|
            @doc_to.xpath("#{tag}[@class = '#{id_or_class_name}']").each do |y|
              unless y.nil? 
                y.xpath("#{tag}").each do |c|
                  c.to_s.scan(/style="([^"]*)"|style='([^"]*)'/).flatten.select{ |i| !i.nil?; unless i.nil?; c['style'] = "#{no_newline_arr}#{i}" end }				
                end
              end
            end
          end
        else
          @html_tags.each do |tag|
            @doc_to.xpath("#{tag}[@id = '#{id_or_class_name}']").each do |y|
              unless y.nil? 
                y.xpath("#{tag}").each do |c|
                  c.to_s.scan(/style="([^"]*)"|style='([^"]*)'/).flatten.select{ |i| !i.nil?; unless i.nil?; c['style'] = "#{arr}#{i}" end }				
                end
              end
            end
          end
        end
      end
    end

    def self.inline_css_with_class_and_html(html)
      style_tags = html.search('style').map { |n| n.inner_text }
      style_tags.each do |tag|
        # CLASS
{'fraction_non_alphanumeric': 0.19134588367518965, 'fraction_numerical': 0.0, 'mean_word_length': 1.6914933837429111, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 5, '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': '2061270', 'n_tokens_mistral': 2634, 'n_tokens_neox': 2572, 'n_words': 458}