0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 15:23:29 -05:00

Fixup colour attribute in <font> tags.

In the markup cleanup function, extract the "color" attribute from font tags
as well as the size and font-face.
This commit is contained in:
Neil Jenkins 2014-01-28 17:37:31 +11:00
parent 88ced455f9
commit db82ba1217

View file

@ -10,7 +10,7 @@
isIOS, isIOS,
isMac, isMac,
isGecko, isGecko,
isIE, isIE8or9or10,
isIE8, isIE8,
isOpera, isOpera,
ctrlKey, ctrlKey,
@ -58,7 +58,6 @@
rangeDoesEndAtBlockBoundary, rangeDoesEndAtBlockBoundary,
expandRangeToBlockBoundaries, expandRangeToBlockBoundaries,
Range,
top, top,
console, console,
setTimeout setTimeout
@ -1205,26 +1204,50 @@ var stylesRewriters = {
FONT: function ( node, parent ) { FONT: function ( node, parent ) {
var face = node.face, var face = node.face,
size = node.size, size = node.size,
colour = node.color,
doc = node.ownerDocument, doc = node.ownerDocument,
fontSpan, sizeSpan, fontSpan, sizeSpan, colourSpan,
newTreeBottom, newTreeTop; newTreeBottom, newTreeTop;
if ( face ) { if ( face ) {
fontSpan = createElement( doc, 'SPAN', { fontSpan = createElement( doc, 'SPAN', {
'class': 'font', 'class': 'font',
style: 'font-family:' + face style: 'font-family:' + face
}); });
newTreeTop = fontSpan;
newTreeBottom = fontSpan;
} }
if ( size ) { if ( size ) {
sizeSpan = createElement( doc, 'SPAN', { sizeSpan = createElement( doc, 'SPAN', {
'class': 'size', 'class': 'size',
style: 'font-size:' + fontSizes[ size ] + 'px' style: 'font-size:' + fontSizes[ size ] + 'px'
}); });
if ( fontSpan ) { if ( !newTreeTop ) {
fontSpan.appendChild( sizeSpan ); newTreeTop = sizeSpan;
} }
if ( newTreeBottom ) {
newTreeBottom.appendChild( sizeSpan );
}
newTreeBottom = sizeSpan;
}
if ( colour && /^#?([\dA-F]{3}){1,2}$/i.test( colour ) ) {
if ( colour.charAt( 0 ) !== '#' ) {
colour = '#' + colour;
}
colourSpan = createElement( doc, 'SPAN', {
'class': 'colour',
style: 'color:' + colour
});
if ( !newTreeTop ) {
newTreeTop = colourSpan;
}
if ( newTreeBottom ) {
newTreeBottom.appendChild( colourSpan );
}
newTreeBottom = colourSpan;
}
if ( !newTreeTop ) {
newTreeTop = newTreeBottom = createElement( doc, 'SPAN' );
} }
newTreeTop = fontSpan || sizeSpan || createElement( doc, 'SPAN' );
newTreeBottom = sizeSpan || fontSpan || newTreeTop;
parent.replaceChild( newTreeTop, node ); parent.replaceChild( newTreeTop, node );
newTreeBottom.appendChild( empty( node ) ); newTreeBottom.appendChild( empty( node ) );
return newTreeBottom; return newTreeBottom;