GIDForums  

Go Back   GIDForums > Webmaster Forums > Web Design Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-Apr-2006, 19:07
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,628
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Marking source code for a web page


Does anyone know of a way to markup source code when posting on a web page? What I mean is, GIDForums has the special bbcode that marks up C, Java, Python, etc. source code so it's easy to read, just like an IDE. Is there a way to simulate this on a web page?

I've thought about using CSS but I'd still have to manually "tag" each item in the code. Could a server-side script do this? If so, how would the logic work? I don't see how you could put the source code on a page and tell a script to parse it (of course, my programming skills are lacking right now ).

It's not critical that I get something to work. I just thought it would look better than having something that looks like the generic "code" you get from bbcode. I've looked online but haven't found anything.
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
  #2  
Old 17-Apr-2006, 04:59
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

Re: Marking source code for a web page


What I do is use Regular Expressions to find the bbcodes within a post.

So assume a post like this is submitted

Code:
This is my code: [c]// some <cpp> code[/c] Help me!

The first step is to place a marker where the code was found and send the example code to the syntax highlighter class or function.

At this stage, the text posted will look something like this

Code:
This is my code: [cpp_001] Help me!

and the string sent to the CPP syntax highlighter is

Code:
// some <cpp> code

The syntax highlighter will process this string and add the 'colouring' by inserting the appropriate html tags. After processing, it will look like

PHP Code:

$highlighted['cpp_001'] =    '<code class="cpp">' .
                    '<pre>' .
                        '<span class="comment">// some &lt;cpp&gt; code</span>' .
                    '</pre>' .
                '</code>'; 



Just before you display the post on a web page, you run it by htmlspecialchars() and put the markers back... simple?
  #3  
Old 17-Apr-2006, 12:01
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,628
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: Marking source code for a web page


Sounds simple enough. I'll mess around with it and see what I can break.

Thanks for the info.
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
User defined headers davis Miscellaneous Programming Forum 6 16-Feb-2006 19:40
Having a problem Chuckles Computer Hardware Forum 19 13-Sep-2004 13:17
Windows 2000 & NT source code leak Garth Farley Computer Software Forum - Windows 3 26-Feb-2004 16:23
web server in secure mode not connecting to http application tcsasp Apache Web Server Forum 0 06-Nov-2003 01:08

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:59.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.