That does work, but it creates some pretty messy html. If you use a pre made javascript library, you just link to it in the <head> then all your <pre> tags automagically adds syntax highlight.
That does work, but it creates some pretty messy html. If you use a pre made javascript library, you just link to it in the <head> then all your <pre> tags automagically adds syntax highlight.
It's only "messy" in the sense that it uses inline style, but that's not as poor a practice as using js to mark-up static content (and I heart javascript).
The thing to look for is something that uses css classes in the mark-up (instead of the inline style), which is tidier, and you can customize it yourself easily if you want:
CSS on that level is as simple as it looks.Code:.synStatement {color: #00ffff} .synIdentifier {color: #88ff88} .synConstant {color: #ffff00} .synPreProc { color: #ff00ff; font-weight:bold; } .synComment { background: #cccccc; color: #151515; font-style:italic; } .synSpecial { color: #ff4444; font-weight:bold;; } .synType {color: #00aa00}
Full property table
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Why? To take syntaxhighlighter as an example you would put it's directory in your root folder, then:
Code:<head> <script type="text/javascript" src="scripts/shCore.js"></script> <script type="text/javascript" src="scripts/shBrushJScript.js"></script> <link type="text/css" rel="stylesheet" href="styles/shCoreDefault.css"/> <script type="text/javascript">SyntaxHighlighter.all();</script> </head> <body> <pre class="brush: js;"> int main( int argc, char **argv ) { printf("Hello World\n"); return 0; } </pre> </body>
A couple of changes to the above:
SyntaxHighlighter seems to be what's used on this site.Code:<head> <script type="text/javascript" src="scripts/shCore.js"></script> <script type="text/javascript" src="scripts/shBrushCpp.js"></script> <link type="text/css" rel="stylesheet" href="styles/shCoreDefault.css"/> <script type="text/javascript">SyntaxHighlighter.all();</script> </head> <body style="background: white; font-family: Helvetica"> <pre class="brush: cpp;"> int main(int argc, char **argv) { printf("Hello World\n"); return 0; } </pre>
Because it has to be executed. I guess that is not a really big deal (people who turn js off are idiots anyway), but I'd call it "abuse" if you use it to do something that is technically not necessary.
OTOH, looking at your example, it is pretty handy in the sense that you can easily edit the code in place, so I won't hold it against you. It would make perfect sense somewhere where the content is being generated dynamically server side (eg, here), which is presumably where it is derived from. But if you are just creating a static page -- I'd go with pregenerated mark-up. Notice that the highlighting here is very slow.
I'll probably make use of that at some point myself, tho, lol. Text::VimColor is too slow for use in real time server side, and if you are doing dynamic content, it's always better to offload the work to the client. Thanks
Last edited by MK27; 03-04-2012 at 10:56 AM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge