Toml: Trim the newline right before the end-delimiter in multi-line strings.

Created on 10 Apr 2015  ·  3Comments  ·  Source: toml-lang/toml

Although you (the owners?) had decided not to trim the last newline in #225 , I'm still not for it. I'd like to make the newline “obvious”. E.g.

key = '''

Just a sentence.

'''

is equal to key = """\nJust a sentence.\n""". Is it really counter-intuitive?

And a special case:

# key = "\n"
key = """

"""

Most helpful comment

I think this issue can be closed:

  1. The OP is now, @ghost.
  2. For the times when you don't want a newline at the start, you can put a \ after the opening quotes.

All 3 comments

To me, yes, what you are suggesting would be counter-intuitive. Trimming the leading newline is also slightly counter-intuitive, but the value of "all column-1 text can start on column 1 of the file" is greater than that counter-intuitiveness. But in your "Just a sentence" example, my brain expects to see two newlines at the end, because there's a blank line there before the closing delimiter. The absence of that second newline would bother me immensely, as would the absence of a final newline in this example:

key = """
Just a sentence.
"""

If I wanted to have no newline at the end of that example, I would have put the closing tag immediately after the period -- and, in fact, I would have simply written "Just a sentence." on a single line in that case. If TOML stripped the newline that I intended to be there, I would be surprised and annoyed.

Think about indentation, or you'll repeat the ugliness of "here documents" taught in too many bash tutorials:

function ugly () {
  ( foo_header
    foo_content_escape <<EndOfContent
      Hello world, indentation is great!
      Unfortunately, most tutorials make it
      look like it's not allowed here:
EndOfContent
    foo_trailer
    ) | tr A-Z a-z
}

In bash and dash, fortunately, you can cheat by making the exact amount of whitespace part of your marker (which you'll then have to quote). In TOML however, you can't choose the marker.

I think this issue can be closed:

  1. The OP is now, @ghost.
  2. For the times when you don't want a newline at the start, you can put a \ after the opening quotes.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ChristianSi picture ChristianSi  ·  3Comments

uvtc picture uvtc  ·  3Comments

clarfonthey picture clarfonthey  ·  4Comments

hukkin picture hukkin  ·  4Comments

jdfergason picture jdfergason  ·  4Comments