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

Support Handlebars #5340

Closed
suchipi opened this issue Nov 5, 2018 · 23 comments
Closed

Support Handlebars #5340

suchipi opened this issue Nov 5, 2018 · 23 comments
Labels
difficulty:hard Issues that might take an entire weekend, or require a tough decision to fix lang:handlebars Issues affecting Handlebars (Glimmer) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. scope:plugin The requested enhancement doesn't belong in Prettier core, but would be a good fit for a plugin type:enhancement A potential new feature to be added, or an improvement to how we print something

Comments

@suchipi
Copy link
Member

suchipi commented Nov 5, 2018

I am opening this issue to track Handlebars support. It was previously tracked in #1882 but that was closed when we added HTML support, so this issue is for Handlebars only.

@suchipi suchipi added type:enhancement A potential new feature to be added, or an improvement to how we print something difficulty:hard Issues that might take an entire weekend, or require a tough decision to fix lang:handlebars Issues affecting Handlebars (Glimmer) labels Nov 5, 2018
@buschtoens
Copy link

Am I correct in assuming, that work has already started in language-handlebars, but is not usable yet?

@suchipi
Copy link
Member Author

suchipi commented Nov 15, 2018

@buschtoens yes

@peterjmag
Copy link

For anyone who might be watching this, you can already try this out like so:

yarn prettier '**/*.hbs' --parser glimmer

Stolen from @ikatyang's comment here: #3534 (comment).

@ikatyang
Copy link
Member

Please note that the glimmer printer is currently unrelated to the HTML printer, which means their formatting rules are not the same. To support Handlebars, we need to somehow combine them together, see #5511 (comment) for more info.

@peterjmag
Copy link

Ah thanks for the clarification @ikatyang! Is my previous comment misleading then? I'm happy to edit it if that's the case.

@mydea
Copy link

mydea commented Feb 22, 2019

I've tried this on our codebase (with --parser glimmer), and in general it seemed to be working quite well, except for one issue: It removes all blank lines, which makes the resulting code rather hard to understand, sometimes. Was this a conscious decision? It is at odds with this: https://prettier.io/docs/en/rationale.html#empty-lines and how this works in JS/CSS.

@lydell
Copy link
Member

lydell commented Feb 22, 2019

@mydea That does not sound intended. Please share an example on the playground.

@mydea
Copy link

mydea commented Feb 22, 2019

Hmm, I can't select the glimmer parser there, as far as I can see?

But what it does is format this:

{{test}}

{{other-test}}


{{final-test}}

to

{{test}}
{{other-test}}
{{final-test}}

@lydell
Copy link
Member

lydell commented Feb 22, 2019

Ah, sorry, I didn't know glimmer wasn't available there.

@Alonski
Copy link
Contributor

Alonski commented Mar 18, 2019

I think adding Glimmer support to the playground should be done anyways so that we can at least experiment with it there.

I would really love to make this official.

@alexander-akait
Copy link
Member

@mfeckie yep, it is bug, better create new issue, also feel free to send a PR with fix (it is easy)

@mfeckie
Copy link

mfeckie commented Mar 18, 2019

@evilebottnawi If I knew how .. I would love to fix it. Happy to open new issue too

@pmccloghrylaing
Copy link

pmccloghrylaing commented Mar 19, 2019

@Alonski
Copy link
Contributor

Alonski commented Mar 19, 2019

@pmccloghrylaing I'm not sure that is valid Handlebars. At least not anything that I have ever seen.

@pmccloghrylaing
Copy link

pmccloghrylaing commented Mar 19, 2019

@Alonski Handlebars doesn't complain about it - @partial-block is really useful if you're creating components and Glimmer doesn't seem to support #if in an attribute value either. The difference is that Handlebars doesn't care about any non-handlebars code - it just gets treated as text - while Glimmer needs to parse the HTML as well and will only support certain Handlebars operations depending on the context.

Here's another example of valid Handlebars that I wouldn't expect Glimmer to support:

<{{#if href}}a href="{{href}}"{{else}}span{{/if}}>...</{{#if href}}a{{else}}span{{/if}}>

@Alonski
Copy link
Contributor

Alonski commented Mar 20, 2019

@pmccloghrylaing ok now I understand you. Maybe this should be called language glimmer then. Or something else. They aren't 100% compatible

@macgyver
Copy link

Is there any plan for handlebars support? it seems like Glimmer is on a path to be supported but, as was pointed out, Glimmer !== Handlebars.

@alexander-akait
Copy link
Member

@macgyver we have plugin api, so you can start this as plugin right now

@gossi
Copy link

gossi commented Jan 16, 2020

I realized today, this is stripping the tilde character: ~

Prettier 1.19.1
Playground link

--parser glimmer

Input:

    <li data-test-reason>
      {{#if some.thing}}
        for {{~some.item~}}
      {{else}}
        <span class="empty">
          ----
        </span>
      {{/if}}
    </li>

Output:

<li data-test-reason>
  {{#if some.thing}}
    for{{some.item}}
  {{else}}
    <span class="empty">
      ----
    </span>
  {{/if}}
</li>

Original Report: mfeckie/handlebars-formatter#18

@ghost
Copy link

ghost commented Jan 16, 2020

@gossi thanks for finding that! A few of us created this issue for asynchronous project management around glimmer + prettier: jgwhite#1
If this specific issue is not tracked there we definitely should add it!

@thorn0
Copy link
Member

thorn0 commented Jun 10, 2020

There is no plans to add support for Handlebars outside of Glimmer's subset. Prettier's plugin API can be used to create a plugin for it.

Glimmer is tracked in #4908 and jgwhite#1.

@thorn0 thorn0 closed this as completed Jun 10, 2020
@thorn0 thorn0 added the scope:plugin The requested enhancement doesn't belong in Prettier core, but would be a good fit for a plugin label Jun 10, 2020
@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Sep 9, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
difficulty:hard Issues that might take an entire weekend, or require a tough decision to fix lang:handlebars Issues affecting Handlebars (Glimmer) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. scope:plugin The requested enhancement doesn't belong in Prettier core, but would be a good fit for a plugin type:enhancement A potential new feature to be added, or an improvement to how we print something
Projects
None yet
Development

No branches or pull requests