Skip to content

Commit ec4873d

Browse files
committed
Unbreak table truncation.
1 parent 30e22ea commit ec4873d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

example.html

+12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ <h2>Example 3: Handling HTML entities</h2>
3939
<div class="example">
4040
<p>&amp;amp; &lt;b&gt;old&lt;/b&gt; foo bar.</p>
4141
</div>
42+
43+
<h2>Example 4: Handling tables</h2>
44+
<div class="example">
45+
<p>Hello!</p>
46+
47+
<table>
48+
<tr><th>Name</th></tr>
49+
<tr><td>Lauren Ipsum</td></tr>
50+
</table>
51+
52+
<p>Goodbye!</p>
53+
</div>
4254

4355
</body>
4456
</html>

jquery.truncator.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@
5454

5555
function truncateNode(node, max_length) {
5656
var node = $(node);
57-
var new_node = node.clone().html("");
57+
var new_node = node.clone().empty();
58+
var truncatedChild;
5859
node.contents().each(function() {
5960
var remaining_length = max_length - new_node.text().length;
6061
if (remaining_length == 0) return;
61-
new_node.append(recursivelyTruncate(this, remaining_length));
62+
truncatedChild = recursivelyTruncate(this, remaining_length);
63+
if (truncatedChild) new_node.append(truncatedChild);
6264
});
6365
return new_node;
6466
}

0 commit comments

Comments
 (0)