'How To Line Break Inside Code Tag In .slim

So I've been looking all up and down Google and I've got nothing. So can someone help?

I have my .slim file all set up and I'm trying to and a pre - code section with a line break in it...

pre
    code[class="language-markup" id="copyHTML-1"]
        = '<label for="name-1">Label</label>\
            <input id="name-1" type="text" name="name" required>'

The output is...

<label for="name-1">Label</label>\
<input id="name-1" type="text" name="name" required>

I get the line break but I get the trailing backslash. How do I get a link break in there with no trailing backslash?

Thanks in advance.



Solution 1:[1]

Actually, line break in string is "\n" in Ruby, and \n must be placed in double quotes "", so you could try this:

= "<label for='name-1'>Label</label>\n
     <input id='name-1' type='text' name='name' required>"

Update part:

Or you could just use slim syntax:

label[for="name-1"]
  | Label
input#name-1[type="text" name="name" required]

Solution 2:[2]

Sounds like you might want to enable the Slim pretty-print feature, which indents nested tags on different lines.

For Rails, you could set this in an environment file., for example config/environments/development.rb:

# Indent html for pretty debugging and do not sort attributes
Slim::Engine.set_options pretty: true, sort_attrs: false

The Slim documentation has more info: https://github.com/slim-template/slim#configuring-slim

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Mike Slinn