4 You can use the ordinary html <table>, <tr> and <td> tags in all wiki
5 pages, if you activate this plugin. Standard attributes are allowed
6 (bgcolor, width, class, style, align, ...). It provides only limited
7 tag correction support, but you can often leave out </tr> and </td>:
18 $ewiki_plugins["format_block"]["htmltable"][] = "ewiki_markup_fblock_htmltable";
19 $ewiki_config["format_block"]["htmltable"] = array("<table", "</table>", false, 0x0027);
22 function ewiki_markup_fblock_htmltable(&$c, &$in, &$ooo, &$s) {
24 if (($p = strpos($c, ">")) !== false) {
27 // clean <table> start and </table> end tag
28 $c = "<table " . ewiki_markup_htmltable_attrs(substr($c, 0, $p))
29 . ">" . substr($c, $p + 4) . "</table>";
31 // clean <td> and <tr> tags
32 $c = preg_replace('#<(/?td|/?tr)(.*?)>#e',
33 '"<\\1" . ewiki_markup_htmltable_attrs("\\2") . ">"', $c);
35 // insert missing </tr> and </td>
36 $c = preg_replace('#(?<!</t[dr]>)\s*<(t[dr])#', '</\\1><\\1', $c);
38 // add last closing </td> and </tr> tags
39 $c = preg_replace('#(?<!</tr>)(\s*</table>)#', '</tr>\\1', $c);
40 $c = preg_replace('#(?<!</td>)(\s*</tr>\s*</table>)#', '</td>\\1', $c);
42 // remove redundant closing tags
43 $c = preg_replace('#(<table[^>]+?>\s*)\s*(</t[dr]>)#', '\\1', $c);
44 $c = preg_replace('#(</?tr>\s*)(\s*</t[dr]>)+#', '\\1', $c);
45 $c = preg_replace('#(</td>\s*)(\s*</td>)*#', '\\1', $c);
50 function ewiki_markup_htmltable_attrs($str) {
51 if (preg_match_all('/(\s+(class|style|width|height|align|bgcolor|valign|border|colspan|rowspan|cellspacing|cellpadding)=(\w+|"[^"]+"))/', $str, $uu)) {
52 $str = implode("", $uu[1]);