...
1 package lexers
2
3 import (
4 "strings"
5
6 . "github.com/alecthomas/chroma/v2"
7 )
8
9
10 var _ = Register(DelegatingLexer(HTML, MustNewLexer(
11 &Config{
12 Name: "PHTML",
13 Aliases: []string{"phtml"},
14 Filenames: []string{"*.phtml", "*.php", "*.php[345]", "*.inc"},
15 MimeTypes: []string{"application/x-php", "application/x-httpd-php", "application/x-httpd-php3", "application/x-httpd-php4", "application/x-httpd-php5", "text/x-php"},
16 DotAll: true,
17 CaseInsensitive: true,
18 EnsureNL: true,
19 Priority: 2,
20 },
21 func() Rules {
22 return Get("PHP").(*RegexLexer).MustRules().
23 Rename("root", "php").
24 Merge(Rules{
25 "root": {
26 {`<\?(php)?`, CommentPreproc, Push("php")},
27 {`[^<]+`, Other, nil},
28 {`<`, Other, nil},
29 },
30 })
31 },
32 ).SetAnalyser(func(text string) float32 {
33 if strings.Contains(text, "<?php") {
34 return 0.5
35 }
36 return 0.0
37 })))
38
View as plain text