Files
news.gitea.happylizard.me/bin/gems/rouge-4.7.0/lib/rouge/lexers/diff.rb
T
pizza2d1 4cee170d66
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 9s
Add bin and edit workflow
2026-09-16 13:11:16 -06:00

48 lines
1.2 KiB
Ruby

# frozen_string_literal: true
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.detect?(text)
return true if text.start_with?('Index: ')
return true if text =~ %r(\Adiff[^\n]*?\ba/[^\n]*\bb/)
return true if text =~ /---.*?\n[+][+][+]/ || text =~ /[+][+][+].*?\n---/
end
state :root do
rule(/^ .*$\n?/, Text)
rule(/^---$\n?/, Punctuation)
rule %r(
(^\++.*$\n?) |
(^>+[ \t]+.*$\n?) |
(^>+$\n?)
)x, Generic::Inserted
rule %r(
(^-+.*$\n?) |
(^<+[ \t]+.*$\n?) |
(^<+$\n?)
)x, Generic::Deleted
rule(/^!.*$\n?/, Generic::Strong)
rule(/^([Ii]ndex|diff).*$\n?/, Generic::Heading)
rule(/^(@@[^@]*@@)([^\n]*\n)/) do
groups Punctuation, Text
end
rule(/^\w.*$\n?/, Punctuation)
rule(/^=.*$\n?/, Generic::Heading)
rule(/.+$\n?/, Text)
end
end
end
end