Permalink
Browse files

"inside" whitespace bugfix

  • Loading branch information...
1 parent dcfea10 commit 5c2e2265859c3c6cb3ce1cbad98837485ed18895 @aaronblohowiak aaronblohowiak committed May 11, 2011
Showing with 35 additions and 13 deletions.
  1. +25 −11 lib/haml.js
  2. +9 −1 test/whitespace.haml
  3. +1 −1 test/whitespace.html
View
@@ -185,20 +185,26 @@ var Haml;
if (attribs) {
attribs = parse_attribs(attribs);
if (attribs._content) {
- if(whitespaceSpecifier = attribs._content.match(/^([<>]{1,2})/)){
- whitespaceSpecifier = whitespaceSpecifier[1];
- if(whitespaceSpecifier.length == 2){
- attribs._content = attribs._content.substr(2)
+ var leader0 = attribs._content.charAt(0),
+ leader1 = attribs._content.charAt(1),
+ leaderLength = 0;
+
+ if(leader0 == "<"){
+ leaderLength++;
+ whitespace.inside = true;
+ if(leader1 == ">"){
+ leaderLength++;
whitespace.around = true;
+ }
+ }else if(leader0 == ">"){
+ leaderLength++;
+ whitespace.around = true;
+ if(leader1 == "<"){
+ leaderLength++;
whitespace.inside = true;
- }else{
- attribs._content = attribs._content.substr(1)
- if(whitespaceSpecifier == ">")
- whitespace.around = true;
- else
- whitespace.inside = true;
}
}
+ attribs._content = attribs._content.substr(leaderLength);
//once we've identified the tag and its attributes, the rest is content.
// this is currently trimmed for neatness.
this.contents.unshift(attribs._content.trim());
@@ -241,7 +247,15 @@ var Haml;
}
if(whitespace.inside){
- content = '" '+content.substr(1, content.length - 2)+' "';
+ if(content.length==0){
+ content='" "'
+ }else{
+ try{ //remove quotes if they are there
+ content = '" '+JSON.parse(content)+' "';
+ }catch(e){
+ content = '" "+\n'+content+'+\n" "';
+ }
+ }
}
if (forceXML ? content.length > 0 : self_close_tags.indexOf(tag) == -1) {
View
@@ -33,4 +33,12 @@
now.
-# empty tag
-%p<>
+%p<>
+
+- id="123456"; locals={name:"hi"}
+
+.item.pending{data-id: id}
+ %input.checkbox(type="checkbox" id="todo-"+id)
+ %label.description(name=("todo-"+id))= (locals.name || "")
+ %span<>= id
+ %a.delete.live{href:"/todo/"+id+"/delete"}> delete
View
@@ -1 +1 @@
-<p>I want my words <a>to have spaces on the outside</a> So they don't run together. But i also want some to have<a> spaces on the inside </a>and still others to have <a> spaces on either side </a> even if it has <a> code </a> on the line <a>or</a> just code with space on the outside</p><p><a>link</a>s that touch their neighbor.</p><p>And <a>links</a> that do not</p><p>Or a <b> important thing </b> with tons of space</p><p>Download the file <a href="/home">here</a> now.</p> <p> </p>
+<p>I want my words <a>to have spaces on the outside</a> So they don't run together. But i also want some to have<a> spaces on the inside </a>and still others to have <a> spaces on either side </a> even if it has <a> code </a> on the line <a>or</a> just code with space on the outside</p><p><a>link</a>s that touch their neighbor.</p><p>And <a>links</a> that do not</p><p>Or a <b> important thing </b> with tons of space</p><p>Download the file <a href="/home">here</a> now.</p> <p> </p> <div data-id="123456" class="item pending"><input type="checkbox" id="todo-123456" class="checkbox" /><label name="todo-123456" class="description">hi</label> <span> 123456 </span> <a href="/todo/123456/delete" class="delete live">delete</a> </div>

0 comments on commit 5c2e226

Please sign in to comment.