Kirill,
Folding is somewhat difficult concept (and entirely due to my
requirements, Oren and Brian are humoring me with this one). The idea
is to allow paragraph text wrapping in a way that does not introduce
spurious carriage returns needed only for text "readability". Hence,
each paragraph is seen as a sequence of characters -- without a carriage
return in them. There are two complications: (a) an actual carriage
return is indicated with two adjacent carriage returns, (b) to allow for
bulleted lists, carriage returns *between* indented content is
preserved.
The rules for this, unfortunately, are kinda ugly:
1. Move the entire folded block into a string buffer, stripping
all "block" indentation.
2. Replace single occurances of a carraige return that is not
immediately followed by a whitespace with a single space.
3. Replace runs of N adjacent carriage returns with N-1
carriage returns.
4. Stripping trailing whitespace; adding a terminating carriage
return.
I'm not sure if this is exactly what is in the specification; but
it is how I had implemented this style a long while back.
On Sat, Feb 18, 2006 at 10:33:51PM +0200, Kirill Simonov wrote:
| >
| .folded
| .line
|
| .next
| .line
|
| ...* bullet
| ...* list
|
| .last
| .line
So, in my buffer after stripping block indentation we have:
"folded\nline\n\nnext\nline\n\n"
" * bullet\n * list\n\n"
"last\nline\n"
After replacing single occurances of a carriage returns not
immediately followed by a tab or space:
"folded line\n\nnext line\n\n"
" * bullet\n * list\n\n"
"last line "
Then replacing *runs* of N carriage returns with N-1:
"folded line\nnext line\n"
" * bullet\n * list\n"
"last line "
After the final step, giving:
| %YAML 1.1
| ---
| !!seq [
| !!str "folded line\n\
| next line\n\
| \ * bullet\n\
| \ * list\n\
| last line\n"
| ]
which, seems correct to the interpretation we have.
| It means that the line break after ".line" is folded. But the spec says
|
| ...empty lines separating lines of a different type are never
| folded...
I think that this was an *attempt* to explain the folding rule for
indented items, but it doesn't reflect the intent. So, I think in this
case the example is correct, but the descriptive rule is wrong. The
rule above, btw, also means that an extra carriage return between
bullets is ignored -- which I think is the intended effect.
| In this case, the correct interpretation should be
|
| %YAML 1.1
| ---
| !!seq [
| !!str "folded line\n\
| next line\n\n\
| \ * bullet\n\
| \ * list\n\n\
| last line\n"
| ]
|
| Is there an easy rule that describes how folding should be done?
Yea, you're correct that the example is wrong given the spec's rule;
however, I think it is the rule that needs to be fixed. I hope the
recipe above helps.
Kind Regards,
Clark
|