0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -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,
isMac,
isGecko,
isIE,
isIE8or9or10,
isIE8,
isOpera,
ctrlKey,
@ -58,7 +58,6 @@
rangeDoesEndAtBlockBoundary,
expandRangeToBlockBoundaries,
Range,
top,
console,
setTimeout
@ -1205,26 +1204,50 @@ var stylesRewriters = {
FONT: function ( node, parent ) {
var face = node.face,
size = node.size,
colour = node.color,
doc = node.ownerDocument,
fontSpan, sizeSpan,
fontSpan, sizeSpan, colourSpan,
newTreeBottom, newTreeTop;
if ( face ) {
fontSpan = createElement( doc, 'SPAN', {
'class': 'font',
style: 'font-family:' + face
});
newTreeTop = fontSpan;
newTreeBottom = fontSpan;
}
if ( size ) {
sizeSpan = createElement( doc, 'SPAN', {
'class': 'size',
style: 'font-size:' + fontSizes[ size ] + 'px'
});
if ( fontSpan ) {
fontSpan.appendChild( sizeSpan );
if ( !newTreeTop ) {
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 );
newTreeBottom.appendChild( empty( node ) );
return newTreeBottom;