I need to write PHP code in Pug files for a project.
How can I extend pug syntax highlighting with PHP syntax, without recreating a full language syntax?
For example, for this piece of code, I would like that PHP code be colored like a regular .php file and keep at the same time pug syntax highlighting.
section
.container
.row
.col
.image-100-wrapper
<?= wp_img($content['image'], 'large') ?>
.row.justify-content-center.mt-5
.col-auto
<?php wp_btn($content['bouton']) ?>
I looked if there was an existing VS code extension that does what I am looking for and I searched if there was a simple way to edit the .pug TextMate rules, but I didn't find it.
Related
The majority of the pages I author contain both HTML and PHP. It would appear that in Netbeans you can have syntax highlighting for one or the other by setting the associated file types.
Coming from Notepad++, I've always taken for granted the fact that I could use php, css, html, javascript all in one file and retain syntax highlighting for all of them.
Is this possible in Netbeans?
I think the answer here is that Netbeans DOES support multiple language, but it will only get it right if there's something hinting at the "inner" language. When I exit PHP with ?> NetBeans tends to format what comes before the next <?php as HTML automatically. Not sure if that is working for you. Maybe you were trying to get highlighting in a string like $output = "<some><html";. I think you can imagine why that second one wouldn't work.
For JS, for example, it seems to look for the <script type="text/javascript">, and stuff inside gets the JS highlighting even if the file type is PHP.
This other question has a great solution for "tricking" Netbeans into rendering your JS output by PHP into being formatted, even when your code doesn't have a <script type="text/javascript"> tag.
All modes for CodeMirror that I've found use PHP parser as multi parser combined with HTML and JavaScript. All these require <?php to start highlighting PHP.
I want to have everything in my textarea highlighted as PHP. Assume <?php at the beginning and ignore any further ?>.
Can I do this?
Use "text/x-php" as your mode option.
I'm using NetBeans as my IDE for a Ember.js project. When I create handlebars templates in my app like below the code highlighting doesn't work correctly.
<script type="text/x-handlebars">
<div>
</div>
</script>
Normally, when I'd select the first div, it and its matching end tag would highlight yellow, but this doesn't work. Since its inside the handlebars script tag both are highlighted red as errors and don't match together. This makes writing complex templates kinda annoying as it can be difficult to pinpoint syntax errors.
Is there anyway to get NetBeans to highlight inside the handlebars tag as if its regular html?
One option, until Netbeans implements this enhancement, is to add the following script tag in index.html immediately after your reference to jQuery:
<script src="js/libs/jquery.js"></script>
<!-- use following line to change script type to 'text/x-handlebars' -->
<script>jQuery('script[type="text/html"]').attr('type', 'text/x-handlebars');</script>
This is a variation of the answer provided by GCoda.
I had the same problem and tried various non satisfying fixes.
In the end I figured the best solution is simply to change the script's type attribute to text/html:
<script type="text/html">
<div>
</div>
</script>
I got same problem. And i just used a some kind of postprocessing, i am using node.js, so i did res.send(data.replace(/type="text\/html"/g,'type="text/x-handlebars"')); on my / page.
I think you can do something similar in you language, and ofcource this is not a fix, just an ugly trick to make developing more easy. Dont keep it in production.
I develop website on Netbeans IDE.
Currently I'm working with Laravel Framework, and I use the Blade template engine which allow to create loop or conditional statement in HTML views without having to jump from HTML to PHP, then to HTML again, ...
However each of Blade's statement aren't recognize as HTML or PHP object, and so Netbeans doesn't make any indentation of them:
#if($isConnected)
<div id="aDiv">...
#else
<div>...
I'd prefer it looks like:
#if($isConnected)
<div id="aDiv">...
#else
<div>...
Is there a way to teach new indentation rules to Netbeans?
Ideas needed: what's the best mime-type to set to *.hbs in Netbeans in order to get the best highlighting for Handlebars templates?
I'm not familiar with Handlebars, but quick look at their page suggests it uses HTML + {{expressions}}. In NetBeans 7.4, {{expressions}} in HTML are interpreted as AngularJS expression so the content is considered to be JS code.
It won't help you but editor uses different color for curly braces and their content in this case. Unless {{expression}} in Handlebar template contains something that is "wrong in JavaScript syntax perspective", you can get at least some coloring and no false errors complaining about JS syntax (that your handlebars would pretend to be)
Of course this is hacky workaround, but at least you could see {{expressions}} in your file more easily and even (at least partially) modify their coloring.