beautifier / js-beautify

Beautifier for javascript
https://beautifier.io
MIT License
8.5k stars 1.36k forks source link

Handlebars support #660

Open spruce opened 9 years ago

spruce commented 9 years ago

Hey, I'm using your library in the sublime extension and was beginning to think whether there exists the possibility to add some custom parser for Handlebars? Because there are some specialities to using Handlebars (and in some time HTMLBars).

One example would be:

{{em-input label="Some Labe" property="amt" type="text" placeholder=""}} {{em-input label="Type*" property="type" type="text" placeholder="(LTD)"}} {{em-input label="Place*" property="place" type="text" placeholder=""}} 

Should be formatted like this:

{{em-input label="Some Labe" property="amt" type="text" placeholder=""}}
{{em-input label="Type*" property="type" type="text" placeholder="(LTD)"}}
{{em-input label="Place*" property="place" type="text" placeholder=""}} 

but the html-parser doesn't understand that syntax. That is understandable but I like that to change :)

spruce commented 9 years ago

Some current Handlebars-issues: #576 #566 #577 #623 #1040 #1173 #1199

louwers commented 8 years ago

My thread seems to be a duplicate: https://github.com/beautify-web/js-beautify/issues/801

basbebe commented 8 years ago

+1

lnmunhoz commented 8 years ago

+1 @rafaelcorreiapoli

rafaelcorreiapoli commented 8 years ago

+1 !!

cancerberoSgx commented 6 years ago

Can I use js-beautify to format handlebars templates ?

simaks commented 6 years ago

+1

Alonski commented 6 years ago

Is it possible to get some guidance in moving this along? Where should I look in the code to possibly start fixing some of these problems and get a PR working?

bitwiseman commented 6 years ago

It's a little hard to nail down because the html beautifier doesn't parse the tags into tokens before formatting.

This is the main loop. There are some special treatment of some handlebars tags but most of them are treated like regular tags. Not great. https://github.com/beautify-web/js-beautify/blob/master/js/src/html/beautifier.js#L882

If you do a search for indent_handlebars you'll find a bunch of other places with special cases for handlebars.

The best thing to do would be to get the html beautifier to parse all input separate from formatting, but that is a bigger effort.