0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2025-03-23 04:51:22 -05:00

Use default block config when inserting plain text

This commit is contained in:
Neil Jenkins 2016-05-25 12:41:57 +10:00
parent 4e7e290fbc
commit aa3857ab77
3 changed files with 50 additions and 16 deletions

View file

@ -3868,18 +3868,35 @@ proto.insertHTML = function ( html, isPaste ) {
return this;
};
var escapeHTMLFragement = function ( text ) {
return text.split( '&' ).join( '&' )
.split( '<' ).join( '&lt;' )
.split( '>' ).join( '&gt;' )
.split( '"' ).join( '&quot;' );
};
proto.insertPlainText = function ( plainText, isPaste ) {
var lines = plainText.split( '\n' ),
i, l, line;
var lines = plainText.split( '\n' );
var config = this._config;
var tag = config.blockTag;
var attributes = config.blockAttributes;
var closeBlock = '</' + tag + '>';
var openBlock = '<' + tag;
var attr, i, l, line;
for ( attr in attributes ) {
openBlock += ' ' + attr + '="' +
escapeHTMLFragement( attributes[ attr ] ) +
'"';
}
openBlock += '>';
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;' );
line = escapeHTMLFragement( line ).replace( / (?= )/g, '&nbsp;' );
// Wrap all but first/last lines in <div></div>
if ( i && i + 1 < l ) {
line = '<DIV>' + ( line || '<BR>' ) + '</DIV>';
line = openBlock + ( line || '<BR>' ) + closeBlock;
}
lines[i] = line;
}

File diff suppressed because one or more lines are too long

View file

@ -1650,18 +1650,35 @@ proto.insertHTML = function ( html, isPaste ) {
return this;
};
var escapeHTMLFragement = function ( text ) {
return text.split( '&' ).join( '&amp;' )
.split( '<' ).join( '&lt;' )
.split( '>' ).join( '&gt;' )
.split( '"' ).join( '&quot;' );
};
proto.insertPlainText = function ( plainText, isPaste ) {
var lines = plainText.split( '\n' ),
i, l, line;
var lines = plainText.split( '\n' );
var config = this._config;
var tag = config.blockTag;
var attributes = config.blockAttributes;
var closeBlock = '</' + tag + '>';
var openBlock = '<' + tag;
var attr, i, l, line;
for ( attr in attributes ) {
openBlock += ' ' + attr + '="' +
escapeHTMLFragement( attributes[ attr ] ) +
'"';
}
openBlock += '>';
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;' );
line = escapeHTMLFragement( line ).replace( / (?= )/g, '&nbsp;' );
// Wrap all but first/last lines in <div></div>
if ( i && i + 1 < l ) {
line = '<DIV>' + ( line || '<BR>' ) + '</DIV>';
line = openBlock + ( line || '<BR>' ) + closeBlock;
}
lines[i] = line;
}