Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,26 @@ The behavior of `=` depends on the setting of the `escapeHtmlByDefault` configur

Haml(src, {escapeHtmlByDefault: true})

## Multi Lines
Attributes can be declared on multiple lines

%input(class="foo"
name="test")
%input{class: "foo",
name: "test"}

Note the above syntax will not work with empty attributes

%input(class="foo"
checked <-- This is not working
name="test")

You can also explcilty use the pipe operator `|` just before line break to write content on multiple lines

%input( |
class="foo" |
name="test" |
)
## Plugins

There are plugins in the parser for things like inline script tags, css blocks, and support for if statements and for loops.
Expand Down
18 changes: 15 additions & 3 deletions lib/haml.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,23 @@ var Haml;
output = [],
ifConditions = [];

// If lines is a string, turn it into an array
// If lines is a string, parse multilines and turn it into an array
if (typeof lines === 'string') {
lines = lines.trim().replace(/\n\r|\r/g, '\n').split('\n');
lines = lines.trim()
// Multine attributes list, use | as a line breaker
lines = lines.replace(/(?<!\|)\|{1}(?!\|)\s*[\n\r]+\s*/g, '')
// Multiline attribute list with (attr="value") notation
lines = lines.replace(/[\n\r]+\s*([a-zA-Z0-9-:@#_]*=['"])/g, function(c, p1) {
return ' ' + p1
})
// Multiline attribute list with {attr: "value"} notation
lines = lines.replace(/,\s*[\n\r]+\s*(['"a-zA-Z0-9-:@#_]*:)/g, function(c, p1) {
return ' ' + p1
})
// Split every line
lines = lines.replace(/\n\r|\r/g, '\n').split('\n');
}

lines.forEach(function(line) {
var match, found = false;

Expand Down