# -*- coding: utf-8 -*- # # frozen_string_literal: true module Rouge module Lexers class XML < RegexLexer title "XML" desc %q(XML) tag 'xml' filenames '*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd', '*.wsdl', '*.svg', '*.plist' mimetypes 'text/xml', 'application/xml', 'image/svg+xml', 'application/rss+xml', 'application/atom+xml' def self.detect?(text) return false if text.doctype?(/html/) return true if text =~ /\A<\?xml\b/ return true if text.doctype? end state :root do rule %r/[^<&]+/, Text rule %r/&\S*?;/, Name::Entity rule %r//, Comment::Preproc rule %r//, Comment, :pop! rule %r/-/, Comment end state :tag do rule %r/\s+/m, Text rule %r/[\w.:-]+\s*=/m, Name::Attribute, :attr rule %r(/?\s*>), Name::Tag, :pop! end state :attr do rule %r/\s+/m, Text rule %r/".*?"|'.*?'|[^\s>]+/m, Str, :pop! end end end end