Sha256: 92b022b6f11ce82d7453b3244a1a2fecd554d37dc5be62465ea61d285c866ada

Contents?: true

Size: 1.22 KB

Versions: 10

Compression:

Stored size: 1.22 KB

Contents

# -*- coding: utf-8 -*- #

module Rouge
  class TextAnalyzer < String
    # Find a shebang.  Returns nil if no shebang is present.
    def shebang
      return @shebang if instance_variable_defined? :@shebang

      self =~ /\A\s*#!(.*)$/
      @shebang = $1
    end

    # Check if the given shebang is present.
    #
    # This normalizes things so that `text.shebang?('bash')` will detect
    # `#!/bash`, '#!/bin/bash', '#!/usr/bin/env bash', and '#!/bin/bash -x'
    def shebang?(match)
      return false unless shebang
      match = /\b#{match}(\s|$)/
      match === shebang
    end

    # Return the contents of the doctype tag if present, nil otherwise.
    def doctype
      return @doctype if instance_variable_defined? :@doctype

      self =~ %r(\A\s*
        (?:<\?.*?\?>\s*)? # possible <?xml...?> tag
        <!DOCTYPE\s+(.+?)>
      )xm
      @doctype = $1
    end

    # Check if the doctype matches a given regexp or string
    def doctype?(type=//)
      type === doctype
    end

    # Return true if the result of lexing with the given lexer contains no
    # error tokens.
    def lexes_cleanly?(lexer)
      lexer.lex(self) do |(tok, _)|
        return false if tok.name == 'Error'
      end

      true
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/rouge-2.2.1/lib/rouge/text_analyzer.rb
rouge-3.2.1 lib/rouge/text_analyzer.rb
rouge-3.2.0 lib/rouge/text_analyzer.rb
rouge_ecl-1.0.0 lib/rouge/text_analyzer.rb
rouge_ecl-0.0.1 lib/rouge/text_analyzer.rb
rouge-3.1.1 lib/rouge/text_analyzer.rb
rouge-3.1.0 lib/rouge/text_analyzer.rb
rouge-3.0.0 lib/rouge/text_analyzer.rb
rouge-2.2.1 lib/rouge/text_analyzer.rb
rouge-2.2.0 lib/rouge/text_analyzer.rb