curly
curly copied to clipboard
Don't include extra whitespace in compiled text
Currently Curly ends up adding extra newlines after components like conditional or context block tags, which can make the resulting markup hard to read.
With this PR the following output:
<section class="knowledge-base">
<div class="category-tree">
<section class="category">
<section class="section">
is shortened to:
<section class="knowledge-base">
<div class="category-tree">
<section class="category">
<section class="section">
Alternatively Curly could strip text output altogether, but that may make the markup unreadable for lack of whitespace.
/cc @dasch
I'm not quite sure I agree with the way it's implemented. I agree that for block components, it would make sense to remove the entire line in the output, iff there's only whitespace and the component itself on that line, e.g.
<div>
{{@post}}
<ul>
{{*comments}}
<li>{{body}}</li>
{{/comments}}
</ul>
{{/post}}
</div>
... should output
<div>
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
</div>
I'm just not sure what the best way to do that is. Maybe add tokens for end-of-line in the scanner, and collapse leading and trailing whitespace in the parser?
Yeah the method proposed in this PR is pretty heavy-handed. I was also unsure what the expectation was for preserving whitespace, so thanks for clarifying that.
I'll take a look into a smarter way to to this in the scanner/parser.
In theory, we could have a stream modifier that post-processes the token stream (which is output by the scanner) by looking for NEWLINE, WHITESPACE, BLOCK COMPONENT START/END, WHITESPACE, NEWLINE
and replacing with BLOCK COMPONENT START/END, NEWLINE
, but I'm not sure it's worth it.