diff --git a/CHANGES.md b/CHANGES.md index a01cf8dc94..67631e65a2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ New languages: +- (php-template) Explicit language to detect PHP templates (vs xml) [Josh Goebel][] - enh(python) Added `python-repl` for Python REPL sessions New themes: diff --git a/VERSION_10_BREAKING.md b/VERSION_10_BREAKING.md index 0d67efda1f..11a0ac99a6 100644 --- a/VERSION_10_BREAKING.md +++ b/VERSION_10_BREAKING.md @@ -1,13 +1,16 @@ ## Version 10 Breaking Changes Incompatibilities: + - chore(parser): compressed version 9.x language definitions no longer supported (rebuild them minified) [Josh Goebel][] - `nohightlight` and `no-highlight` are the only "ignore me" css classes now (`plain` and `text` no longer count) (to get the old behavior you can customize `noHighlightRe`) - a grammar with a top-level `self` reference will now always throw an error (previously in safe mode this would be silently ignored) +- PHP templates are now detected as `php-template`, not `xml` Renamed Language Files: + - chore(parser): rename `nimrod.js` to `nim.js` [Josh Goebel][] - chore(parser): rename `cs.js` to `csharp.js` [Josh Goebel][] - chore(parser): rename `tex.js` to `latex.js` [Josh Goebel][] @@ -19,11 +22,13 @@ Renamed Language Files: (https://github.com/highlightjs/highlight.js/issues/2146) Legacy Browser Issues: + - **We're now using ES2015 features in the codebase. Internet Explorer 11 is no longer supported.** - In general legacy browsers are no longer supported. - chore(parser): remove `load` listener in favor of only the newer `DOMContentLoaded` [Josh Goebel][] Removed styles: + - chore(styles): darkula.css (use darcula.css instead) [Josh Goebel][] [Josh Goebel]: https://github.com/yyyc514 diff --git a/src/languages/php-template.js b/src/languages/php-template.js new file mode 100644 index 0000000000..dfebbf6be5 --- /dev/null +++ b/src/languages/php-template.js @@ -0,0 +1,30 @@ +/* +Language: PHP Template +Requires: xml.js, php.js +Author: Josh Goebel +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}) + ] + } + ] + }; +} diff --git a/src/languages/php.js b/src/languages/php.js index a199a65433..752bc448df 100644 --- a/src/languages/php.js +++ b/src/languages/php.js @@ -11,7 +11,12 @@ export default function(hljs) { begin: '\\$+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' }; var PREPROCESSOR = { - className: 'meta', begin: /<\?(php|=)?|\?>/ + className: 'meta', + variants: [ + { begin: /<\?php/, relevance: 10 }, // boost for obvious PHP + { begin: /<\?[=]?/ }, + { begin: /\?>/ } // end php tag + ] }; var STRING = { className: 'string', diff --git a/src/languages/xml.js b/src/languages/xml.js index d9dee3e2f9..1b49fef5c1 100644 --- a/src/languages/xml.js +++ b/src/languages/xml.js @@ -97,19 +97,6 @@ export default function(hljs) { className: 'meta', begin: /<\?xml/, end: /\?>/, relevance: 10 }, - { - 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}) - ] - }, { className: 'tag', /* diff --git a/test/detect/php-template/default.txt b/test/detect/php-template/default.txt new file mode 100644 index 0000000000..d01ad4a791 --- /dev/null +++ b/test/detect/php-template/default.txt @@ -0,0 +1,8 @@ + + + + + diff --git a/test/fixtures/expect/sublanguages.txt b/test/fixtures/expect/sublanguages.txt index 2a89d6ae2d..9c5be2499d 100644 --- a/test/fixtures/expect/sublanguages.txt +++ b/test/fixtures/expect/sublanguages.txt @@ -1,4 +1,5 @@ -<? echo 'php'; /* ?> */ ?> +<? echo 'php'; /* ?> */ ?> <body> <script>document.write('Legacy code');</script> </body> +