From dba8ec47d22f487f54e45d53ee7a167b366a6c63 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Mon, 5 Jun 2017 11:17:38 +1000 Subject: [PATCH] Fixes: css, html, php. --- _tools/pygments2chroma.py | 5 ++++- lexers/css.go | 4 ++-- lexers/html.go | 8 ++++---- lexers/php.go | 4 ++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/_tools/pygments2chroma.py b/_tools/pygments2chroma.py index 660dd5a..6933ba7 100644 --- a/_tools/pygments2chroma.py +++ b/_tools/pygments2chroma.py @@ -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: diff --git a/lexers/css.go b/lexers/css.go index 2f1c5cf..d5f71a2 100644 --- a/lexers/css.go +++ b/lexers/css.go @@ -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"}, diff --git a/lexers/html.go b/lexers/html.go index 414c671..3c5e0a8 100644 --- a/lexers/html.go +++ b/lexers/html.go @@ -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)}, diff --git a/lexers/php.go b/lexers/php.go index 2a42ffc..ef43de8 100644 --- a/lexers/php.go +++ b/lexers/php.go @@ -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},