-
Notifications
You must be signed in to change notification settings - Fork 3.7k
add(php-template) Explicit language to detect PHP templates #2417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,30 @@ | ||
| /* | ||
| Language: PHP Template | ||
| Requires: xml.js, php.js | ||
| Author: Josh Goebel <[email protected]> | ||
| Website: https://www.php.net | ||
| Category: common | ||
| */ | ||
|
|
||
| export default function(hljs) { | ||
| return { | ||
| name: "PHP template", | ||
| subLanguage: 'xml', | ||
| contains: [ | ||
| { | ||
| begin: /<\?(php|=)?/, | ||
| end: /\?>/, | ||
| subLanguage: 'php', | ||
| contains: [ | ||
| // We don't want the php closing tag ?> to close the PHP block when | ||
| // inside any of the following blocks: | ||
| {begin: '/\\*', end: '\\*/', skip: true}, | ||
| {begin: 'b"', end: '"', skip: true}, | ||
| {begin: 'b\'', end: '\'', skip: true}, | ||
| hljs.inherit(hljs.APOS_STRING_MODE, {illegal: null, className: null, contains: null, skip: true}), | ||
| hljs.inherit(hljs.QUOTE_STRING_MODE, {illegal: null, className: null, contains: null, skip: true}) | ||
| ] | ||
| } | ||
| ] | ||
| }; | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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,8 @@ | ||
| <html> | ||
| </html> | ||
| <body> | ||
| <?php | ||
| # Here echo command is used to print | ||
| echo "Hello, world!"; | ||
| ?> | ||
| </body> |
This file contains hidden or 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,4 +1,5 @@ | ||
| <span class="php"><span class="hljs-meta"><?</span> <span class="hljs-keyword">echo</span> <span class="hljs-string">'php'</span>; <span class="hljs-comment">/* ?> */</span> <span class="hljs-meta">?></span></span> | ||
| <span class="php"><span class="hljs-meta"><?</span> <span class="hljs-keyword">echo</span> <span class="hljs-string">'php'</span>; <span class="hljs-comment">/* ?> */</span> <span class="hljs-meta">?></span></span><span class="xml"> | ||
| <span class="hljs-tag"><<span class="hljs-name">body</span>></span> | ||
| <span class="hljs-tag"><<span class="hljs-name">script</span>></span><span class="javascript"><span class="hljs-built_in">document</span>.write(<span class="hljs-string">'Legacy code'</span>);</span><span class="hljs-tag"></<span class="hljs-name">script</span>></span> | ||
| <span class="hljs-tag"></<span class="hljs-name">body</span>></span> | ||
| </span> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I can't say I like this two-grammars approach very much...
But looking at your PR I got a thought: what if we allow two sublanguages here? I. e.
This way we got one grammar that resolves into either
xml+ containedphp, or justphp.If only we had a way to disallow
phpto act as a top-level language...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.
But it IS a top-level language... someone could post a snippet of PHP without the tags... in which case it's a php snippet, ie
phpcode... meanwhile aphp-templateis HTML+PHP...That makes me head hurt - and what is the advantage of doing it that way? PHP code on it's own is NOT a php template.
Uh oh!
There was an error while loading. Please reload this page.
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.
It's consistent with how we do VBScript-HTML and how I've suggested we do other templating languages. For these type of things you have 3 things happening:
Those would be 3 different grammars. This is true for PHP also... the language itself is technically distinct from the templating language.
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.
Just rename
phpto_php, andphp-templatetophp.So that you can use single
phpfor both php snippets and php templates.Uh oh!
There was an error while loading. Please reload this page.
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.
How would that work for ERB or VBscript? I'm trying to also look at the BIG picture here on how we handling templating in general - we should try and be consistent.
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.
REMEMBER, no one is using
phpnow for PHP... well they might be, but they're more likely usingxmlsince that highlights HTML + PHP.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.
Right. And we consider it bad, because it makes xml grammar bloated.
On the other hand, adding xml support to the core language doesn't seem bad. Or it does?
The same way.
(leaving aside existing ERB and VBScript-html for the sake of discussion)