-
-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split PHP into two lexers - PHP and PHTML.
The former is pure PHP code while the latter is PHP code in <? ?> tags, within HTML. Fixes #210.
- Loading branch information
1 parent
1150149
commit 2b9ea60
Showing
10 changed files
with
229 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package circular | ||
|
||
import ( | ||
"strings" | ||
|
||
. "github.com/alecthomas/chroma" // nolint | ||
"github.com/alecthomas/chroma/lexers/h" | ||
"github.com/alecthomas/chroma/lexers/internal" | ||
) | ||
|
||
// PHTML lexer is PHP in HTML. | ||
var PHTML = internal.Register(DelegatingLexer(h.HTML, MustNewLexer( | ||
&Config{ | ||
Name: "PHTML", | ||
Aliases: []string{"phtml"}, | ||
Filenames: []string{"*.phtml"}, | ||
MimeTypes: []string{"application/x-php", "application/x-httpd-php", "application/x-httpd-php3", "application/x-httpd-php4", "application/x-httpd-php5"}, | ||
DotAll: true, | ||
CaseInsensitive: true, | ||
EnsureNL: true, | ||
}, | ||
Rules{ | ||
"root": { | ||
{`<\?(php)?`, CommentPreproc, Push("php")}, | ||
{`[^<]+`, Other, nil}, | ||
{`<`, Other, nil}, | ||
}, | ||
}.Merge(phpCommonRules), | ||
).SetAnalyser(func(text string) float32 { | ||
if strings.Contains(text, "<?php") { | ||
return 0.5 | ||
} | ||
return 0.0 | ||
}))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,9 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
|
||
<h1>My first PHP page</h1> | ||
<?php | ||
|
||
$docs = $modx->getIterator('modResource', ["parent" => 84]); | ||
|
||
foreach($docs as $doc){ | ||
$q=$doc->content; | ||
$doc->set("content", preg_replace("/Some value/i", "Replacement", $q)); | ||
print_r($doc->content); | ||
// $doc->save(); | ||
} | ||
} | ||
// some comment | ||
?> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
|
||
<h1>My first PHP page</h1> | ||
<?php | ||
|
||
$docs = $modx->getIterator('modResource', ["parent" => 84]); | ||
|
||
foreach($docs as $doc){ | ||
$q=$doc->content; | ||
$doc->set("content", preg_replace("/Some value/i", "Replacement", $q)); | ||
print_r($doc->content); | ||
// $doc->save(); | ||
} | ||
// some comment | ||
?> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
[ | ||
{"type":"CommentPreproc","value":"\u003c!DOCTYPE html\u003e"}, | ||
{"type":"Text","value":"\n"}, | ||
{"type":"Punctuation","value":"\u003c"}, | ||
{"type":"NameTag","value":"html"}, | ||
{"type":"Punctuation","value":"\u003e"}, | ||
{"type":"Text","value":"\n"}, | ||
{"type":"Punctuation","value":"\u003c"}, | ||
{"type":"NameTag","value":"body"}, | ||
{"type":"Punctuation","value":"\u003e"}, | ||
{"type":"Text","value":"\n\n"}, | ||
{"type":"Punctuation","value":"\u003c"}, | ||
{"type":"NameTag","value":"h1"}, | ||
{"type":"Punctuation","value":"\u003e"}, | ||
{"type":"Text","value":"My first PHP page"}, | ||
{"type":"Punctuation","value":"\u003c/"}, | ||
{"type":"NameTag","value":"h1"}, | ||
{"type":"Punctuation","value":"\u003e"}, | ||
{"type":"Text","value":"\n"}, | ||
{"type":"CommentPreproc","value":"\u003c?php"}, | ||
{"type":"Text","value":"\n\n"}, | ||
{"type":"NameVariable","value":"$docs"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"Operator","value":"="}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameVariable","value":"$modx"}, | ||
{"type":"Operator","value":"-\u003e"}, | ||
{"type":"NameAttribute","value":"getIterator"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"LiteralStringSingle","value":"'modResource'"}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"Text","value":" "}, | ||
{"type":"Punctuation","value":"["}, | ||
{"type":"LiteralStringDouble","value":"\"parent\""}, | ||
{"type":"Text","value":" "}, | ||
{"type":"Operator","value":"=\u003e"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"LiteralNumberInteger","value":"84"}, | ||
{"type":"Punctuation","value":"]);"}, | ||
{"type":"Text","value":"\n\n"}, | ||
{"type":"Keyword","value":"foreach"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"NameVariable","value":"$docs"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"Keyword","value":"as"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameVariable","value":"$doc"}, | ||
{"type":"Punctuation","value":"){"}, | ||
{"type":"Text","value":"\n "}, | ||
{"type":"NameVariable","value":"$q"}, | ||
{"type":"Operator","value":"="}, | ||
{"type":"NameVariable","value":"$doc"}, | ||
{"type":"Operator","value":"-\u003e"}, | ||
{"type":"NameAttribute","value":"content"}, | ||
{"type":"Punctuation","value":";"}, | ||
{"type":"Text","value":"\n "}, | ||
{"type":"NameVariable","value":"$doc"}, | ||
{"type":"Operator","value":"-\u003e"}, | ||
{"type":"NameAttribute","value":"set"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"LiteralStringDouble","value":"\"content\""}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameOther","value":"preg_replace"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"LiteralStringDouble","value":"\"/Some value/i\""}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"Text","value":" "}, | ||
{"type":"LiteralStringDouble","value":"\"Replacement\""}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameVariable","value":"$q"}, | ||
{"type":"Punctuation","value":"));"}, | ||
{"type":"Text","value":"\n "}, | ||
{"type":"NameOther","value":"print_r"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"NameVariable","value":"$doc"}, | ||
{"type":"Operator","value":"-\u003e"}, | ||
{"type":"NameAttribute","value":"content"}, | ||
{"type":"Punctuation","value":");"}, | ||
{"type":"Text","value":"\n "}, | ||
{"type":"CommentSingle","value":"// $doc-\u003esave();\n"}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"Text","value":" \n"}, | ||
{"type":"CommentSingle","value":"// some comment\n"}, | ||
{"type":"CommentPreproc","value":"?\u003e"}, | ||
{"type":"Text","value":"\n"}, | ||
{"type":"Punctuation","value":"\u003c/"}, | ||
{"type":"NameTag","value":"body"}, | ||
{"type":"Punctuation","value":"\u003e"}, | ||
{"type":"Text","value":"\n"}, | ||
{"type":"Punctuation","value":"\u003c/"}, | ||
{"type":"NameTag","value":"html"}, | ||
{"type":"Punctuation","value":"\u003e"}, | ||
{"type":"Text","value":"\n"} | ||
] |
Oops, something went wrong.
2b9ea60
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMG Thank you!!!