Sha256: d0db3d9dc24470b2ab62ab3f13c2b724523466685c853a4f836227733972940e

Contents?: true

Size: 841 Bytes

Versions: 2

Compression:

Stored size: 841 Bytes

Contents

module Rouge
  module Lexers
    class Diff < RegexLexer
      title 'diff'
      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.start_with?('--- ')
      end

      state :root do
        rule(/^ .*\n/, Text)
        rule(/^---\n/, Text)
        rule(/^\+.*\n/, Generic::Inserted)
        rule(/^-+.*\n/, Generic::Deleted)
        rule(/^!.*\n/, Generic::Strong)
        rule(/^@.*\n/, Generic::Subheading)
        rule(/^([Ii]ndex|diff).*\n/, Generic::Heading)
        rule(/^=.*\n/, Generic::Heading)
        rule(/.*\n/, Text)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
rouge-1.10.1 lib/rouge/lexers/diff.rb
gitlab-rouge-1.9.2 lib/rouge/lexers/diff.rb