PHP background color highlighting between HTML/Javascript/jQuery/etc


#1

Hello,
how can change only background color in PHP code/syntax? Like this screenshot from Dreamweaver because I need to recognize PHP with easy between anything else. I use Atom Dark syntax theme.

Awesome editor! I love it!
Thanks in advance.


#2

You can use something like this in your styles.less:

.editor .embedded.php {
	background: #000;
}

Using whatever colour you want instead of #000.


#3

Thank you, for most of the code works,
but in one case is not working look screenshot

Thanks again for the help.


#4

Hello,
when i write PHP between Javascript and jQuery is not changing background color… (not always, in some cases). How to fix this?

Thanks.


#5

The PHP that isn’t highlighted is inside some Javascript code. Perhaps you need to tweak the Javascript grammar to recognize PHP escape codes (<? and ?>). I don’t know how to tweak grammars, yet.


#6

I have edit the package.json in /Applications/Atom.app/Contents/Resources/app/node_modules/atom-dark-syntax but is not working.

I have add this part:

"begin" : "<\?(php|=)?",
"end" : "\?>",
"scope" : "source.php",
"settings": [
{
"background": "#e5e8c0"
}
]

I have read this guide https://atom.io/docs/latest/creating-a-package#language-grammars but I don’t get it.
Here is how the file looks now:

{
"name": "atom-dark-syntax",
"theme": "syntax",
"version": "0.19.0",
"description": "Default dark theme for syntax",
"repository": {
"type": "git",
"url": "https://github.com/atom/atom-dark-syntax"
},
"license": "MIT",
"engines": {
"atom": ">0.50.0"
},
"readme": "# Atom Dark Syntax theme\n\nDefault dark syntax theme for Atom.\n\nThis theme is installed by default with Atom and can be activated by going to\nthe _Themes_ section in the Settings view (`cmd-,`) and selecting it from the\n_Syntax Themes_ dropdown menu.\n\n![](https://f.cloud.github.com/assets/671378/2264549/f49e9bf2-9e73-11e3-9329-e2d59dd1b119.png)\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/atom/atom-dark-syntax/issues"
},
"homepage": "https://github.com/atom/atom-dark-syntax",
"_id": "atom-dark-syntax@0.19.0",
"dist": {
"shasum": "7c9b0b2976f254b35c3110ff06d64ef60ec127d1"
},
"_resolved": "/var/folders/rn/p9pyl6yx4s706_xbcy89lyfw0000gp/T/d-114622-48768-12u8guu/package.tgz",
"_from": "/var/folders/rn/p9pyl6yx4s706_xbcy89lyfw0000gp/T/d-114622-48768-12u8guu/package.tgz",





"begin" : "<\?(php|=)?",
"end" : "\?>",
"scope" : "source.php",
"settings": [
{
"background": "#e5e8c0"
}
]




}

#7

I think you want this file:

/Applications/Atom.app/Contents/Resources/app/node_modules/language-javascript/grammars/javascript.json

But I don’t have a good idea how to do it. I searched in the PHP grammar, and the key word to search for seems to be “inject”, but if you search for that you will see that it already attempts to inject itself for JS code. PHP grammar is here:

/Applications/Atom.app/Contents/Resources/app/node_modules/language-php/grammars/php.json

#8

Yes you are right, these are the files. I think it’s a bug (not sure)… because I download the Twilight-Syntax the default Textmate 2 theme (which gives different PHP background color) but when I use this theme in Atom works fine with HTML and Jquery but I have same problem with PHP into plain Javascript.

In Textmate 2 works perfect:

I write a lot Javascript with PHP all day and this is problem for me.
Anyone expert with grammar to help? Anyone to confirm that is not bug?


#9

Looks like highlight error, screenshot (the green part):


#10

Did you know that you can just drop the screenshot right into the text box? This prevents people from having to click a link with obnoxious ads and Discourse provides much better lightbox functionality than most image viewing sites out there:


#11

I didn’t know, I have correct my posts for the screenshots,
yes is better, thank you.


#12

Hi, if I put PHP code between “” in Javascript then the background color works.

var dates_1 = "<? echo json_encode($_chart_schedule_week_dates_1); ?>";//works
var dates_1 = <? echo json_encode($_chart_schedule_week_dates_1); ?>;//not working

Do I need to edit the theme to fix it?
Do I need to create package to fix it?
It is the grammar?
It’s code highlight bug? so I have to wait for next versions?

Thanks.


#13

Hi, this solution doesn’t work anymore, any ideas please?


#14

Solution here!