XHTMLAndHTML4.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. class HTMLPurifier_HTMLModule_Tidy_XHTMLAndHTML4 extends HTMLPurifier_HTMLModule_Tidy
  3. {
  4. /**
  5. * @return array
  6. */
  7. public function makeFixes()
  8. {
  9. $r = array();
  10. // == deprecated tag transforms ===================================
  11. $r['font'] = new HTMLPurifier_TagTransform_Font();
  12. $r['menu'] = new HTMLPurifier_TagTransform_Simple('ul');
  13. $r['dir'] = new HTMLPurifier_TagTransform_Simple('ul');
  14. $r['center'] = new HTMLPurifier_TagTransform_Simple('div', 'text-align:center;');
  15. $r['u'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:underline;');
  16. $r['s'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:line-through;');
  17. $r['strike'] = new HTMLPurifier_TagTransform_Simple('span', 'text-decoration:line-through;');
  18. // == deprecated attribute transforms =============================
  19. $r['caption@align'] =
  20. new HTMLPurifier_AttrTransform_EnumToCSS(
  21. 'align',
  22. array(
  23. // we're following IE's behavior, not Firefox's, due
  24. // to the fact that no one supports caption-side:right,
  25. // W3C included (with CSS 2.1). This is a slightly
  26. // unreasonable attribute!
  27. 'left' => 'text-align:left;',
  28. 'right' => 'text-align:right;',
  29. 'top' => 'caption-side:top;',
  30. 'bottom' => 'caption-side:bottom;' // not supported by IE
  31. )
  32. );
  33. // @align for img -------------------------------------------------
  34. $r['img@align'] =
  35. new HTMLPurifier_AttrTransform_EnumToCSS(
  36. 'align',
  37. array(
  38. 'left' => 'float:left;',
  39. 'right' => 'float:right;',
  40. 'top' => 'vertical-align:top;',
  41. 'middle' => 'vertical-align:middle;',
  42. 'bottom' => 'vertical-align:baseline;',
  43. )
  44. );
  45. // @align for table -----------------------------------------------
  46. $r['table@align'] =
  47. new HTMLPurifier_AttrTransform_EnumToCSS(
  48. 'align',
  49. array(
  50. 'left' => 'float:left;',
  51. 'center' => 'margin-left:auto;margin-right:auto;',
  52. 'right' => 'float:right;'
  53. )
  54. );
  55. // @align for hr -----------------------------------------------
  56. $r['hr@align'] =
  57. new HTMLPurifier_AttrTransform_EnumToCSS(
  58. 'align',
  59. array(
  60. // we use both text-align and margin because these work
  61. // for different browsers (IE and Firefox, respectively)
  62. // and the melange makes for a pretty cross-compatible
  63. // solution
  64. 'left' => 'margin-left:0;margin-right:auto;text-align:left;',
  65. 'center' => 'margin-left:auto;margin-right:auto;text-align:center;',
  66. 'right' => 'margin-left:auto;margin-right:0;text-align:right;'
  67. )
  68. );
  69. // @align for h1, h2, h3, h4, h5, h6, p, div ----------------------
  70. // {{{
  71. $align_lookup = array();
  72. $align_values = array('left', 'right', 'center', 'justify');
  73. foreach ($align_values as $v) {
  74. $align_lookup[$v] = "text-align:$v;";
  75. }
  76. // }}}
  77. $r['h1@align'] =
  78. $r['h2@align'] =
  79. $r['h3@align'] =
  80. $r['h4@align'] =
  81. $r['h5@align'] =
  82. $r['h6@align'] =
  83. $r['p@align'] =
  84. $r['div@align'] =
  85. new HTMLPurifier_AttrTransform_EnumToCSS('align', $align_lookup);
  86. // @bgcolor for table, tr, td, th ---------------------------------
  87. $r['table@bgcolor'] =
  88. $r['tr@bgcolor'] =
  89. $r['td@bgcolor'] =
  90. $r['th@bgcolor'] =
  91. new HTMLPurifier_AttrTransform_BgColor();
  92. // @border for img ------------------------------------------------
  93. $r['img@border'] = new HTMLPurifier_AttrTransform_Border();
  94. // @clear for br --------------------------------------------------
  95. $r['br@clear'] =
  96. new HTMLPurifier_AttrTransform_EnumToCSS(
  97. 'clear',
  98. array(
  99. 'left' => 'clear:left;',
  100. 'right' => 'clear:right;',
  101. 'all' => 'clear:both;',
  102. 'none' => 'clear:none;',
  103. )
  104. );
  105. // @height for td, th ---------------------------------------------
  106. $r['td@height'] =
  107. $r['th@height'] =
  108. new HTMLPurifier_AttrTransform_Length('height');
  109. // @hspace for img ------------------------------------------------
  110. $r['img@hspace'] = new HTMLPurifier_AttrTransform_ImgSpace('hspace');
  111. // @noshade for hr ------------------------------------------------
  112. // this transformation is not precise but often good enough.
  113. // different browsers use different styles to designate noshade
  114. $r['hr@noshade'] =
  115. new HTMLPurifier_AttrTransform_BoolToCSS(
  116. 'noshade',
  117. 'color:#808080;background-color:#808080;border:0;'
  118. );
  119. // @nowrap for td, th ---------------------------------------------
  120. $r['td@nowrap'] =
  121. $r['th@nowrap'] =
  122. new HTMLPurifier_AttrTransform_BoolToCSS(
  123. 'nowrap',
  124. 'white-space:nowrap;'
  125. );
  126. // @size for hr --------------------------------------------------
  127. $r['hr@size'] = new HTMLPurifier_AttrTransform_Length('size', 'height');
  128. // @type for li, ol, ul -------------------------------------------
  129. // {{{
  130. $ul_types = array(
  131. 'disc' => 'list-style-type:disc;',
  132. 'square' => 'list-style-type:square;',
  133. 'circle' => 'list-style-type:circle;'
  134. );
  135. $ol_types = array(
  136. '1' => 'list-style-type:decimal;',
  137. 'i' => 'list-style-type:lower-roman;',
  138. 'I' => 'list-style-type:upper-roman;',
  139. 'a' => 'list-style-type:lower-alpha;',
  140. 'A' => 'list-style-type:upper-alpha;'
  141. );
  142. $li_types = $ul_types + $ol_types;
  143. // }}}
  144. $r['ul@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $ul_types);
  145. $r['ol@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $ol_types, true);
  146. $r['li@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $li_types, true);
  147. // @vspace for img ------------------------------------------------
  148. $r['img@vspace'] = new HTMLPurifier_AttrTransform_ImgSpace('vspace');
  149. // @width for table, hr, td, th, col ------------------------------------------
  150. $r['table@width'] =
  151. $r['td@width'] =
  152. $r['th@width'] =
  153. $r['col@width'] =
  154. $r['hr@width'] = new HTMLPurifier_AttrTransform_Length('width');
  155. return $r;
  156. }
  157. }
  158. // vim: et sw=4 sts=4