Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emmet not working in files with .php extension #17

Open
maktaba opened this issue Aug 25, 2016 · 4 comments
Open

Emmet not working in files with .php extension #17

maktaba opened this issue Aug 25, 2016 · 4 comments

Comments

@maktaba
Copy link

maktaba commented Aug 25, 2016

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.

@sergeche
Copy link
Member

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

@maktaba
Copy link
Author

maktaba commented Aug 25, 2016

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);
},

@sergeche
Copy link
Member

How exactly Emmet behaviour differs for PHP for you?

@maktaba
Copy link
Author

maktaba commented Aug 25, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants