-
Notifications
You must be signed in to change notification settings - Fork 73
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
Add whitespace guidance document #197
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,107 @@ | ||||||||||
# Whitespace in Mustache | ||||||||||
|
||||||||||
*(This document is non-normative and summarizes the whitespace rules presented in the specs for implementation authors.)* | ||||||||||
|
||||||||||
## Terms | ||||||||||
|
||||||||||
<dl> | ||||||||||
<dt>element</dt> | ||||||||||
<dd>A section, inverted section, parent, or block tag plus its content up to and including its associated end tag. For example, <code>{{$foo}}bar{{/foo}}</code> is a single block element.</dd> | ||||||||||
<dt>argument block</dt> | ||||||||||
<dd>A block element that is a direct child of a parent tag.</dd> | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(or whatever other term for "element " we come up with). This could probably also use an example ( |
||||||||||
<dt>parameter block</dt> | ||||||||||
<dd>A block element that is not a direct child of a parent tag.</dd> | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
</dl> | ||||||||||
|
||||||||||
## Standalone tags and elements | ||||||||||
|
||||||||||
Mustache tries to avoid adding undesired blank lines for non-interpolation tags. | ||||||||||
For example, assuming that `boolean = true`, the following template: | ||||||||||
|
||||||||||
```mustache | ||||||||||
| This Is | ||||||||||
{{#boolean}} | ||||||||||
| | ||||||||||
{{/boolean}} | ||||||||||
| A Line | ||||||||||
``` | ||||||||||
|
||||||||||
will render as: | ||||||||||
|
||||||||||
```plain | ||||||||||
| This Is | ||||||||||
| | ||||||||||
| A Line | ||||||||||
``` | ||||||||||
|
||||||||||
instead of: | ||||||||||
|
||||||||||
```plain | ||||||||||
| This Is | ||||||||||
|
||||||||||
| | ||||||||||
|
||||||||||
| A Line | ||||||||||
``` | ||||||||||
|
||||||||||
A tag is considered **standalone** if the tag is the only text on the line except whitespace. | ||||||||||
Interpolation tags are never considered standalone. | ||||||||||
The leading whitespace, trailing whitespace, and line ending of a standalone tag are ignored. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Ignored" could be further clarified. I would say that this whitespace is not part of the literal template content, but could be considered part of the tag delimiters instead. |
||||||||||
|
||||||||||
Additionally, parent elements and parameter blocks | ||||||||||
are considered standalone if the start tag has zero or more whitespace characters preceding it on its line | ||||||||||
and its associated end tag has zero or more whitespace characters following it on its line. | ||||||||||
Comment on lines
+52
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I don't think it would hurt to include "clearance" in the glossary, but this works. |
||||||||||
In such cases, the leading whitespace of such a parent tag or parameter block's start tag, | ||||||||||
the trailing whitespace of the associated end tag, | ||||||||||
and the line ending of the associated end tag are ignored. | ||||||||||
|
||||||||||
## Indentation | ||||||||||
|
||||||||||
Mustache tries to keep indentation consistent when using partials, parents, and blocks. | ||||||||||
For example, for the following template: | ||||||||||
|
||||||||||
```mustache | ||||||||||
{{<parent}}{{$block}} | ||||||||||
one | ||||||||||
two | ||||||||||
{{/block}}{{/parent}} | ||||||||||
``` | ||||||||||
|
||||||||||
and the following definition of `parent`: | ||||||||||
|
||||||||||
```mustache | ||||||||||
Hi, | ||||||||||
{{$block}} | ||||||||||
{{/block}} | ||||||||||
``` | ||||||||||
|
||||||||||
the template will render as: | ||||||||||
|
||||||||||
```plain | ||||||||||
Hi, | ||||||||||
one | ||||||||||
two | ||||||||||
``` | ||||||||||
|
||||||||||
instead of: | ||||||||||
|
||||||||||
```plain | ||||||||||
Hi, | ||||||||||
one | ||||||||||
two | ||||||||||
``` | ||||||||||
|
||||||||||
If a block tag is at the end of a line (ignoring any trailing whitespace) | ||||||||||
and it is either part of an argument block or part of a standalone parameter block, | ||||||||||
Comment on lines
+94
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wording is a bit confusing because it can be read as if you're only talking about nested blocks, i.e., blocks within blocks. |
||||||||||
then the block element's **intrinsic indentation** is the sequence of leading whitespace characters on the line following the block tag. | ||||||||||
Otherwise, the block element's intrinsic indentation is the empty string. | ||||||||||
Mustache implementations must ignore the occurrence of the block element's intrinsic indentation | ||||||||||
at the beginning of each line of the block element's content. | ||||||||||
Comment on lines
+98
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe more explicit:
Suggested change
|
||||||||||
|
||||||||||
When a standalone partial tag or standalone parent element is expanded, | ||||||||||
the leading whitespace on the start tag's line is prepended to each line of the expanded template. | ||||||||||
A similar behavior occurs for standalone parameter blocks. | ||||||||||
If a standalone parameter block's start tag is at the end of a line (possibly with trailing whitespace), | ||||||||||
then its intrinsic indentation is prepended to each line of the argument block that is overriding it. | ||||||||||
Otherwise, the leading whitespace of the standalone parameter block's start tag | ||||||||||
is prepended to each line of the argument block that is overriding it. | ||||||||||
Comment on lines
+101
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two things:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I somewhat agree that "element" covers the meaning better than "tag pair", but I wish there was a less HTML-centric term that we could use instead. Some people feel that Mustache is prioritizing HTML over other target languages because of escaping and I would rather avoid reinforcing that perception if possible.
I have not come up with another idea yet but will keep trying. Please help!