Release 2.1.3, merged in 1404 to HEAD.
[htmlpurifier/bfroehle.git] / library / HTMLPurifier / HTMLModule / Tidy / XHTMLAndHTML4.php
blobdcf306a0197a0c1214d74306e664432749ea771c
1 <?php
3 require_once 'HTMLPurifier/HTMLModule/Tidy.php';
5 require_once 'HTMLPurifier/TagTransform/Simple.php';
6 require_once 'HTMLPurifier/TagTransform/Font.php';
8 require_once 'HTMLPurifier/AttrTransform/BgColor.php';
9 require_once 'HTMLPurifier/AttrTransform/BoolToCSS.php';
10 require_once 'HTMLPurifier/AttrTransform/Border.php';
11 require_once 'HTMLPurifier/AttrTransform/Name.php';
12 require_once 'HTMLPurifier/AttrTransform/Length.php';
13 require_once 'HTMLPurifier/AttrTransform/ImgSpace.php';
14 require_once 'HTMLPurifier/AttrTransform/EnumToCSS.php';
16 require_once 'HTMLPurifier/ChildDef/StrictBlockquote.php';
18 class HTMLPurifier_HTMLModule_Tidy_XHTMLAndHTML4 extends
19 HTMLPurifier_HTMLModule_Tidy
22 function makeFixes() {
24 $r = array();
26 // == deprecated tag transforms ===================================
28 $r['font'] = new HTMLPurifier_TagTransform_Font();
29 $r['menu'] = new HTMLPurifier_TagTransform_Simple('ul');
30 $r['dir'] = new HTMLPurifier_TagTransform_Simple('ul');
31 $r['center'] = new HTMLPurifier_TagTransform_Simple('div', 'text-align:center;');
32 $r['u'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:underline;');
33 $r['s'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:line-through;');
34 $r['strike'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:line-through;');
36 // == deprecated attribute transforms =============================
38 $r['caption@align'] =
39 new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
40 // we're following IE's behavior, not Firefox's, due
41 // to the fact that no one supports caption-side:right,
42 // W3C included (with CSS 2.1). This is a slightly
43 // unreasonable attribute!
44 'left' => 'text-align:left;',
45 'right' => 'text-align:right;',
46 'top' => 'caption-side:top;',
47 'bottom' => 'caption-side:bottom;' // not supported by IE
48 ));
50 // @align for img -------------------------------------------------
51 $r['img@align'] =
52 new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
53 'left' => 'float:left;',
54 'right' => 'float:right;',
55 'top' => 'vertical-align:top;',
56 'middle' => 'vertical-align:middle;',
57 'bottom' => 'vertical-align:baseline;',
58 ));
60 // @align for table -----------------------------------------------
61 $r['table@align'] =
62 new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
63 'left' => 'float:left;',
64 'center' => 'margin-left:auto;margin-right:auto;',
65 'right' => 'float:right;'
66 ));
68 // @align for hr -----------------------------------------------
69 $r['hr@align'] =
70 new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
71 // we use both text-align and margin because these work
72 // for different browsers (IE and Firefox, respectively)
73 // and the melange makes for a pretty cross-compatible
74 // solution
75 'left' => 'margin-left:0;margin-right:auto;text-align:left;',
76 'center' => 'margin-left:auto;margin-right:auto;text-align:center;',
77 'right' => 'margin-left:auto;margin-right:0;text-align:right;'
78 ));
80 // @align for h1, h2, h3, h4, h5, h6, p, div ----------------------
81 // {{{
82 $align_lookup = array();
83 $align_values = array('left', 'right', 'center', 'justify');
84 foreach ($align_values as $v) $align_lookup[$v] = "text-align:$v;";
85 // }}}
86 $r['h1@align'] =
87 $r['h2@align'] =
88 $r['h3@align'] =
89 $r['h4@align'] =
90 $r['h5@align'] =
91 $r['h6@align'] =
92 $r['p@align'] =
93 $r['div@align'] =
94 new HTMLPurifier_AttrTransform_EnumToCSS('align', $align_lookup);
96 // @bgcolor for table, tr, td, th ---------------------------------
97 $r['table@bgcolor'] =
98 $r['td@bgcolor'] =
99 $r['th@bgcolor'] =
100 new HTMLPurifier_AttrTransform_BgColor();
102 // @border for img ------------------------------------------------
103 $r['img@border'] = new HTMLPurifier_AttrTransform_Border();
105 // @clear for br --------------------------------------------------
106 $r['br@clear'] =
107 new HTMLPurifier_AttrTransform_EnumToCSS('clear', array(
108 'left' => 'clear:left;',
109 'right' => 'clear:right;',
110 'all' => 'clear:both;',
111 'none' => 'clear:none;',
114 // @height for td, th ---------------------------------------------
115 $r['td@height'] =
116 $r['th@height'] =
117 new HTMLPurifier_AttrTransform_Length('height');
119 // @hspace for img ------------------------------------------------
120 $r['img@hspace'] = new HTMLPurifier_AttrTransform_ImgSpace('hspace');
122 // @name for img, a -----------------------------------------------
123 $r['img@name'] =
124 $r['a@name'] = new HTMLPurifier_AttrTransform_Name();
126 // @noshade for hr ------------------------------------------------
127 // this transformation is not precise but often good enough.
128 // different browsers use different styles to designate noshade
129 $r['hr@noshade'] =
130 new HTMLPurifier_AttrTransform_BoolToCSS(
131 'noshade',
132 'color:#808080;background-color:#808080;border:0;'
135 // @nowrap for td, th ---------------------------------------------
136 $r['td@nowrap'] =
137 $r['th@nowrap'] =
138 new HTMLPurifier_AttrTransform_BoolToCSS(
139 'nowrap',
140 'white-space:nowrap;'
143 // @size for hr --------------------------------------------------
144 $r['hr@size'] = new HTMLPurifier_AttrTransform_Length('size', 'height');
146 // @type for li, ol, ul -------------------------------------------
147 // {{{
148 $ul_types = array(
149 'disc' => 'list-style-type:disc;',
150 'square' => 'list-style-type:square;',
151 'circle' => 'list-style-type:circle;'
153 $ol_types = array(
154 '1' => 'list-style-type:decimal;',
155 'i' => 'list-style-type:lower-roman;',
156 'I' => 'list-style-type:upper-roman;',
157 'a' => 'list-style-type:lower-alpha;',
158 'A' => 'list-style-type:upper-alpha;'
160 $li_types = $ul_types + $ol_types;
161 // }}}
163 $r['ul@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $ul_types);
164 $r['ol@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $ol_types, true);
165 $r['li@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $li_types, true);
167 // @vspace for img ------------------------------------------------
168 $r['img@vspace'] = new HTMLPurifier_AttrTransform_ImgSpace('vspace');
170 // @width for hr, td, th ------------------------------------------
171 $r['td@width'] =
172 $r['th@width'] =
173 $r['hr@width'] = new HTMLPurifier_AttrTransform_Length('width');
175 return $r;
181 class HTMLPurifier_HTMLModule_Tidy_Transitional extends
182 HTMLPurifier_HTMLModule_Tidy_XHTMLAndHTML4
184 var $name = 'Tidy_Transitional';
185 var $defaultLevel = 'heavy';
188 class HTMLPurifier_HTMLModule_Tidy_Strict extends
189 HTMLPurifier_HTMLModule_Tidy_XHTMLAndHTML4
191 var $name = 'Tidy_Strict';
192 var $defaultLevel = 'light';
194 function makeFixes() {
195 $r = parent::makeFixes();
196 $r['blockquote#content_model_type'] = 'strictblockquote';
197 return $r;
200 var $defines_child_def = true;
201 function getChildDef($def) {
202 if ($def->content_model_type != 'strictblockquote') return parent::getChildDef($def);
203 return new HTMLPurifier_ChildDef_StrictBlockquote($def->content_model);