module Rouge module Lexers class XML < RegexLexer tag 'xml' filenames *%w(*.xml *.xsl *.rss *.xslt *.xsd *.wsdl) mimetypes *%w( text/xml application/xml image/svg+xml application/rss+xml application/atom+xml ) def self.analyze_text(text) return 0.5 if text.doctype? return 0.5 if text[0..1000] =~ %r(<.+?>.*?)m return 0.8 if text =~ /\A<\?xml\b/ end state :root do rule /[^<&]+/, 'Text' rule /&\S*?;/, 'Name.Entity' rule //, 'Comment.Preproc' rule //, 'Comment', :pop! rule /-/, 'Comment' end state :tag do rule /\s+/m, 'Text' rule /[\w.:-]+\s*=/m, 'Name.Attribute', :attr rule %r(/?\s*>), 'Name.Tag', :pop! end state :attr do rule /\s+/m, 'Text' rule /".*?"|'.*?'|[^\s>]+/, 'Literal.String', :pop! end end end end