Skip to content

Nesting & Indentation

padolsey edited this page Mar 17, 2013 · 1 revision

SIML allows nesting of elements, attributes, directives and text within curly brackets or via indentation.

Nesting via indentation

By default (aka curly:false mode), SIML will assume your indents indicate levels of nesting:

html
  head
    title
  body
    header

(Generates)

<html>
  <head>
    <title></title>
  </head>
  <body>
    <header></header>
  </body>
</html>

Some notes about this:

  • Be consistent with your tab/indentation characters. SIML will count the whitespace characters at the start of each line. It won't equate something like four spaces to a single tab character.
  • You can use curly brackets if you wish but you should note that doing so will mean that SIML nesting-via-indentation mechanism will ignore all areas within those brackets.

Just curlies

siml.parse('something', {
  curly: true // Force SIML to ignore indentation, only paying attention to curlies.
});

Using only curly brackets for nesting would look like this:

html {
  head {
    title
  }
  body {
    header
  }
}

Having configured curly:true means that SIML will ignore your indentation. So even if you do:

a
 b
  c

... you'll just get:

<a></a>
<b></b>
<c></c>
Clone this wiki locally