Permalink
Browse files

Preserving html line breaks

  • Loading branch information...
jeremyharris committed Feb 27, 2018
1 parent 55a290e commit 950c23355d3d0953766381531045a3f1b70c0a8b
Showing with 16 additions and 0 deletions.
  1. +9 −0 demos.html
  2. +7 −0 jquery.splitlines.js
View
@@ -87,6 +87,7 @@
$('#example-6').splitLines();
$('#example-7').splitLines({tag:'<span>',width: 120});
$('#example-8').splitLines({width: 10});
$('#example-9').splitLines({width: 150});
$('#example-6').css('height', 24).children().css({
position: 'absolute',
@@ -186,6 +187,14 @@ <h1>jQuery <span class="code">splitLines()</span> demos</h1>
Long words will not fit into small widths!
</div>
</div>
<div>
<p>A test for preserving <code>&lt;br&gt;</code> tags.</p>
<div id="example-9" class="example">
Broken up <br/> with html line <br> breaks but still with split lines.
How about <span>words in tags<br/> with brs!</span>
</div>
</div>
</div>
</div>
</body>
View
@@ -35,6 +35,10 @@
var words = [];
var splitContent;
for (var c=0; c<contents.length; c++) {
if (contents[c].nodeName === 'BR') {
words.push('<br>');
continue;
}
if (contents[c].nodeType == 3) {
splitContent = _splitWords(contents[c].textContent || contents[c].toString());
} else {
@@ -46,6 +50,9 @@
}
}
for (var w=0; w<splitContent.length; w++) {
if (splitContent[w] === '') {
continue;
}
words.push(splitContent[w]);
}
}

0 comments on commit 950c233

Please sign in to comment.