Reply to topic
How to program a Code Blocks filter
whitesites


Joined: 05 Jul 2004
Posts: 174
Location: Houston, TX
Reply with quote
I am developing my own blog engine, and one of the features I need is a Code Blocks filter, so I can paste HTML c#, PHP, and other codes onto the page. Any suggestions for how I program a filter that does this? How does the HMS code block work?
shmoo


Joined: 05 Oct 2005
Posts: 9
Reply with quote
I'm not the greatest programmer in the world, but it's my understanding that most (if not all) languages already come with components/classes/whatever that will do this for you...... so you probably won't have to code a filter from scratch.

Another easy solution would be to just scan the users' input for bracket characters (square, parenthesis, angled, curly)... removing them should render any code useless. (Feel free to prove me wrong though... I'm still learning this stuff).
Sample Code
comprug
Forum Regular

Joined: 15 Feb 2006
Posts: 340
Reply with quote
If you are looking to provide sample code, I would reccomend replacing < and > with %lt; and &gt;. You can then replace (for example) [phpcode] and [/phpcode] with <div class="php"> and </div>. A utility such as Chili will help code highlighting.

Chili: http://noteslog.com/personal/projects/chili/1.8c/

Thanks
nathacof


Joined: 24 Oct 2006
Posts: 93
Location: Bear, DE
Reply with quote
If you're using PHP try this one on for size:

http://pear.php.net/package/Text_Highlighter

I was thinking of doing the same thing, but problems arise (especially with php) where you might have perfectly valid HTML inside of your code, which is then rendered anywhere you print out that code.

I'm hoping this Pear package is going to alleviate some of those headaches.
How to program a Code Blocks filter
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
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic