0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2025-02-23 07:15:50 -05:00

Fix escaping first/last line plain text on insertion.

Fixes #157.
This commit is contained in:
Neil Jenkins 2015-11-20 13:55:57 +11:00
parent bf8f796ea4
commit 987f3afd52
3 changed files with 25 additions and 17 deletions

View file

@ -3668,14 +3668,18 @@ proto.insertHTML = function ( html, isPaste ) {
proto.insertPlainText = function ( plainText, isPaste ) {
var lines = plainText.split( '\n' ),
i, l;
for ( i = 1, l = lines.length - 1; i < l; i += 1 ) {
lines[i] = '<DIV>' +
lines[i].split( '&' ).join( '&amp;' )
i, l, line;
for ( i = 0, l = lines.length; i < l; i += 1 ) {
line = lines[i];
line = line.split( '&' ).join( '&amp;' )
.split( '<' ).join( '&lt;' )
.split( '>' ).join( '&gt;' )
.replace( / (?= )/g, '&nbsp;' ) +
'</DIV>';
.replace( / (?= )/g, '&nbsp;' );
// Wrap all but first/last lines in <div></div>
if ( i && i + 1 < l ) {
line = '<DIV>' + ( line || '<BR>' ) + '</DIV>';
}
lines[i] = line;
}
return this.insertHTML( lines.join( '' ), isPaste );
};

File diff suppressed because one or more lines are too long

View file

@ -1536,14 +1536,18 @@ proto.insertHTML = function ( html, isPaste ) {
proto.insertPlainText = function ( plainText, isPaste ) {
var lines = plainText.split( '\n' ),
i, l;
for ( i = 1, l = lines.length - 1; i < l; i += 1 ) {
lines[i] = '<DIV>' +
lines[i].split( '&' ).join( '&amp;' )
i, l, line;
for ( i = 0, l = lines.length; i < l; i += 1 ) {
line = lines[i];
line = line.split( '&' ).join( '&amp;' )
.split( '<' ).join( '&lt;' )
.split( '>' ).join( '&gt;' )
.replace( / (?= )/g, '&nbsp;' ) +
'</DIV>';
.replace( / (?= )/g, '&nbsp;' );
// Wrap all but first/last lines in <div></div>
if ( i && i + 1 < l ) {
line = '<DIV>' + ( line || '<BR>' ) + '</DIV>';
}
lines[i] = line;
}
return this.insertHTML( lines.join( '' ), isPaste );
};