Php – How to enhance Notepad++ to support Laravel blade syntax highlighting in a PHP file

notepadPHPsyntax highlighting

After looking online I cannot find any info on enhancing N++ to support syntax highlighting for Laravel's Blade syntax (*.blade.php).

Example: demo.blade.php

<html>
    <head>
        <title>App Name - @yield('title')</title>
    </head>
    <body>
        @section('sidebar')
            This is the master sidebar.
        @show

        <div class="container">
            @yield('content')
        </div>
    </body>
</html>

I know Notepad++ supports user-defined languages to add syntax highlighting support for new file extensions (I have used this before for *.scss files).

However, I want to continue using N++'s built in highlighting for *.php files and add to it by creating rules to match the Blade syntax within a PHP file. If I was to use N++'s user-defined language functionality for Blade files, I would also have to re-define all the syntax highlighting for PHP syntax.

I have attempted to modify N++'s langs.xml and stylers.xml files under the PHP definition but with no luck.

Therefore, how would I enhance N++ to provide syntax highlighting support for Blade? This was my starting point which is Blade highlighting in Sublime.

Best Answer

This is possible only by writing and compiling your own Notepad++ build along with custom built-in language. See Notepad++ source code how other languages (e.g. HTML which can contain JavaScript) are implemented. This cannot be achieved by User-defined language mechanism which is simplified (by design).

There also should be another way by writing a Notepad++ plugin. Several such plugins exist (you can find them using Plugin Manager) so you can have a model source code.

If you are attempting to avoid programming for this task, use for example similar editor called SynWrite which has much more powerful engine for User-defined languages although (of course) it is more difficult to learn. There, the result is achievable.

Here is similar answer.

Related Question