{"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"lesson-5-block-and-flow-scalars","__idx":0},"children":["Lesson 5: Block and flow scalars"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Write a string across more than one line using literal blocks, folded blocks, or flows."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This is also the course's first introduction to indentation within YAML files."," ","YAML is commonly indented with two-space increments."," ","It's important to use spaces and not \"tab\" characters for indentation."," ","It's okay to use tabs if your editor converts them to spaces (most do have that as a setting)."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"literal-blocks","__idx":1},"children":["Literal blocks"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["A literal style block starts with a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["|"]}," followed by a line break and indentation."," ","Then, the string starts on the next line."," ","Indent all the lines for the same string the same way."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"yaml","header":{"controls":{"copy":{}}},"source":"summary: regular scalar\ndescription: |\n  This is my sentence with the literal scalar.\n  And another sentence.\noperationId: jasmint\n","lang":"yaml"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The literal style block has a line break after the first sentence in the example."," ","Line breaks are taken literally (as actual line breaks within the string)."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"folded-blocks","__idx":2},"children":["Folded blocks"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["A folded style block starts with a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":[">"]}," followed by a line break."," ","But the line breaks are treated as a line break if there are multiple consecutive line breaks."," ","Otherwise, they're treated as spaces."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"yaml","header":{"controls":{"copy":{}}},"source":"summary: regular scalar\ndescription: >\n  This is my sentence with the folded scalar.\n  And another sentence starts without a preceding line break.\n\n  And a sentence starts with a preceding line break, because there are two consecutive line breaks preceding this line.\noperationId: jasmint\n","lang":"yaml"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"line-breaks-to-end-blocks","__idx":3},"children":["Line breaks to end blocks"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The block type can be followed with nothing (as shown in the examples above) which is the default clip."]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Line break style"},"children":["Line break style"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Description"},"children":["Description"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Clip  (default)"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Adds single line break at the end of the string"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Strip (-)"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Removes line breaks from the end of the string"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Keep (+)"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Keeps (more than one) line breaks at the end of the string"]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Examples with literal style"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"yaml","header":{"controls":{"copy":{}}},"source":"description: |\n  This has the default\n  Clip behavior.\n","lang":"yaml"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"yaml","header":{"controls":{"copy":{}}},"source":"description: |-\n  This has the strip\n  behavior.\n","lang":"yaml"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"yaml","header":{"controls":{"copy":{}}},"source":"description: |+\n  This has the keep\n  behavior.\n","lang":"yaml"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Examples with folded style"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"yaml","header":{"controls":{"copy":{}}},"source":"description: >\n  This has the default\n  Clip behavior.\n","lang":"yaml"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"yaml","header":{"controls":{"copy":{}}},"source":"description: >-\n  This has the strip\n  behavior.\n","lang":"yaml"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"yaml","header":{"controls":{"copy":{}}},"source":"description: >+\n  This has the keep\n  behavior.\n","lang":"yaml"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"flow-scalars","__idx":4},"children":["Flow scalars"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You should be aware of flow scalars (but probably not use them because you have less explicit control of the behavior)."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"yaml","header":{"controls":{"copy":{}}},"source":"Summary: regular scalar\nDescription: This is my sentence with a flow scalar.\n  And this is my next sentence.\noperationId: scaly\n","lang":"yaml"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"yaml","header":{"controls":{"copy":{}}},"source":"Summary: regular scalar\nDescription: 'This is my sentence with a flow scalar.\n  And this is my next sentence.'\noperationId: scaly\n","lang":"yaml"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"yaml","header":{"controls":{"copy":{}}},"source":"Summary: regular scalar\nDescription: \"This is my sentence with a flow scalar.\n  And this is my next sentence.\"\noperationId: scaly\n","lang":"yaml"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The single quote removes the ending line break."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"exercise-51-find-the-problematic-scalars-multiple-choice","__idx":5},"children":["Exercise 5.1: Find the problematic scalars (multiple choice)"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["A)"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"yaml","header":{"controls":{"copy":{}}},"source":"# Example A\nDescription: |\nThis is my description of a wonderful exercise.\n","lang":"yaml"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["B)"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"yaml","header":{"controls":{"copy":{}}},"source":"# Example B\nDescription: {\n  This is my description of a wonderful exercise.\n","lang":"yaml"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["C)"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"yaml","header":{"controls":{"copy":{}}},"source":"# Example C\nDescription: <\n  This is my description of a wonderful exercise.\n","lang":"yaml"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["D)"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"yaml","header":{"controls":{"copy":{}}},"source":"# Example D\nDescription: This is my first sentence.\nThis is my description of a wonderful exercise.\n","lang":"yaml"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Which scalar is problematic?"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Example A"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Example B"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Example C"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Example D"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["All of the above"]}]},{"$$mdtype":"Tag","name":"details","attributes":{},"children":[{"$$mdtype":"Tag","name":"summary","attributes":{},"children":["See answer"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["All of the above."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Example A is missing indentation."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"diff","header":{"controls":{"copy":{}}},"source":"# Example A\nDescription: |\n- This is my description of a wonderful exercise.\n+   This is my description of a wonderful exercise.\n","lang":"diff"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Example B used a wrong token ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["{"]}," instead of ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["|"]}," or ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":[">"]},"."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"diff","header":{"controls":{"copy":{}}},"source":"# Example B\n- Description: {\n+ Description: |\n    This is my description of a wonderful exercise.\n","lang":"diff"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Example C had the mirror of the correct symbol ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":[">"]},"."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"diff","header":{"controls":{"copy":{}}},"source":"# Example C\n- Description: <\n+ Description: >\n    This is my description of a wonderful exercise.\n","lang":"diff"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Example D uses a flow scalar but lacks the indentation."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"diff","header":{"controls":{"copy":{}}},"source":"# Example D\nDescription: This is my first sentence.\n- This is my description of a wonderful exercise.\n+   This is my description of a wonderful exercise.\n","lang":"diff"},"children":[]}]}]},"frontmatter":{"seo":{"title":"Block and flow scalars"}},"tagList":["html"],"title":"Block and flow scalars","lastModified":"2025-05-28T16:01:32.000Z"}