<commit_before>module ImageHelper
  def check_title(image)
    get_notice(image.title, image.is_for_sale? ? Image::TITLE_MIN_FOR_SALE : Image::TITLE_MIN, 'words')
  end

  def check_desc(image)
    get_notice(render_image_data(I18n.locale, image), image.is_for_sale? ? Image::DESC_MIN_FOR_SALE : Image::DESC_MIN, 'words')
  end

  def check_tags(image)
    get_notice(image.tags_resolved, image.is_for_sale? ? Image::TAGS_MIN_FOR_SALE : Image::TAGS_MIN, 'tags')
  end

  ##
  # Replace urls with links
  #
  def highlight_links(text)
    begin
      new_text = text.dup
      while new_text =~ /([\s\r\n]+|^)(http:\/\/|https:\/\/|www.)([^\s\r\n]*\.[^\s\r\n]*)([\s\r\n]+|$)/s
        protocol = $2
        href = $3
        new_text.gsub!("#{protocol}#{href}", "<a href='#{protocol}#{href}' rel='nofollow'>#{protocol}#{href}</a>")
      end
      new_text
    rescue
      text
    end
  end

  private

  def get_notice(str, need_words, object_names)
    if str.scan(/\w+/).size < need_words
      "<span class=\"label label-important\">need #{need_words} #{object_names}</span>".html_safe
    end
  end
end<commit_msg>highlight links in non-ascii texts<commit_after># encoding: UTF-8

module ImageHelper
  def check_title(image)
    get_notice(image.title, image.is_for_sale? ? Image::TITLE_MIN_FOR_SALE : Image::TITLE_MIN, 'words')
  end

  def check_desc(image)
    get_notice(render_image_data(I18n.locale, image), image.is_for_sale? ? Image::DESC_MIN_FOR_SALE : Image::DESC_MIN, 'words')
  end

  def check_tags(image)
    get_notice(image.tags_resolved, image.is_for_sale? ? Image::TAGS_MIN_FOR_SALE : Image::TAGS_MIN, 'tags')
  end

  ##
  # Replace urls with links
  #
  def highlight_links(text)
    begin
      new_text = text.dup
      while new_text =~ /([\s\r\n]+|^)(http:\/\/|https:\/\/|www.)([^\s\r\n]*\.[^\s\r\n]*)([\s\r\n]+|$)/su
        protocol = $2
        href = $3
        new_text.gsub!("#{protocol}#{href}", "<a href='#{protocol}#{href}' rel='nofollow'>#{protocol}#{href}</a>")
      end
      new_text
    rescue
      text
    end
  end

  private

  def get_notice(str, need_words, object_names)
    if str.scan(/\w+/u).size < need_words
      "<span class=\"label label-important\">need #{need_words} #{object_names}</span>".html_safe
    end
  end
end
{'fraction_non_alphanumeric': 0.17456140350877192, 'fraction_numerical': 0.003947368421052632, 'mean_word_length': 3.4463937621832357, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '5801969', 'n_tokens_mistral': 883, 'n_tokens_neox': 869, 'n_words': 144}