Is there a way create a multi-line scalar in YAML that would preserve leading spaces for all lines?
For example, this text:
* apples
* oranges
* lemons
intentionally starts each line with space. What if I want to have exactly the above
string (i.e. " * apples\n * oranges\n * lemons"
defined somewhere in YAML document? Is it possible to do without losing the spaces and
in a most readable way?
The usual way using the |
does not work as it strips the spaces before the asterisks:
data:
maybe_a_bulleted_list: |
* apples
* oranges
* lemons
but if I could just say that the next block is indented by four spaces instead of five (subtracting the previous indentation, which is already known), it would be almost what I need.
Is there a way to achieve this with elegant YAML?
Background: I'm trying to create a human-editable file that contains small sections of free text that will end up converted to HTML. I would like to use Markdown for this, but since the sections are going to be only simple (un)ordered lists, I'm thinking about supporting both Markdown and TracWiki. The problem is that TracWiki format, to work properly, needs each bullet list item to start with space (otherwise multi-line items don't fold properly).
You should look into Block Chomping Indicator spec.
In your case it will look like:
data:
maybe_a_bulleted_list: |4+
* apples
* oranges
* lemons
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With