hspace
and vspace
are margins in pixels. The conversion should be direct, immediate and simple.
Where do you want the correction to take place? I don't know anything about CKEditor's source, so that leads me to propose three options.
Option 1: Replace the hspace
and vspace
attributes with proper CSS at submit time. This might impact editability later.
Option 2: Replace the hspace
and vspace
attributes with proper CSS at render time. This might be slow if you do it the right way (HTML parser).
Option 3: Replace the hspace
and vspace
attributes with proper CSS on the client side at render time. This should be trivial in jQuery, Prototype, Mootools, or whatever library you're using.
jQuery to the rescue! Something like this could work.
$('img[hspace]').each(function(el){
var pixels = parseInt($(el).attr('hspace'));
if(isNaN(pixels) || pixels < 1)
pixels = 0;
else
pixels = pixels / 2
$(el).css('marginLeft', pixels + 'px')
.css('marginRight', pixels + 'px')
.removeAttr('hspace');
});
$('img[vspace]').each(function(el){
var pixels = parseInt($(el).attr('vspace'));
if(isNaN(pixels) || pixels < 1)
pixels = 0;
else
pixels = pixels / 2
$(el).css('marginTop', pixels + 'px')
.css('marginBottom', pixels + 'px')
.removeAttr('vspace');
});