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

Auto-indent of partials causes problems with rendering code blocks in blog posts #4364

Closed
ErisDS opened this issue Oct 30, 2014 · 1 comment
Labels
bug [triage] something behaving unexpectedly
Milestone

Comments

@ErisDS
Copy link
Member

ErisDS commented Oct 30, 2014

There is an ongoing discussion about this on the handlebars repo. It was originally discovered as a sort-of-bug-in-Ghost via a weird issue on the forum and applies to themes which use a partial to output content. I'm raising it here as a way to keep track of it.


Essentially, in Handlebars 2.0.0, any partial which is indented is now rendered with that indent applied to the beginning of every line output by the partial. So if I have a partial like:

<section>
{{content}}
</section>

and I output it in my post.hbs like:

<body>
    {{> my-partial}}
</body>

Then every line of the partial, including every line output by {{content}} will have 4 spaces applied at the beginning, just like the {{> my-partial}} line has.

This sort of makes sense - it makes for nicely aligned source code, but it also fudges with anything in the partial which is whitespace-sensitive, like a <pre> or a <textarea>. Essentially, if you have a nicely formatted code block in your blog content, when it gets rendered to the page, all the lines of code will weirdly have 4 extra spaces at the start.

The solution is simple enough - don't use a partial, or don't indent your partial, but this behaviour is very hard to predict in my opinion.

The discussion on the handlebars repo might lead to a compiler flag we can use to disable this. Alternatively we could downgrade back to handlebars 1.3.0 for rendering themes. If we do neither of these, then we have to be very careful to document this behaviour.

@ErisDS ErisDS added bug [triage] something behaving unexpectedly themes labels Oct 30, 2014
@ErisDS ErisDS added this to the Next Backlog milestone Oct 30, 2014
@egoist
Copy link

egoist commented Feb 14, 2015

Meet the same bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [triage] something behaving unexpectedly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants