-
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
Conversation
- Adds a separate language to detect PHP templates to avoid overloading `xml` XML never should have built-in PHP support in the first place as there are any number of templating languages out there, and they all can't be built into XML. This rectifies that situation.
| export default function(hljs) { | ||
| return { | ||
| name: "PHP template", | ||
| subLanguage: 'xml', |
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.
subLanguage: ['xml','php'],This way we got one grammar that resolves into either xml + contained php, or just php.
If only we had a way to disallow php to 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.
If only we had a way to disallow php to act as a top-level language...
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 php code... meanwhile a php-template is HTML+PHP...
what if we allow two sublanguages here?
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.
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...
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:
- The core language (say Ruby)
- The tagging/templating language (say ERB)
- The actual output format (say HTML)
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 php to _php, and php-template to php.
So that you can use single php for both php snippets and php templates.
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.
So that you can use single php for both php snippets and php templates.
REMEMBER, no one is using php now for PHP... well they might be, but they're more likely using xml since 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.
REMEMBER, no one is using php now for PHP... well they might be, but they're more likely using xml since that highlights HTML + PHP.
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?
How would that work for ERB or VBscript?
The same way.
(leaving aside existing ERB and VBScript-html for the sake of discussion)
That doesn't work because that's EITHER OR. Either it will be colored HTML OR it will be colored PHP. That's only 2 out of the 3, hence why we're adding php-template.
Note: That might have worked in the past, but it is NOT correct for php (or any templating languages) to be hidden inside |
|
I don't think we have a perfect way of doing this currently (see the longer issue thread). I personally think |
Why? This part takes care of it:
Do you mean "is better than existing PHP and XML"? |
I'm not sure I follow... How? Where is that code snippet? As previously mentioned you can't put every single templating language inside XML - and it's inconsistent. We already have many HTML templating languages (Twig, handlebars, HTMLBars, etc)... they are always their own grammar. When you do something like sublanguage: So really what you're suggesting is
Yes.
As a general way of thinking about it I'm not opposed. But I think this is specific to how PHP is thought about. PHP has historically been defined as "PHP/HTML"...
Very much disagree here. Ruby and ERB are not interchangeable. Ruby code is Ruby code and ERB is a templating language based on Ruby. They are discrete things and thought of as such. |
I'd have to give this some more thought, but it produces really ugly HTML: |
|
This is going to a lot of trouble just to build a "nice php alias"... Since that's the ONLY additional thing doing it the way you suggest gives you. Having "php" and "php-template" for auto-detect works just fine, auto-detect will decide... but if you want the user to only ever have to think I'd like to suggest that You could imagine something like: |
|
This touches on #2371 also. Perhaps aliases should be more ambiguous. As as soon as you add So perhaps both PHP and PHP-template claim |
No doubt.
ERB is lucky to have its own name. But for PHP you're like "well, I'm using PHP inside HTML, so I'm going to use... what's-his-name... php-html? no... ah, php-template! some day I'll memorize..."
Yeah, this is a way to go. |
Yeah, I do understand the problem you're trying to solve. :-) And I don't love |
- Adds a separate language to detect PHP templates to avoid overloading `xml` XML never should have built-in PHP support in the first place as there are any number of templating languages out there, and they all can't be built into XML. This rectifies that situation.
Closes #2330.