...

Source file src/github.com/alecthomas/chroma/lexers/x/xml.go

Documentation: github.com/alecthomas/chroma/lexers/x

     1  package x
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // XML lexer.
     9  var XML = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:      "XML",
    12  		Aliases:   []string{"xml"},
    13  		Filenames: []string{"*.xml", "*.xsl", "*.rss", "*.xslt", "*.xsd", "*.wsdl", "*.wsf", "*.svg", "*.csproj", "*.vcxproj", "*.fsproj"},
    14  		MimeTypes: []string{"text/xml", "application/xml", "image/svg+xml", "application/rss+xml", "application/atom+xml"},
    15  		DotAll:    true,
    16  	},
    17  	xmlRules,
    18  ))
    19  
    20  func xmlRules() Rules {
    21  	return Rules{
    22  		"root": {
    23  			{`[^<&]+`, Text, nil},
    24  			{`&\S*?;`, NameEntity, nil},
    25  			{`\<\!\[CDATA\[.*?\]\]\>`, CommentPreproc, nil},
    26  			{`<!--`, Comment, Push("comment")},
    27  			{`<\?.*?\?>`, CommentPreproc, nil},
    28  			{`<![^>]*>`, CommentPreproc, nil},
    29  			{`<\s*[\w:.-]+`, NameTag, Push("tag")},
    30  			{`<\s*/\s*[\w:.-]+\s*>`, NameTag, nil},
    31  		},
    32  		"comment": {
    33  			{`[^-]+`, Comment, nil},
    34  			{`-->`, Comment, Pop(1)},
    35  			{`-`, Comment, nil},
    36  		},
    37  		"tag": {
    38  			{`\s+`, Text, nil},
    39  			{`[\w.:-]+\s*=`, NameAttribute, Push("attr")},
    40  			{`/?\s*>`, NameTag, Pop(1)},
    41  		},
    42  		"attr": {
    43  			{`\s+`, Text, nil},
    44  			{`".*?"`, LiteralString, Pop(1)},
    45  			{`'.*?'`, LiteralString, Pop(1)},
    46  			{`[^\s>]+`, LiteralString, Pop(1)},
    47  		},
    48  	}
    49  }
    50  

View as plain text