<commit_before>module Hyrax
  module CitationsBehaviors
    module Formatters
      class ChicagoFormatter < BaseFormatter
        include Hyrax::CitationsBehaviors::PublicationBehavior
        include Hyrax::CitationsBehaviors::TitleBehavior
        def format(work)
          text = ""

          # setup formatted author list
          authors_list = all_authors(work)
          text << format_authors(authors_list)
          text = "<span class=\"citation-author\">#{text}</span>" if text.present?
          # Get Pub Date
          pub_date = setup_pub_date(work)
          text << " #{pub_date}." unless pub_date.nil?

          text << format_title(work.to_s)
          pub_info = setup_pub_info(work, false)
          text << " #{pub_info}." if pub_info.present?
          text.html_safe
        end

        def format_authors(authors_list = [])
          return '' if authors_list.blank?
          text = ''
          text << surname_first(authors_list.first) if authors_list.first
          authors_list[1..6].each_with_index do |author, index|
            text << if index + 2 == authors_list.length # we've skipped the first author
                      ", and #{given_name_first(author)}."
                    else
                      ", #{given_name_first(author)}"
                    end
          end
          text << " et al." if authors_list.length > 7
          # if for some reason the first author ended with a comma
          text.gsub!(',,', ',')
          text << "." unless text =~ /\.$/
          text
        end
        # rubocop:enable Metrics/MethodLength

        def format_date(pub_date); end

        def format_title(title_info)
          return "" if title_info.blank?
          title_text = chicago_citation_title(title_info)
          title_text << '.' unless title_text =~ /\.$/
          title_text = Loofah.fragment(title_text).scrub!(:whitewash).to_s
          " <i class=\"citation-title\">#{title_text}</i>"
        end
      end
    end
  end
end
<commit_msg>More complete whitewashing of Chicago Citation format<commit_after>module Hyrax
  module CitationsBehaviors
    module Formatters
      class ChicagoFormatter < BaseFormatter
        include Hyrax::CitationsBehaviors::PublicationBehavior
        include Hyrax::CitationsBehaviors::TitleBehavior
        def format(work)
          text = ""

          # setup formatted author list
          authors_list = all_authors(work)
          text << format_authors(authors_list)
          text = "<span class=\"citation-author\">#{text}</span>" if text.present?
          # Get Pub Date
          pub_date = setup_pub_date(work)
          text << " #{whitewash(pub_date)}." unless pub_date.nil?

          text << format_title(work.to_s)
          pub_info = setup_pub_info(work, false)
          text << " #{whitewash(pub_info)}." if pub_info.present?
          text.html_safe
        end

        def format_authors(authors_list = [])
          return '' if authors_list.blank?
          text = ''
          text << surname_first(authors_list.first) if authors_list.first
          authors_list[1..6].each_with_index do |author, index|
            text << if index + 2 == authors_list.length # we've skipped the first author
                      ", and #{given_name_first(author)}."
                    else
                      ", #{given_name_first(author)}"
                    end
          end
          text << " et al." if authors_list.length > 7
          # if for some reason the first author ended with a comma
          text.gsub!(',,', ',')
          text << "." unless text =~ /\.$/
          whitewash(text)
        end
        # rubocop:enable Metrics/MethodLength

        def format_date(pub_date); end

        def format_title(title_info)
          return "" if title_info.blank?
          title_text = chicago_citation_title(title_info)
          title_text << '.' unless title_text =~ /\.$/
          title_text = whitewash(title_text)
          " <i class=\"citation-title\">#{title_text}</i>"
        end

        private

          def whitewash(text)
            Loofah.fragment(text.to_s).scrub!(:whitewash).to_s
          end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.10487338748208314, 'fraction_numerical': 0.0019111323459149545, 'mean_word_length': 1.9300209937018895, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 13, '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': '6817146', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1150, 'n_words': 263}