{"action":"opened","issue":{"url":"https://api.github.com/repos/highlightjs/highlight.js/issues/2330","repository_url":"https://api.github.com/repos/highlightjs/highlight.js","labels_url":"https://api.github.com/repos/highlightjs/highlight.js/issues/2330/labels{/name}","comments_url":"https://api.github.com/repos/highlightjs/highlight.js/issues/2330/comments","events_url":"https://api.github.com/repos/highlightjs/highlight.js/issues/2330/events","html_url":"https://github.com/highlightjs/highlight.js/issues/2330","id":541258596,"node_id":"MDU6SXNzdWU1NDEyNTg1OTY=","number":2330,"title":"Discuss: How we handle the PHP templating language","user":{"login":"yyyc514","id":6473,"node_id":"MDQ6VXNlcjY0NzM=","avatar_url":"https://avatars1.githubusercontent.com/u/6473?v=4","gravatar_id":"","url":"https://api.github.com/users/yyyc514","html_url":"https://github.com/yyyc514","followers_url":"https://api.github.com/users/yyyc514/followers","following_url":"https://api.github.com/users/yyyc514/following{/other_user}","gists_url":"https://api.github.com/users/yyyc514/gists{/gist_id}","starred_url":"https://api.github.com/users/yyyc514/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yyyc514/subscriptions","organizations_url":"https://api.github.com/users/yyyc514/orgs","repos_url":"https://api.github.com/users/yyyc514/repos","events_url":"https://api.github.com/users/yyyc514/events{/privacy}","received_events_url":"https://api.github.com/users/yyyc514/received_events","type":"User","site_admin":false},"labels":[{"id":81702511,"node_id":"MDU6TGFiZWw4MTcwMjUxMQ==","url":"https://api.github.com/repos/highlightjs/highlight.js/labels/enhancement","name":"enhancement","color":"bfe5bf","default":true,"description":""},{"id":81702474,"node_id":"MDU6TGFiZWw4MTcwMjQ3NA==","url":"https://api.github.com/repos/highlightjs/highlight.js/labels/language","name":"language","color":"ddeeff","default":false,"description":""}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-12-21T00:48:16Z","updated_at":"2019-12-21T00:48:16Z","closed_at":null,"author_association":"COLLABORATOR","body":"Related:\r\n\r\n- https://github.com/highlightjs/highlight.js/issues/725\r\n- https://github.com/andreasjansson/language-detection.el\r\n\r\nTechnically PHP is a templating language that exists inside HTML, ie a full PHP template snippet would look like:\r\n\r\n```php\r\n<?php echo '<p>Hello World</p>'; ?> \r\n```\r\n\r\nAlthough `echo '<p>Hello World</p>';` is still valid PHP code, per se... and it's possible to run this with `php -r`.  \r\n\r\nSo keep these two very different context in mind...\r\n\r\n---\r\n\r\nOur current handling of PHP is problematic in several ways.  It's not very intuitive, and it gives people the wrong idea about how to handle templating languages in general.  PHP currently is handled by `xml` and `php`.  `php` is the actual php code itself, while the php templating functionality is buried inside `xml`.\r\n\r\nThat means a snippet such as `<?php echo '<p>Hello World</p>'; ?> ` would be auto-detected as XML, not PHP.  I believe that is one reason we score so poorly on some of the [language detection stats](https://github.com/andreasjansson/language-detection.el).  They are throwing PHP files at us and expecting us to return \"php\" but instead we return \"xml\".\r\n\r\nThis also isn't intuitive if you are manually trying to specify the highlighting language... if you have a FULL PHP template and specify \"php\" your highlighting will be pretty broken because HTML won't be highlighted at all... you'd instead need to specify \"xml\" to get proper highlighting.\r\n\r\nBut if you have only php *code*, without the `<?php ?>` start/end tags then `php` would work.\r\n\r\n---\r\n\r\nJust including PHP in `xml` makes people start thinking about this wrongly (IMHO)... See issue #725, for example.  They see PHP handled by XML and get the idea that that's perhaps where we should dump other templating languages.\r\n\r\nShould XML also handle Mojolicious? ERB?  Handlebars? etc... I think it's obvious this is not the correct path.  The correct way to specify a grammar for PHP would look something like:\r\n\r\n```\r\nexport default function(hljs) {\r\n  return {\r\n    subLanguage: 'xml',\r\n    contains: [\r\n      {\r\n        begin: '<\\?(php)?', end: '\\?>',\r\n        subLanguage: 'php-code'\r\n      }\r\n    ]\r\n  };\r\n}\r\n```\r\n\r\nIf we just made this change today (moving the existing `php` to `php-code`) this should \"just work\" regarding auto-detect.  But now we'd have two different languages that PHP could be detected as, depending on whether it was enclosed in `<?php ?>` tags or not... `php` or `php-code`.  This seems suboptimal.\r\n\r\nAlso, this presents a new problem when someone wants to manually specify the language.  Should they use `php` or `php-code`?\r\n\r\nI'm not 100% sure what the best course of action is here, but I think we need to figure this out and slide it into version 10, as it's likely going to be another breaking change.\r\n\r\n"}}
{"actor":{"display_login":"yyyc514"}}