Sha256: a4374c090eb38f7bbbfb36d1d8607c25facf331fba2223d53f17f13ab4d0a7bd

Contents?: true

Size: 945 Bytes

Versions: 14

Compression:

Stored size: 945 Bytes

Contents

module Rouge
  module Lexers
    class Diff < RegexLexer
      desc "Lexes unified diffs or patches"

      tag 'diff'
      aliases 'patch', 'udiff'
      filenames '*.diff', '*.patch'
      mimetypes 'text/x-diff', 'text/x-patch'

      def self.analyze_text(text)
        return 1   if text.start_with?('Index: ')
        return 1   if text.start_with?('diff ')

        return 0.9 if text =~ /\A---.*?\n\+\+\+/m
      end

      state :header do
        rule /^diff .*?\n(?=---|\+\+\+)/m, Generic::Heading
        rule /^--- .*?\n/, Generic::Deleted
        rule /^\+\+\+ .*?\n/, Generic::Inserted
      end

      state :diff do
        rule /@@ -\d+,\d+ \+\d+,\d+ @@.*?\n/, Generic::Heading
        rule /^\+.*?\n/, Generic::Inserted
        rule /^-.*?\n/,  Generic::Deleted
        rule /^ .*?\n/,  Text
        rule /^.*?\n/,   Error
      end

      state :root do
        mixin :header
        mixin :diff
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rouge-1.5.0 lib/rouge/lexers/diff.rb
rouge-1.4.0 lib/rouge/lexers/diff.rb
rouge-1.3.4 lib/rouge/lexers/diff.rb
rouge-1.3.3 lib/rouge/lexers/diff.rb
rouge-1.3.2 lib/rouge/lexers/diff.rb
rouge-1.3.1 lib/rouge/lexers/diff.rb
rouge-1.3.0 lib/rouge/lexers/diff.rb
rouge-1.2.0 lib/rouge/lexers/diff.rb
rouge-1.1.0 lib/rouge/lexers/diff.rb
rouge-0.5.4 lib/rouge/lexers/diff.rb
rouge-0.5.3 lib/rouge/lexers/diff.rb
rouge-0.5.2 lib/rouge/lexers/diff.rb
rouge-0.5.1 lib/rouge/lexers/diff.rb
rouge-0.5.0 lib/rouge/lexers/diff.rb