max pleaner max pleaner - 1 month ago 6
Ruby Question

slim - how to make a node which contains both plaintext and other nodes

Here's my slim template:

h5
span built by
a href='http://maxpleaner.com' maxpleaner
| with
a a href='http://github.com/maxpleaner/static' static


I was expecting this to render this:


built by maxpleaner with static


but it is rendering this instead:


built by a href='http://maxpleaner.com' maxpleaner | with a a href='http://github.com/maxpleaner/static' static


Is there a way to mix plaintext and child nodes, or do I need to make child nodes to contain my plaintext?

Answer

If you start with text on the same line as the tag, Slim considers the whole nested block to be plain text. If you move “built by” down into the block it works like you want:

h5
  span
    | built by 
    a href='http://maxpleaner.com' maxpleaner
    |  with 
    a href='http://github.com/maxpleaner/static' static

You have to be careful about whitespace here though. You may prefer to use ' instead of |, and add a > to your tags:

h5
  span
    ' built by
    a> href='http://maxpleaner.com' maxpleaner
    ' with
    a href='http://github.com/maxpleaner/static' static

To avoid whitespace issues you could use an embedded language like markdown, but this adds p tags, so might not be ideal in this case:

h5: span
  markdown:
    built by [maxpleaner](http://maxpleaner.com) with [static](http://github.com/maxpleaner/static)
Comments