-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhighlight.php
More file actions
49 lines (38 loc) · 839 Bytes
/
highlight.php
File metadata and controls
49 lines (38 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
require_once './includes/common.php';
if (empty($argv[1]) || empty($argv[2]))
{
echo "Usage: <XHTML input> <XHTML output>\n";
exit(1);
}
$from = $argv[1];
$to = $argv[2];
if ($to == '-') $to = 'php://stdout';
echo 'Highlighting ', $from, " to $to... ";
class NeutralizeTALES extends PHPTAL_PreFilter
{
function filter($src)
{
return preg_replace_callback('/\$+{/',array('self','escape'), $src);
}
private function escape($m)
{
$m = rtrim($m[0],'{');
return $m.$m.'{';
}
}
$phptal->addPreFilter(new NeutralizeTALES());
try {
$phptal->setTemplate($from);
$r = $phptal->execute();
}
catch (Exception $e){
echo $e;
exit(1);
}
if (!file_put_contents($to, $r))
{
fwrite(STDERR,'Unable to open '.$to.' for writing'."\n");
exit(1);
}
echo "saved\n";