Page 1 of 1

PHP code color parser

Posted: Sat Mar 04, 2006 11:38 am
by amygdela
Hello,

Is there a way to implement this

http://www.sitepoint.com/article/highli ... e-code-php

into CMSMS? I'd love to see that implemented for my PHP related website.

Thanks for any input,

amygdela

Re: PHP code color parser

Posted: Sat Mar 04, 2006 1:19 pm
by Ted
I would make a smarty block function to do this.  It would live in the plugins dir and be called something like block.highlight.php.  Then you should be able to do {highlight}{/highlight}.

The reference to the block function is here: http://smarty.php.net/manual/en/plugins ... ctions.php

Re: PHP code color parser

Posted: Sat Mar 04, 2006 1:48 pm
by amygdela
Wicked, that's a nice start! I'll have a look and see what I can build with it. Thanks

//EDIT

WOW!!!

Wicked!! I never knew writing plugins for smarty was this easy! it works like a charm.

Here it goes:

1. Download the package for the PHP highlighter here
2. Extract the package, and upload init.inc.php to your server in the same folder as your homepage
3. Create a new document, add this to it:

Code: Select all

<?php
include_once 'init.inc.php';
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     block.highlight.php
 * Type:     block
 * Name:     translate
 * Purpose:  translate a block of text
 * -------------------------------------------------------------
 */
function smarty_block_highlight($params, $content, &$smarty)
{
    if (isset($content)) {
         highlight_string($content);
        return $content;
    }
}
?> 
Save it as block.highlight.php in your /plugins folder.

Done! To use this block, use {highlight}{/highlight}

Perfect! ;)

Re: PHP code color parser

Posted: Sat Mar 04, 2006 2:40 pm
by Ted
Nice.  12 minutes total.  That's what I like to hear.  :)

Re: PHP code color parser

Posted: Sat Mar 04, 2006 2:59 pm
by amygdela
hahaha, it is a superfast solution indeed :P

Re: PHP code color parser

Posted: Mon Mar 20, 2006 11:25 pm
by Dee
It would be nice if code highligting would be implemented in the CMS template/stylesheet editor.