GNOME Bugzilla – Bug 723956
Highlight PHP and then ignore the PHP sections for highlighting HTML, JavaScript, etc
Last modified: 2019-11-29 17:02:11 UTC
See https://bugzilla.gnome.org/show_bug.cgi?id=565524#c12 The PHP sections (between <?php and ?>) should be parsed in priority, wherever they occur. And then for the HTML, JavaScript, CSS, etc highlighting, the PHP sections should be completely ignored. Currently the embedded-lang-hook context must be referenced at a lot of places, and there will always be missing places, where PHP is not highlighted correctly (inside a JavaScript or CSS context for example). I don't know if the syntax highlighting engine of GtkSourceView is able to do that.
Created attachment 279507 [details] Testcase for PHP highlighting in Script, Style and Attributes.
I think Bluefish has a better support for PHP/HTML/JavaScript etc. Unfortunately Bluefish doesn't use GtkSourceView. The implementation of the Bluefish syntax highlighting is described here: http://oli4444.wordpress.com/2010/08/14/bluefish-editor-widget-design/ If one day Bluefish wants to use GtkSourceView, it should be feasible (but it's a lot of work) to implement a custom engine (see gtksourceengine.h). In the meantime I think it's better to use Bluefish for web development, it is also based on GTK+ and GtkTextView, and is specialized for web development.
This issue now has a $100 bounty on Bountysource https://www.bountysource.com/issues/1406544-highlight-php-and-then-ignore-the-php-sections-for-highlighting-html-javascript-etc
The GtkSourceView syntax highlighting engine doesn't support that, so it's quite difficult to fix. The syntax highlighting engine needs to be extended. AFAIK, it's not possible to fix this bug only by modifying the XML files describing the syntax of PHP, HTML, etc. But if Bluefish already ignores PHP sections to highlight the HTML parts, then another solution is to include the syntax highlighting engine of Bluefish into GtkSourceView. With some code refactoring to create utility classes that both engines can use.
A proposed MR is available here https://gitlab.gnome.org/GNOME/gtksourceview/merge_requests/110#note_658438