...

Source file src/github.com/alecthomas/chroma/lexers/h/html.go

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

     1  package h
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma"          // nolint
     5  	. "github.com/alecthomas/chroma/lexers/c" // nolint
     6  	"github.com/alecthomas/chroma/lexers/internal"
     7  	. "github.com/alecthomas/chroma/lexers/j" // nolint
     8  )
     9  
    10  // HTML lexer.
    11  var HTML = internal.Register(MustNewLazyLexer(
    12  	&Config{
    13  		Name:            "HTML",
    14  		Aliases:         []string{"html"},
    15  		Filenames:       []string{"*.html", "*.htm", "*.xhtml", "*.xslt"},
    16  		MimeTypes:       []string{"text/html", "application/xhtml+xml"},
    17  		NotMultiline:    true,
    18  		DotAll:          true,
    19  		CaseInsensitive: true,
    20  	},
    21  	htmlRules,
    22  ))
    23  
    24  func htmlRules() Rules {
    25  	return Rules{
    26  		"root": {
    27  			{`[^<&]+`, Text, nil},
    28  			{`&\S*?;`, NameEntity, nil},
    29  			{`\<\!\[CDATA\[.*?\]\]\>`, CommentPreproc, nil},
    30  			{`<!--`, Comment, Push("comment")},
    31  			{`<\?.*?\?>`, CommentPreproc, nil},
    32  			{`<![^>]*>`, CommentPreproc, nil},
    33  			{`(<)(\s*)(script)(\s*)`, ByGroups(Punctuation, Text, NameTag, Text), Push("script-content", "tag")},
    34  			{`(<)(\s*)(style)(\s*)`, ByGroups(Punctuation, Text, NameTag, Text), Push("style-content", "tag")},
    35  			{`(<)(\s*)([\w:.-]+)`, ByGroups(Punctuation, Text, NameTag), Push("tag")},
    36  			{`(<)(\s*)(/)(\s*)([\w:.-]+)(\s*)(>)`, ByGroups(Punctuation, Text, Punctuation, Text, NameTag, Text, Punctuation), nil},
    37  		},
    38  		"comment": {
    39  			{`[^-]+`, Comment, nil},
    40  			{`-->`, Comment, Pop(1)},
    41  			{`-`, Comment, nil},
    42  		},
    43  		"tag": {
    44  			{`\s+`, Text, nil},
    45  			{`([\w:-]+\s*)(=)(\s*)`, ByGroups(NameAttribute, Operator, Text), Push("attr")},
    46  			{`[\w:-]+`, NameAttribute, nil},
    47  			{`(/?)(\s*)(>)`, ByGroups(Punctuation, Text, Punctuation), Pop(1)},
    48  		},
    49  		"script-content": {
    50  			{`(<)(\s*)(/)(\s*)(script)(\s*)(>)`, ByGroups(Punctuation, Text, Punctuation, Text, NameTag, Text, Punctuation), Pop(1)},
    51  			{`.+?(?=<\s*/\s*script\s*>)`, Using(Javascript), nil},
    52  		},
    53  		"style-content": {
    54  			{`(<)(\s*)(/)(\s*)(style)(\s*)(>)`, ByGroups(Punctuation, Text, Punctuation, Text, NameTag, Text, Punctuation), Pop(1)},
    55  			{`.+?(?=<\s*/\s*style\s*>)`, Using(CSS), nil},
    56  		},
    57  		"attr": {
    58  			{`".*?"`, LiteralString, Pop(1)},
    59  			{`'.*?'`, LiteralString, Pop(1)},
    60  			{`[^\s>]+`, LiteralString, Pop(1)},
    61  		},
    62  	}
    63  }
    64  

View as plain text