Skip to content

Commit

Permalink
Fix space before next open span
Browse files Browse the repository at this point in the history
  • Loading branch information
chinedufn committed Mar 6, 2019
1 parent d9cc824 commit e124a87
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
16 changes: 16 additions & 0 deletions crates/html-macro-test/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,19 @@ fn text_tokens_in_between_vars_space_around_between() {
"<div> Hello Space World </div>"
)
}

#[test]
fn text_space_before_next_open_tag() {
assert_eq!(
&html! { <div>Hello <img /> world</div> }.to_string(),
"<div>Hello <img> world</div>"
)
}

#[test]
fn text_no_space_before_open_tag() {
assert_eq!(
&html! { <div>Hello<img /> world</div> }.to_string(),
"<div>Hello<img> world</div>"
)
}
1 change: 1 addition & 0 deletions crates/html-macro/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl HtmlParser {
name,
attrs,
closing_bracket_span,
..
} => {
self.parse_open_tag(name, closing_bracket_span, attrs);
self.last_tag_kind = Some(TagKind::Open);
Expand Down
3 changes: 3 additions & 0 deletions crates/html-macro/src/parser/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ impl HtmlParser {
Some(Tag::Braced { brace_span, .. }) => {
self.separated_by_whitespace(&text_end, brace_span)
}
Some(Tag::Open {
open_bracket_span, ..
}) => self.separated_by_whitespace(&text_end, open_bracket_span),
_ => false,
};
if should_insert_space_after_text {
Expand Down
6 changes: 4 additions & 2 deletions crates/html-macro/src/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum Tag {
Open {
name: Ident,
attrs: Vec<Attr>,
open_bracket_span: Span,
closing_bracket_span: Span,
},
/// </div>
Expand Down Expand Up @@ -87,7 +88,7 @@ impl Parse for Tag {
let is_open_tag = optional_close.is_none();

if is_open_tag {
return parse_open_tag(&mut input);
return parse_open_tag(&mut input, first_angle_bracket_span);
} else {
return parse_close_tag(&mut input, first_angle_bracket_span);
}
Expand All @@ -103,7 +104,7 @@ impl Parse for Tag {
}

/// `<div id="app" class=*CSS>`
fn parse_open_tag(input: &mut ParseStream) -> Result<Tag> {
fn parse_open_tag(input: &mut ParseStream, open_bracket_span: Span) -> Result<Tag> {
let name: Ident = input.parse()?;

let attrs = parse_attributes(input)?;
Expand All @@ -117,6 +118,7 @@ fn parse_open_tag(input: &mut ParseStream) -> Result<Tag> {
Ok(Tag::Open {
name,
attrs,
open_bracket_span,
closing_bracket_span,
})
}
Expand Down

0 comments on commit e124a87

Please sign in to comment.