[TwigBridge] Prevent code extension to display warning

This commit is contained in:
Grégoire Pineau 2013-08-10 11:31:15 +02:00
parent 36e4b8c1c2
commit e8e76ece5a
2 changed files with 6 additions and 2 deletions

View File

@ -137,7 +137,9 @@ class CodeExtension extends \Twig_Extension
public function fileExcerpt($file, $line)
{
if (is_readable($file)) {
$code = highlight_file($file, true);
// highlight_file could throw warnings
// see https://bugs.php.net/bug.php?id=25725
$code = @highlight_file($file, true);
// remove main code/span tags
$code = preg_replace('#^<code.*?>\s*<span.*?>(.*)</span>\s*</code>#s', '\\1', $code);
$content = preg_split('#<br />#', $code);

View File

@ -131,7 +131,9 @@ class CodeHelper extends Helper
}
}
$code = highlight_file($file, true);
// highlight_file could throw warnings
// see https://bugs.php.net/bug.php?id=25725
$code = @highlight_file($file, true);
// remove main code/span tags
$code = preg_replace('#^<code.*?>\s*<span.*?>(.*)</span>\s*</code>#s', '\\1', $code);
$content = preg_split('#<br />#', $code);