/usr/lib/ruby/vendor_ruby/rugments/lexers/html.rb is in ruby-rugments 1.0.0~beta8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | module Rugments
module Lexers
class HTML < RegexLexer
title 'HTML'
desc 'HTML, the markup language of the web'
tag 'html'
filenames '*.htm', '*.html', '*.xhtml'
mimetypes 'text/html', 'application/xhtml+xml'
def self.analyze_text(text)
return 1 if text.doctype?(/\bhtml\b/i)
return 1 if text =~ /<\s*html\b/
end
state :root do
rule /[^<&]+/m, Text
rule /&\S*?;/, Name::Entity
rule /<!DOCTYPE .*?>/im, Comment::Preproc
rule /<!\[CDATA\[.*?\]\]>/m, Comment::Preproc
rule /<!--/, Comment, :comment
rule /<\?.*?\?>/m, Comment::Preproc # php? really?
rule /<\s*script\s*/m do
token Name::Tag
push :script_content
push :tag
end
rule /<\s*style\s*/m do
token Name::Tag
push :style_content
push :tag
end
rule %r{<\s*[a-zA-Z0-9:-]+}, Name::Tag, :tag # opening tags
rule %r{<\s*/\s*[a-zA-Z0-9:-]+\s*>}, Name::Tag # closing tags
end
state :comment do
rule /[^-]+/, Comment
rule /-->/, Comment, :pop!
rule /-/, Comment
end
state :tag do
rule /\s+/m, Text
rule /[a-zA-Z0-9_:-]+\s*=/m, Name::Attribute, :attr
rule /[a-zA-Z0-9_:-]+/, Name::Attribute
rule %r{/?\s*>}m, Name::Tag, :pop!
end
state :attr do
# TODO: are backslash escapes valid here?
rule /"/ do
token Str
goto :dq
end
rule /'/ do
token Str
goto :sq
end
rule /[^\s>]+/, Str, :pop!
end
state :dq do
rule /"/, Str, :pop!
rule /[^"]+/, Str
end
state :sq do
rule /'/, Str, :pop!
rule /[^']+/, Str
end
state :script_content do
rule %r{<\s*/\s*script\s*>}m, Name::Tag, :pop!
rule %r{.*?(?=<\s*/\s*script\s*>)}m do
delegate Javascript
end
end
state :style_content do
rule %r{<\s*/\s*style\s*>}m, Name::Tag, :pop!
rule %r{.*(?=<\s*/\s*style\s*>)}m do
delegate CSS
end
end
end
end
end
|