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

Handlebars support #4

Closed
Glavin001 opened this issue Jun 4, 2014 · 3 comments
Closed

Handlebars support #4

Glavin001 opened this issue Jun 4, 2014 · 3 comments

Comments

@Glavin001
Copy link

Currently, the HTML beautifier will treat Handlebars as content. I believe js-beautifier does support indentation of Handlebars in HTML code. I will look into this further and get back with my findings.

Please +1 if you are interesting in this feature; I may even submit a Pull Request if it will help.

/cc @Frozenfire92

@Glavin001
Copy link
Author

See https://github.com/einars/js-beautify/blob/219a44e96c92f7362143ff14925dd27c34640fb2/js/lib/beautify-html.js#L181

if (indent_handlebars) {
                        // Handlebars parsing is complicated.
                        // {{#foo}} and {{/foo}} are formatted tags.
                        // {{something}} should get treated as content, except:
                        // {{else}} specifically behaves like {{#if}} and {{/if}}
                        var peek3 = this.input.substr(this.pos, 3);
                        if (peek3 === '{{#' || peek3 === '{{/') {
                            // These are tags and not content.
                            break;
                        } else if (this.input.substr(this.pos, 2) === '{{') {
                            if (this.get_tag(true) === '{{else}}') {
                                break;
                            }
                        }
                    }

It looks like indent_handlebars is default false: https://github.com/einars/js-beautify/blob/219a44e96c92f7362143ff14925dd27c34640fb2/js/lib/beautify-html.js#L54

If this is configurable, then we are all set!

How about when the file extension is .hbs or .handlebars then it turns to true.

@Glavin001
Copy link
Author

Reproduce this bug:

{{#if flag}} content1 {{else}} content2 {{/if}}

Then beautifier, it does not change. It should look like:

{{#if flag}} 
    content1 
{{else}} 
    content2 
{{/if}}

@Glavin001
Copy link
Author

Moving to Glavin001/atom-beautify#13.

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

1 participant