Skip to content

Commit

Permalink
fix(taFixChrome, taFixChrome.spec): corrected a bug introduced when c…
Browse files Browse the repository at this point in the history
…orrecting pasted html (see PR #1411)
  • Loading branch information
JoelParke committed Dec 5, 2016
1 parent 7a23913 commit 35be0a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/factories.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ angular.module('textAngular.factories', [])
/////////////////////////////////////////////////////////////
if (!keepStyles) {
while (match = betterSpanMatch.exec(html)) {
//console.log('matched string:', match[0], 'before:', html.substring(lastIndex, match.index-1));
finalHtml += html.substring(lastIndex, match.index - 1);
lastIndex += match.index;
finalHtml += html.substring(lastIndex, match.index-1);
styleVal = match[0];
lastIndex += match[0].length;
// test for chrome inserted junk
match = /font-family: inherit;|line-height: 1.[0-9]{3,12};|color: inherit; line-height: 1.1;|color: rgb\(\d{1,3}, \d{1,3}, \d{1,3}\);|background-color: rgb\(\d{1,3}, \d{1,3}, \d{1,3}\);/gi.exec(styleVal);
if (match) {
Expand All @@ -93,14 +90,16 @@ angular.module('textAngular.factories', [])
} else {
finalHtml += ' ' + styleVal;
}
lastIndex = betterSpanMatch.lastIndex;
}
finalHtml += html.substring(lastIndex);
}
//console.log('final:', finalHtml);
// only replace when something has changed, else we get focus problems on inserting lists
if(lastIndex > 0){
// replace all empty strings
return finalHtml.replace(/<span\s?>(.*?)<\/span>(<br(\/|)>|)/ig, '$1');
var fe = finalHtml.replace(/<span\s?>(.*?)<\/span>(<br(\/|)>|)/ig, '$1');
return fe;
} else return html;
};
return taFixChrome;
Expand Down
8 changes: 8 additions & 0 deletions test/taFixChrome.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,13 @@ describe('taFixChrome', function(){
it('should keep styles', function(){
expect(taFixChrome('<div><span style="font-family: inherit; line-height: 1.428571429;">Test Content</span></div>', true)).toBe('<div><span style="font-family: inherit; line-height: 1.428571429;">Test Content</span></div>');
});

it('should handle multiple styles', function(){
expect(
taFixChrome('<pre class="command-line" style="text-align: left;"><span class="command">git checkout master</span><span>git fetch upstream</span>git merge upstream/master</pre><pre class="command-line" style="text-align: left;">git push</pre>', false))
.toBe(
'<pre class="command-line" style="text-align: left;"><span class="command">git checkout master</span>git fetch upstreamgit merge upstream/master</pre><pre class="command-line" style="text-align: left;">git push</pre>');
});

});
});

0 comments on commit 35be0a0

Please sign in to comment.