fix image text
[pear] / HTML / Clean / FilterStyleToTag.php
1 <?php
2
3
4
5 /**
6  *  replaces styles with HTML
7  *  
8  * 
9  *  
10  *
11  */ 
12
13 require_once 'Filter.php';
14
15 class HTML_Clean_FilterStyleToTag extends HTML_Clean_Filter
16 {
17     
18     var $tag = true;
19     
20     // what we are going to change..
21     var $tags = array(
22         
23         
24         'B'  => array( 'font-weight' => 'bold' ),
25         'I' =>   array(  'font-style'  => 'italic' ),
26         
27         // h1.. h6 ?? font-size?
28         'SUP'  => array(   'vertical-align'  => 'super'),
29         'SUB' => array(   'vertical-align' => 'sub' )
30         
31     );
32     
33     function __construct($cfg)
34     {
35         parent::__construct($cfg);
36         $this->walk($cfg['node']);
37     }
38     
39  
40     
41     
42     
43     function replaceTag($node)
44     {
45         
46         
47         if (!$node->hasAttribute("style")) {
48             return true;
49         }
50         $inject = array();
51         $style = $this->styleToObject($node, true);
52         foreach ($this->tags as $tn => $kv) {
53             list($k,$v) = $kv;
54             if (!isset($style[$k]) || $style[$k] != $v) {
55                 continue;
56             }
57             unset($style[$k]);
58             $inject[] = $tn;
59         }
60         if (!count($inject)) {
61             return true; 
62         }
63         $this->nodeSetStyle($node, $style);
64         $cn = $this->arrayFrom($node->childNodes);
65         $nn = $node;
66         foreach($inject as $t) { 
67         
68             $nc = $node->ownerDocument->createElement($t);
69             $nn->appendChild($nc);
70             $nn = $nc;
71         }
72         foreach($cn as $n) {
73             $node->removeChild($n);
74             $nn->appendChild($n);
75         }
76         
77         return true; /// iterate thru
78     }
79     
80  
81     
82 }