\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /opt/chef/embedded/lib/ruby/gems/2.7.0/gems/coderay-1.1.3/lib/coderay/encoders/html/

Viewing File: numbering.rb

module CodeRay
module Encoders
  
  class HTML
    
    module Numbering  # :nodoc:
      
      def self.number! output, mode = :table, options = {}
        return self unless mode
        
        options = DEFAULT_OPTIONS.merge options
        
        start = options[:line_number_start]
        unless start.is_a? Integer
          raise ArgumentError, "Invalid value %p for :line_number_start; Integer expected." % start
        end
        
        anchor_prefix = options[:line_number_anchors]
        anchor_prefix = 'line' if anchor_prefix == true
        anchor_prefix = anchor_prefix.to_s[/[\w-]+/] if anchor_prefix
        anchoring =
          if anchor_prefix
            proc do |line|
              line = line.to_s
              anchor = anchor_prefix + line
              "<a href=\"##{anchor}\" name=\"#{anchor}\">#{line}</a>"
            end
          else
            :to_s.to_proc
          end
        
        bold_every = options[:bold_every]
        highlight_lines = options[:highlight_lines]
        bolding =
          if bold_every == false && highlight_lines == nil
            anchoring
          elsif highlight_lines.is_a? Enumerable
            highlight_lines = highlight_lines.to_set
            proc do |line|
              if highlight_lines.include? line
                "<strong class=\"highlighted\">#{anchoring[line]}</strong>"  # highlighted line numbers in bold
              else
                anchoring[line]
              end
            end
          elsif bold_every.is_a? Integer
            raise ArgumentError, ":bolding can't be 0." if bold_every == 0
            proc do |line|
              if line % bold_every == 0
                "<strong>#{anchoring[line]}</strong>"  # every bold_every-th number in bold
              else
                anchoring[line]
              end
            end
          else
            raise ArgumentError, 'Invalid value %p for :bolding; false or Integer expected.' % bold_every
          end
        
        if position_of_last_newline = output.rindex(RUBY_VERSION >= '1.9' ? /\n/ : ?\n)
          after_last_newline = output[position_of_last_newline + 1 .. -1]
          ends_with_newline = after_last_newline[/\A(?:<\/span>)*\z/]
          
          if ends_with_newline
            line_count = output.count("\n")
          else
            line_count = output.count("\n") + 1
          end
        else
          line_count = 1
        end
        
        case mode
        when :inline
          max_width = (start + line_count).to_s.size
          line_number = start
          output.gsub!(/^.*$\n?/) do |line|
            line_number_text = bolding.call line_number
            indent = ' ' * (max_width - line_number.to_s.size)
            line_number += 1
            "<span class=\"line-numbers\">#{indent}#{line_number_text}</span>#{line}"
          end
        
        when :table
          line_numbers = (start ... start + line_count).map(&bolding).join("\n")
          line_numbers << "\n"
          line_numbers_table_template = Output::TABLE.apply('LINE_NUMBERS', line_numbers)
          
          output.gsub!(/<\/div>\n/, '</div>')
          output.wrap_in! line_numbers_table_template
          output.wrapped_in = :div
        
        when :list
          raise NotImplementedError, 'The :list option is no longer available. Use :table.'
        
        else
          raise ArgumentError, 'Unknown value %p for mode: expected one of %p' %
            [mode, [:table, :inline]]
        end
        
        output
      end
      
    end
    
  end
  
end
end