Sha256: 614ba8fe4fc374a79163133446c1b7e2d363e288c1f0dee4f7c18f88aa402346
Contents?: true
Size: 1.86 KB
Versions: 7
Compression:
Stored size: 1.86 KB
Contents
module Rouge module Lexers class HTML < RegexLexer tag 'html' filenames '*.htm', '*.html', '*.xhtml', '*.xslt' 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 /<!\[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 /".*?"/, 'Literal.String', :pop! rule /'.*?'/, 'Literal.String', :pop! rule /[^\s>]+/, 'Literal.String', :pop! 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
Version data entries
7 entries across 7 versions & 1 rubygems