Skip to content

Commit

Permalink
just append the wrapped element
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 4, 2014
1 parent f23d503 commit 401f11c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/Mojo/DOM.pm
Expand Up @@ -212,7 +212,7 @@ sub wrap {

# Wrap element
$self->_replace($tree, $new);
splice @$current, _start($current), 0, _link(['root', $tree], $current);
push @$current, _link(['root', $tree], $current);

return $self;
}
Expand Down Expand Up @@ -816,12 +816,15 @@ This element's type.
Wrap HTML/XML fragment around this element.
# "<div><h1>A</h1>B</div>"
# "<div>B<h1>A</h1></div>"
$dom->parse('<h1>A</h1>')->at('h1')->wrap('<div>B</div>')->root;
# "<div><div><h1>A</h1></div>B</div>"
$dom->parse('<h1>A</h1>')->at('h1')->wrap('<div><div></div>B</div>')->root;
# "<div><h1>A</h1></div><div>B</div>"
$dom->parse('<h1>A</h1>')->at('h1')->wrap('<div></div><div>B</div>')->root;
=head2 xml
my $bool = $dom->xml;
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/dom.t
Expand Up @@ -2019,7 +2019,7 @@ is $dom->at('a')->wrap('<b></b>')->type, 'a', 'right element';
is "$dom", '<b><a>Test</a></b>', 'right result';
is $dom->at('a')->wrap('C<c><d>D</d><e>E</e></c>F')->parent->type, 'd',
'right element';
is "$dom", '<b>C<c><d><a>Test</a>D</d><e>E</e></c>F</b>', 'right result';
is "$dom", '<b>C<c><d>D<a>Test</a></d><e>E</e></c>F</b>', 'right result';

# Broken "div" in "td"
$dom = Mojo::DOM->new(<<EOF);
Expand Down

0 comments on commit 401f11c

Please sign in to comment.