4dbf16ef42ce266e5821be792d9cfce128ebc9b0
[atutor.git] / mods / wiki / plugins / old / markup_code.php
1 <?php
2
3 /*
4   This is another workaround plugin providing <code>...</code> and
5   <php>...</php> escapes for the current rendering kernel.
6 */
7
8
9 $ewiki_plugins["render"][0] = "ewiki_format_pre_code";
10
11
12 function ewiki_format_pre_code($wsrc, $sl=1, $hl=EWIKI_ALLOW_HTML, $sh=0) {
13
14    $html = "";
15
16    $loop = 20;
17    while (preg_match("#^(.*?\n)?<(code>|php>|\?php|\?)(.+?)\n(</code|</php|\?)>#s", $wsrc, $uu) && ($loop--)) {
18
19       $rend = &$uu[1];
20       $code = &$uu[3];
21       $wsrc = substr($wsrc, strlen($uu[0]));
22
23       $html .= ewiki_format($rend,  $sl,$hl,$sh);
24       $html .= "<pre>".
25                ewiki_format_pre_code_escape($code, $uu[2]!="code>") .
26                "\n</pre>";
27
28    }
29
30    if (strlen($wsrc)) {
31       $html .= ewiki_format($wsrc,  $sl,$hl,$sh);
32    }
33
34    return($html);
35 }
36
37 function ewiki_format_pre_code_escape($html, $highl) {
38
39    $html = trim($html, "\n");
40
41    if ($highl) {
42       ob_start();
43       $html = highlight_string($html);
44       $html = ob_get_contents();
45       ob_end_clean();
46    }
47
48    return($html);
49 }
50
51 ?>