3 require_once 'Wiki/Parser.php';
4 require_once 'Wiki/HTMLFormatter.php';
5 require_once 'Wiki/OneLinerFormatter.php';
6 require_once 'Wiki/Item.php';
13 static $macros = array();
14 static $processors = array();
16 static function format_to_html($text) {
17 $f = new MTrack_Wiki_HTMLFormatter;
20 if (false) { /* saveHTML messes with the encoding */
22 @$d = DOMDocument::loadHTML($html);
24 $d->formatOutput = true;
25 $d->substituteEntities = false;
26 $html = $d->saveHTML();
27 $html = preg_replace("/^.*<body>/sm", '', $html);
28 $html = preg_replace(",</body>.*,sm", '', $html);
34 static function format_to_oneliner($text) {
35 $f = new MTrack_Wiki_OneLinerFormatter;
39 static function format_wiki_page($name) {
40 $d = MTrack_Wiki_Item::loadByPageName($name);
42 return self::format_to_html($d->content);
47 static function register_macro($name, $callback) {
48 self::$macros[$name] = $callback;
51 static function register_processor($name, $callback) {
52 self::$processors[$name] = $callback;
55 static function macro_IncludeWiki($pagename) {
56 return self::format_wiki_page($pagename);
58 static function macro_IncludeHelp($pagename) {
59 return self::format_to_html(file_get_contents(
60 dirname(__FILE__) . '/../defaults/help/' . basename($pagename)));
62 static function macro_comment() {
65 static function processor_comment($name, $content) {
68 static function processor_html($name, $content) {
69 return join("\n", $content);
71 static function processor_dataset($name, $content) {
72 $res = '<table class="report wiki dataset">';
73 while (count($content)) {
74 $row = array_shift($content);
75 $next_row = array_shift($content);
76 $cols = preg_split("/\s*\|\s*/", $row);
77 if ($next_row[0] == '-') {
79 $res .= '<thead><tr>';
80 foreach ($cols as $c) {
81 $res .= "<th>" . htmlentities($c, ENT_QUOTES, 'utf-8') . "</th>\n";
83 $res .= "</tr></thead><tbody>";
85 if (is_string($next_row)) {
86 array_unshift($content, $next_row);
90 foreach ($cols as $c) {
91 $res .= "<td>" . htmlentities($c, ENT_QUOTES, 'utf-8') . "</td>\n";
96 $res .= "</tbody></table>\n";