我在 CKeditor 4 中遇到了同样的问题。我搜索了但我没有得到解决方案。但我需要它,所以我在 js 中创建了自己的方法。它工作得很好。
我创建了ownFuntoin:
函数 ConvertFontTagToSpanTag(str) {
var startIndex = str.indexOf('<font');
while (startIndex >= 0) {
var endIndex = str.substring(startIndex).indexOf('>');
var subString1 = str.substring(startIndex, (startIndex + endIndex) + 1);
var subString2 = subString1;
var mapObj = {
size: "font-size:",
face: "font-family:",
color: "color:"
};
subString2 = subString2.replace(/size|face|color/gi, function (matched) {
return mapObj[matched];
});
subString2 = subString2.replace(/['"]/g, ';');
subString2 = subString2.replace(/=;/g, '');
subString2 = subString2.replace('font', 'span');
if (subString2.length > 6) {
subString2 = [subString2.slice(0, 6), 'style=\"', subString2.slice(6)].join('');
subString2 = [subString2.slice(0, subString2.length - 1), '\"', subString2.slice(subString2.length - 1)].join('');
}
//Converting Font-size
var sizeIndex = subString2.indexOf('font-size:');
if (sizeIndex >= 0) {
var sizeEndIndex = subString2.substring(sizeIndex).indexOf(';');
var size = subString2.substring(sizeIndex + 10, (sizeIndex + sizeEndIndex));
//Removing Font size
subString2 = subString2.slice(0, (sizeIndex + sizeEndIndex) - 1) + subString2.slice((sizeIndex + sizeEndIndex));
//Adding Font Size
subString2 = [subString2.slice(0, (sizeIndex + sizeEndIndex)-1), ConvertSpanFontSize(size), subString2.slice((sizeIndex + sizeEndIndex)-1)].join('');
}
//end
str = str.replace(subString1, subString2);
startIndex = str.indexOf('<font');
}
str = str.replace(/font>/g, 'span>');
return str;
}
function ConvertSpanFontSize(size) {
switch (size) {
case '1': return '0.63em';
case '2': return '0.82em';
case '3': return '1.0em';
case '4': return '1.13em';
case '5': return '1.5em';
case '6': return '2em';
case '7': return '3em';
default: return '4em';
}
干杯...!谢谢