1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-07-01 00:35:06 +02:00

Fixes: css, html, php.

This commit is contained in:
Alec Thomas
2017-06-05 11:17:38 +10:00
parent 6aea285ca4
commit dba8ec47d2
4 changed files with 12 additions and 9 deletions

View File

@ -83,7 +83,10 @@ def resolve_emitter(emitter):
assert args == {}, args
emitter = 'UsingSelf("%s")' % state
elif issubclass(args, pygments_lexer.Lexer):
emitter = 'Using(%s, nil)' % args.__name__
name = args.__name__
if name.endswith('Lexer'):
name = name[:-5]
emitter = 'Using(%s, nil)' % name
else:
raise ValueError('only support "using" with lexer classes, not %r' % args)
else:

View File

@ -4,8 +4,8 @@ import (
. "github.com/alecthomas/chroma" // nolint
)
// Css lexer.
var Css = Register(NewLexer(
// CSS lexer.
var CSS = Register(NewLexer(
&Config{
Name: "CSS",
Aliases: []string{"css"},

View File

@ -4,8 +4,8 @@ import (
. "github.com/alecthomas/chroma" // nolint
)
// Html lexer.
var Html = Register(NewLexer(
// HTML lexer.
var HTML = Register(NewLexer(
&Config{
Name: "HTML",
Aliases: []string{"html"},
@ -41,11 +41,11 @@ var Html = Register(NewLexer(
},
"script-content": {
{`(<)(\s*)(/)(\s*)(script)(\s*)(>)`, ByGroups(Punctuation, Text, Punctuation, Text, NameTag, Text, Punctuation), Pop(1)},
{`.+?(?=<\s*/\s*script\s*>)`, Using(JavascriptLexer, nil), nil},
{`.+?`, Using(JavaScript, nil), nil},
},
"style-content": {
{`(<)(\s*)(/)(\s*)(style)(\s*)(>)`, ByGroups(Punctuation, Text, Punctuation, Text, NameTag, Text, Punctuation), Pop(1)},
{`.+?(?=<\s*/\s*style\s*>)`, Using(CssLexer, nil), nil},
{`.+?`, Using(CSS, nil), nil},
},
"attr": {
{`".*?"`, LiteralString, Pop(1)},

View File

@ -22,7 +22,7 @@ var Php = Register(NewLexer(
},
"php": {
{`\?>`, CommentPreproc, Pop(1)},
{`(<<<)([\'"]?)((?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*)(\2\n.*?\n\s*)(\3)(;?)(\n)`, ByGroups(LiteralString, LiteralString, LiteralStringDelimiter, LiteralString, LiteralStringDelimiter, Punctuation, Text), nil},
// {`(<<<)([\'"]?)((?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*)(\2\n.*?\n\s*)(\3)(;?)(\n)`, ByGroups(LiteralString, LiteralString, LiteralStringDelimiter, LiteralString, LiteralStringDelimiter, Punctuation, Text), nil},
{`\s+`, Text, nil},
{`#.*?\n`, CommentSingle, nil},
{`//.*?\n`, CommentSingle, nil},
@ -34,7 +34,7 @@ var Php = Register(NewLexer(
{`\?`, Operator, nil},
{`[\[\]{}();,]+`, Punctuation, nil},
{`(class)(\s+)`, ByGroups(Keyword, Text), Push("classname")},
{`(function)(\s*)(?=\()`, ByGroups(Keyword, Text), nil},
{`(function)(\s*)`, ByGroups(Keyword, Text), nil},
{`(function)(\s+)(&?)(\s*)`, ByGroups(Keyword, Text, Operator, Text), Push("functionname")},
{`(const)(\s+)((?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*)`, ByGroups(Keyword, Text, NameConstant), nil},
{`(and|E_PARSE|old_function|E_ERROR|or|as|E_WARNING|parent|eval|PHP_OS|break|exit|case|extends|PHP_VERSION|cfunction|FALSE|print|for|require|continue|foreach|require_once|declare|return|default|static|do|switch|die|stdClass|echo|else|TRUE|elseif|var|empty|if|xor|enddeclare|include|virtual|endfor|include_once|while|endforeach|global|endif|list|endswitch|new|endwhile|not|array|E_ALL|NULL|final|php_user_filter|interface|implements|public|private|protected|abstract|clone|try|catch|throw|this|use|namespace|trait|yield|finally)\b`, Keyword, nil},