XHTMLAndHTML4.php 6.6 KB

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