Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

180 lines
6.9KB

  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['td@bgcolor'] =
  89. $r['th@bgcolor'] =
  90. new HTMLPurifier_AttrTransform_BgColor();
  91. // @border for img ------------------------------------------------
  92. $r['img@border'] = new HTMLPurifier_AttrTransform_Border();
  93. // @clear for br --------------------------------------------------
  94. $r['br@clear'] =
  95. new HTMLPurifier_AttrTransform_EnumToCSS(
  96. 'clear',
  97. array(
  98. 'left' => 'clear:left;',
  99. 'right' => 'clear:right;',
  100. 'all' => 'clear:both;',
  101. 'none' => 'clear:none;',
  102. )
  103. );
  104. // @height for td, th ---------------------------------------------
  105. $r['td@height'] =
  106. $r['th@height'] =
  107. new HTMLPurifier_AttrTransform_Length('height');
  108. // @hspace for img ------------------------------------------------
  109. $r['img@hspace'] = new HTMLPurifier_AttrTransform_ImgSpace('hspace');
  110. // @noshade for hr ------------------------------------------------
  111. // this transformation is not precise but often good enough.
  112. // different browsers use different styles to designate noshade
  113. $r['hr@noshade'] =
  114. new HTMLPurifier_AttrTransform_BoolToCSS(
  115. 'noshade',
  116. 'color:#808080;background-color:#808080;border:0;'
  117. );
  118. // @nowrap for td, th ---------------------------------------------
  119. $r['td@nowrap'] =
  120. $r['th@nowrap'] =
  121. new HTMLPurifier_AttrTransform_BoolToCSS(
  122. 'nowrap',
  123. 'white-space:nowrap;'
  124. );
  125. // @size for hr --------------------------------------------------
  126. $r['hr@size'] = new HTMLPurifier_AttrTransform_Length('size', 'height');
  127. // @type for li, ol, ul -------------------------------------------
  128. // {{{
  129. $ul_types = array(
  130. 'disc' => 'list-style-type:disc;',
  131. 'square' => 'list-style-type:square;',
  132. 'circle' => 'list-style-type:circle;'
  133. );
  134. $ol_types = array(
  135. '1' => 'list-style-type:decimal;',
  136. 'i' => 'list-style-type:lower-roman;',
  137. 'I' => 'list-style-type:upper-roman;',
  138. 'a' => 'list-style-type:lower-alpha;',
  139. 'A' => 'list-style-type:upper-alpha;'
  140. );
  141. $li_types = $ul_types + $ol_types;
  142. // }}}
  143. $r['ul@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $ul_types);
  144. $r['ol@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $ol_types, true);
  145. $r['li@type'] = new HTMLPurifier_AttrTransform_EnumToCSS('type', $li_types, true);
  146. // @vspace for img ------------------------------------------------
  147. $r['img@vspace'] = new HTMLPurifier_AttrTransform_ImgSpace('vspace');
  148. // @width for hr, td, th ------------------------------------------
  149. $r['td@width'] =
  150. $r['th@width'] =
  151. $r['hr@width'] = new HTMLPurifier_AttrTransform_Length('width');
  152. return $r;
  153. }
  154. }
  155. // vim: et sw=4 sts=4