"content1": "Arbitrary free text\nover \"multiple lines\" stopping\nafter indentation changes. # After string we have 2 spaces and 2 new lines Literal Block Scalar: A Literal Block Scalar | will include the newlines and any trailing spaces. "content": "Arbitrary free text over multiple lines stopping after indentation changes."Ģ. # Note: It has 1 new line after the string Block Notation(plain, flow-style, scalar): Newlines become spaces and extra newlines after the block are removed. Some of this information has also been summarised here.ġ. *2 block styles, each with 2 possible block chomping indicators (or none), and with 9 possible indentation indicators (or none), 1 plain style and 2 quoted styles: 2 x (2 + 1) x (9 + 1) + 1 + 2 = 63 "very \"long\" 'string' with\nparagraph gap, \n and spaces.", "very \"long\"\n'string' with\n\nparagraph gap, "very \"long\" 'string' with\nparagraph gap, Note the trailing spaces on the line before "spaces." - > "Leading space" applies after the first line (which establishes the indent) \n means "newline character" ( \n in JavaScript) except under "Other features". Note that such a more-indented line may consist only of such leading white space. In addition, folding does not apply to line breaks surrounding text lines that contain leading white space. (This doesn't happen with flow styles.) Section 6.5: If you insert extra spaces at the start of not-the-first lines in Folded style, they will be kept, with a bonus newline. Note: Leading spaces in Folded style ( >) Just in case the above isn't enough for you, you can add a " block indentation indicator" (after your block chomping indicator, if you have one): - >8 → "this is my very very \"very\" long string, isn't it."Īdvice: Avoid. Single-quoted style (literal ' must be doubled, no special characters, possibly useful for expressing strings starting with double quotes): Key: 'this is my very very "very" And maybe adding newlines mid-line is conceivably useful. This is the only way you can break a very long token (like a URL) across lines without adding spaces. → "this is my very very \"very\" loooong string.\n\nLove, YAML."Īdvice: Use in very specific situations. May look convenient, but you're liable to shoot yourself in the foot by accidentally using forbidden punctuation and triggering a syntax error.ĭouble-quoted style ( \ and " must be escaped by \, newlines can be inserted with a literal \n sequence, lines can be concatenated without spaces with trailing \): Key: "this is my very very \"very\" loooo\ Plain style (no escaping, no # or : combinations, first character can't be ", ' or many other punctuation characters ): Key: this is my very very veryĪdvice: Avoid. Doubled newline characters become one newline. They can begin on the same line as the key, or with additional newlines first, which are stripped. These have limited escaping, and construct a single-line string with no new line characters. >+, |+: "keep": keep the line feed, keep trailing blank lines.>-, |-: "strip": remove the line feed, remove the trailing blank lines.>, |: "clip": keep the line feed, remove the trailing blank lines.You can control the handling of the final new line in the string, and any trailing blank lines ( \n\n) by adding a block chomping indicator character: Block styles with block chomping indicator ( >-, |-, >+, |+) Alternatively, they can be written with the folded style (denoted by “>”) where each line break is folded to a space unless it ends an empty or a more-indented line.Īdvice: Use this for inserting formatted text (especially Markdown) as a value. Scalar content can be written in block notation, using a literal style (indicated by “|”) where all line breaks are significant. Here's the official definition from the YAML Spec 1.2 → this is my very very very\nlong string\n Turns every newline within the string into a literal newline, and adds one at the end: Key: | → this is my very very very long string\nĮxtra leading space is retained and causes extra newlines. > Folded style removes single newlines within the string (but adds one at the end, and converts double newlines to singles): Key: > These allow characters such as \ and " without escaping, and add a new line ( \n) to the end of your string. Use "." if you need to split lines in the middle of words or want to literally type linebreaks as \n: key: "Antidisestab\ Use >- or |- instead if you don't want a linebreak appended at the end. Use | if you want those linebreaks to be preserved as \n (for instance, embedded markdown with paragraphs). Use > most of the time: interior line breaks are stripped out, although you get one at the end: key: > There are 5 6 NINE (or 63*, depending how you count) different ways to write multi-line strings in YAML.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |