Jump to content

Syntax high lighting


SyncViews

Recommended Posts

How do I get php to add html tags to highlight code?

 

Some of them (like == or <=) I can just do by replaceing say '==' with '<span class="comparison">==</span>' But what of strings, varibles, reals etc?

 

eg

if (height >= 125 || width >= 125)
{
    tobig = 1;
    show_message('Item is to big');
}

need to go to:

<span class="conditional">if</span> (<span class="var">height</span> <span class="comparison"><=</span> <span class="real">125</span> <span class="logical">||</span> <span class="var">width</span> <span class="comparison">>=</span> <span class="real">125</span>)
{
    <span class="var">tobig</span> <span class="assignment">=</span> <span class="real">1</span>;
    <span class="function">show_message</span>('<span class="string">Item is to big</span>');
}

Link to comment
Share on other sites

As I only really want something to prase one thing useing one style (useing existing css files) there must be a better way without all the bulk GeShi adds...

 

Basicly I need it to do serval passes adding tags arcording to some basic rules eg (could merge some of these but it's easyer to understand this way I think)

 

1st pass:

add comment tags to all "/* .... */" blocks

 

2nd pass:

add comment tags from "//" to the end of the line while igornaing existing comment blocks

 

3rd pass onwards - skip all code within comment blocks:

add string tage to all "..." and '...' blocks

 

4th pass onwards - skip all comments and string blocks:

replace certain items (eg "if", "else", "=", "+") with versions includeing tags

 

5th pass:

add real tags to all numbers

 

6th pass:

add tags to all functions (mayby by detecting the string(...)?)

 

7th pass:

add constant tags to all predefined constants (these constants could be stored in an array)

 

8th pass:

All remaining strings outside tags are given varible tags

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.