Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

block.phphighlight.php

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
tsigo
Smarty Rookie


Joined: 14 Jun 2003
Posts: 7

PostPosted: Tue Jul 08, 2003 8:49 pm    Post subject: block.phphighlight.php Reply with quote

I'm writing a developer manual for a project and I wanted an easy way to highlight PHP code, so I came up with this simple plugin. I didn't see one already made, so here it is if someone also needs it.

[php:1:1df96c33d8]<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: block.phphighlight.php
* Type: block function
* Name: phphighlight
* Version: 1.0
* Date: July 8, 2003
* Purpose: Syntax highlighting for PHP code
* Example:
* {phphighlight}
* {literal}
* $var = "test";
* echo $var . '<br />';
* {/literal}
* {/phphighlight}
* Install: Just drop into the plugin directory.
* Author: Rob Speicher <tsigo@eqdkp.com>
* -------------------------------------------------------------
*/
function smarty_block_phphighlight($params, $content, &$this)
{
$content = trim($content);
if ($content != "")
{
if ( !preg_match('#^<\?php#', $content) )
{
$content = '<?php' . "\n" . $content;
}

if ( !preg_match('#\?>$#', $content) )
{
$content = $content . "\n" . '?>';
}

ob_start();
highlight_string($content);
$content = ob_get_contents();
ob_end_clean();

return preg_replace('#^<\?php(.*)\?>$#', '\1', $content);
}
}
?>[/php:1:1df96c33d8]

Note: If you set your left and right delimiters to something other than '{' and '}' then you can get away without using the '{literal}' tags.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP