Skip to content

Strip YAML trailing newline #12253

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

Merged
merged 1 commit into from
Sep 2, 2019
Merged

Strip YAML trailing newline #12253

merged 1 commit into from
Sep 2, 2019

Conversation

mikemix
Copy link
Contributor

@mikemix mikemix commented Sep 2, 2019

Previous YAML resulted in a trailing newline!

Previous YAML resulted in a trailing newline!
@mikemix mikemix changed the title Strip YAML trailing multiline Strip YAML trailing newline Sep 2, 2019
@javiereguiluz
Copy link
Member

@mikemix thanks for this. However, I find this syntax a bit confusing ... if we don't add this, where's the newline added? Is the newline visible to end users in the web page? Thanks.

@mikemix
Copy link
Contributor Author

mikemix commented Sep 2, 2019

@javiereguiluz think of yourself as a regular bloke who wants to translate his app. So he visits the docs and sees the examples. Lets create a simple one:

ui:
  article_count: >
      {count, plural,
        one   {one article}
        other {# articles}
      }

And lets use it:

<h1>Articles ({{ 'ui.article_count'|trans({'count': 5}) }})</h1>

You would expect this to be <h1>Articles (5 articles)</h1> right? But this is going to be <h1>Articles(5 articles )</h1> - notice the whitespace before ending parenthesis.

This is because a newline was added (one from the YAML file), the generated html looks as follows:

<h1>Articles (5 articles
)</h1>

So, in my very humble opinion, either use the >- YAML multiline syntax (nothing fancy, see this) which strips ending newline, or add a note that something like that may happen.

The newline is always going to be there, because either there's another translation item in the YAML, or this is the end of the file. AFAIK people usually turn the Ensure line feed at file end on Save on in phpStorm.

@javiereguiluz
Copy link
Member

@mikemix you explained it perfectly! Thanks for such a great and detailed explanation. Let's merge this. Thanks ... and congrats on your first Symfony Docs contribution!

javiereguiluz added a commit that referenced this pull request Sep 2, 2019
This PR was merged into the 4.3 branch.

Discussion
----------

Strip YAML trailing newline

Previous YAML resulted in a trailing newline!

<!--

If your pull request fixes a BUG, use the oldest maintained branch that contains
the bug (see https://symfony.com/roadmap for the list of maintained branches).

If your pull request documents a NEW FEATURE, use the same Symfony branch where
the feature was introduced (and `master` for features of unreleased versions).

-->

Commits
-------

8cdec91 Strip YAML trailing multiline
@javiereguiluz javiereguiluz merged commit 8cdec91 into symfony:4.3 Sep 2, 2019
@mikemix mikemix deleted the patch-1 branch September 2, 2019 14:30
javiereguiluz added a commit that referenced this pull request Sep 2, 2019
…es (javiereguiluz)

This PR was merged into the 3.4 branch.

Discussion
----------

Yaml: minor syntax issues and expanded multi-line examples

Thanks to #12253 (created by @mikemix) I learned about this `>-` syntax ... so I think we should mention it.

Commits
-------

79b0c49 Yaml: minor syntax issues and expanded multi-line examples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants