4 * Pre-transform that changes deprecated hspace and vspace attributes to CSS
6 class HTMLPurifier_AttrTransform_ImgSpace extends HTMLPurifier_AttrTransform
16 protected $css = array(
17 'hspace' => array('left', 'right'),
18 'vspace' => array('top', 'bottom')
24 public function __construct($attr)
27 if (!isset($this->css[$attr])) {
28 trigger_error(htmlspecialchars($attr) . ' is not valid space attribute');
34 * @param HTMLPurifier_Config $config
35 * @param HTMLPurifier_Context $context
38 public function transform($attr, $config, $context)
40 if (!isset($attr[$this->attr])) {
44 $width = $this->confiscateAttr($attr, $this->attr);
45 // some validation could happen here
47 if (!isset($this->css[$this->attr])) {
52 foreach ($this->css[$this->attr] as $suffix) {
53 $property = "margin-$suffix";
54 $style .= "$property:{$width}px;";
56 $this->prependCSS($attr, $style);