Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-line with lines starting with space

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).

like image 892
Alois Mahdal Avatar asked Oct 26 '13 20:10

Alois Mahdal


1 Answers

You should look into Block Chomping Indicator spec.

In your case it will look like:

data:
    maybe_a_bulleted_list: |4+
         *  apples
         *  oranges
         *  lemons
like image 187
lig Avatar answered Oct 02 '22 16:10

lig