PHP code color parser

Talk about new features for CMSMS and modules.
Post Reply
amygdela

PHP code color parser

Post 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
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

Re: PHP code color parser

Post 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
amygdela

Re: PHP code color parser

Post 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! ;)
Last edited by amygdela on Sat Mar 04, 2006 2:00 pm, edited 1 time in total.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

Re: PHP code color parser

Post by Ted »

Nice.  12 minutes total.  That's what I like to hear.  :)
amygdela

Re: PHP code color parser

Post by amygdela »

hahaha, it is a superfast solution indeed :P
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm

Re: PHP code color parser

Post by Dee »

It would be nice if code highligting would be implemented in the CMS template/stylesheet editor.
Post Reply

Return to “Feature ideas”