...

Source file src/github.com/alecthomas/chroma/lexers/circular/phtml.go

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

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

View as plain text