emmetio/npp

Emmet not working in files with .php extension

maktaba opened this issue · 4 comments

Is there any way I can get emmet to work within html files that are saved with the .php file extension.

I love using Emmet, but I have hundreds of (legacy) files full of html with (some) php inside them that have the .php extension.
Not being able to use emmet when working on these files basically make it useless to me.

Just to be clear I'm not asking to use emmet to write any php or to change the keybindings etc.
Only that emmet treats a file with the .php file extension in the same way as a .html


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

You can update this function to return html if current file has .php extension

Hi Sergache

Thank for a quick reply.
I've tried to do as you suggested (code below), but can't seem to get it to work.
The thing that bugs me is that 'html' is the default, even for a file that no extension, but if the extension is php then emmet doesn't kick in.
Could that mean that it is actively disabled in the case of a php file?
After trying the code below I tried to force things by always returning 'html' just to see what would happen: return require('actionUtils').detectSyntax(this, 'html');
But that didn't make any change to how emmet behaved either.

getSyntax: function() {
var syntax = this._syntax || 'html';
var fileExt = 'html';
var m = this.getFilePath().match(/.(\w+)$/i);
if (m) {
fileExt = m[1];
}

if (fileExt == 'php') {
syntax = 'html';
}

if (syntax == 'user') {
syntax = fileExt;
}

// maybe it's XSL?
if (syntax == 'xml' && fileExt == 'xsl') {
syntax = 'xsl';
}

return require('actionUtils').detectSyntax(this, syntax);
},

How exactly Emmet behaviour differs for PHP for you?

Hi Sergeche

I was about to send you an example, when I discovered what my problem was, it has nothing to do with the file extension or syntax detection.
I had made a simple php file with some html in it and saved it no text, then opened it and emmett would not make an appearance at all, nothing.
When I was about to send you my example code I noticed the encoding "ANSI" even though new docs in Notepad++ are UTF-8 be default.
When I changed the encoding to UTF-8 then everything worked fine without having to resort to changing any emmet javascript.

Notepad++ occasionally get the encoding detection wrong.
When you save a simple text file with the UTF-8 encoding but without actually using any UTF-8 encoded characters, then it fails to detect UTF-8 and displays in "ANSI" and then Emmet does not kick in and nothing seems to work.

A simple work around for the detection problem is to make a comment with a single UTF-8 character or /* ñ */
Then Notepad++ will detect it corectly.

Thank you for your time, hopefully it is not "wasted" and this small thread will help another lost soul in the future.

So in this case the solution was simple: Make sure the file encoding is UTF-8!

Thanks,
Jan