Steve Howell [mailto:showell@...] wrote:
> > - >
> > This is paragraph
> > Number 1.
> > There is 1 newline in between these.
> > *This* accomplishes DWIM.
> > There are 2 newlines in between these,
> > and so on.
> > - |
> > This is paragraph Number 1.
> > There is 1 newline in between these. *This* accomplishes DWIM.
> > There are 2 newlines in between these, and so on.
> I don't see how this is DWIM at all. YAML is robbing me of
> newlines when I don't expect them to be robbed. The only place
> I want newlines removed is inside the paragraph.
That is, there would be no way whatsoever to write the above example in a
folded style? That seems wrong to me. I'd be forced to use escaped format to
write the above? Ugh.
> Most folks separate paragraphs with empty lines. For
> example, you separate
> paragraphs in your email with empty lines. But now, for
> YAML, we are going
> to require an extra newline? This seems wrong to me.
Separating paragraphs with an empty line is exactly what I expect to
happen... That's what the folded style *does*. If you are using a folded
format, your *internal* format is "newline to end a paragraph". Not two. If
your *internal* format says "two newlines to separate a paragraph", it means
you are doing another folding *on top* of the YAML folding. Fine, just
This is paragraph
There is 1 newline in between these.
*This* accomplishes DWIM.
There are 2 newlines in between these, and so on.
And feed that into your own folding code.
If your problem is "how do I display folded text in a human-friendly way",
the answer is "line-wrap it as if it will be written into a folded scalar".
This gives you back your empty line. You *have* to do *something* to such
text before displaying it to a user *anyway*, otherwise you will get
extremely long lines which isn't what you mean. If you have some OS or
window system code that line-wraps the value but doesn't add an empty line,
and you insist on displaying them, just double the newlines before you pass
it to this code. In HTML, just change each line feed to </p><p>. And so on.
The correct solution depends on the system used to display the text.
> > ... the above is the correct
> > interpretation, as a reading of the spec will quickly show:
> > "... Thus a single line feed can be serialized as two, two
> > line feeds can be serialized as three, etc.".
> Yes, but then the spec also says this:
> In nested scalars, folding only applies to line feeds that
> separate text
> lines starting with a non-space character.
All the line feeds in the above examples satisfy this (except for the very
final one and that one is controlled by the chomping modifier). Note the
folding applies to "line feed*S*". A better phrasing would be "applies to
*sequences of line feeds* that...".
> Hence, folding does not apply to
> leading line feeds, line feeds surrounding an empty line ending with a
> specific line break, or line feeds surrounding a text line
> that starts with a space character.
The above examples don't contain any of these exceptions.
> There's no compelling use case for smushed paragraphs.
I think that:
- An internal representation where a line feeds represents a paragraph break
and there's no trace of line wrapping is a common use case, and is supported
perfectly by the folded scalar style.
- An internal representation where single line feeds are folded and should
line feeds indicate paragraph is a common use case and is supported
perfectly by using the block scalar style.
- An internal representations where single line feeds are absolutely
forbidden and a double line feed represents a paragraph is something I never
heard of. As you point out, this internal representation format is not
supported well by YAML.
Your proposal would make the first use case impossible. For example:
> They'd still be
> representable in YAML under the more DWIMmish approach,
> although it might be
> a bit ugly. If we want to support smushed paragraphs better,
> perhaps we
> could say that a line that only has a "\" is not rendered,
> but forces the
> preceding line to have a newline?
And have to escape \ in folded scalars? No thanks.