1package h
2
3import (
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.
11var HTML = internal.Register(MustNewLexer(
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 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*)(script)(\s*)`, ByGroups(Punctuation, Text, NameTag, Text), Push("script-content", "tag")},
30 {`(<)(\s*)(style)(\s*)`, ByGroups(Punctuation, Text, NameTag, Text), Push("style-content", "tag")},
31 {`(<)(\s*)([\w:.-]+)`, ByGroups(Punctuation, Text, NameTag), Push("tag")},
32 {`(<)(\s*)(/)(\s*)([\w:.-]+)(\s*)(>)`, ByGroups(Punctuation, Text, Punctuation, Text, NameTag, Text, Punctuation), nil},
33 },
34 "comment": {
35 {`[^-]+`, Comment, nil},
36 {`-->`, Comment, Pop(1)},
37 {`-`, Comment, nil},
38 },
39 "tag": {
40 {`\s+`, Text, nil},
41 {`([\w:-]+\s*)(=)(\s*)`, ByGroups(NameAttribute, Operator, Text), Push("attr")},
42 {`[\w:-]+`, NameAttribute, nil},
43 {`(/?)(\s*)(>)`, ByGroups(Punctuation, Text, Punctuation), Pop(1)},
44 },
45 "script-content": {
46 {`(<)(\s*)(/)(\s*)(script)(\s*)(>)`, ByGroups(Punctuation, Text, Punctuation, Text, NameTag, Text, Punctuation), Pop(1)},
47 {`.+?(?=<\s*/\s*script\s*>)`, Using(Javascript), nil},
48 },
49 "style-content": {
50 {`(<)(\s*)(/)(\s*)(style)(\s*)(>)`, ByGroups(Punctuation, Text, Punctuation, Text, NameTag, Text, Punctuation), Pop(1)},
51 {`.+?(?=<\s*/\s*style\s*>)`, Using(CSS), nil},
52 },
53 "attr": {
54 {`".*?"`, LiteralString, Pop(1)},
55 {`'.*?'`, LiteralString, Pop(1)},
56 {`[^\s>]+`, LiteralString, Pop(1)},
57 },
58 },
59))