Minimalistic Syntax Highlighter plug-in for WordPress which also makes sure code can still be copied and pasted into your favourite compiler!
This plug-in is totally designed for developers.
You know, that sort of people who post code snippets in their blog regularly and hardly use the Visual Editor, because they write the HTML themselves. But they don’t like WordPress messing with their quotes and dashes, so this plug-in makes sure no one touches one of their lovingly crafted lines of code.
It’s also very minimalistic – less than 10k, not counting the GeSHi library which is also included.
In addition, it’s also lazy. It will try to avoid doing as much work as possible. That is good, because it will not eat resources like other plug-ins out there.
Download
You can install SyHi from within your blog plugins admin page. Search for SyHi
! Or you can also download a zip file from the plug-in page at the Plugins directory/
How to use it
Whenever you want to post some syntax highlighted code, surround it with <code lang=”language”></code>. That’s it.
Example:
<code lang="php">
class HelloWorld()
{
public function __construct()
{
echo "This is an unnecessarily long version of Hello World";
}
}
</code>
gets you
class HelloWorld()
{
public function __construct()
{
echo "This is an unnecessarily long version of Hello World";
}
}The ‘lang’ attribute can be entirely omitted. You will get whitespace, quotes and dashes preservation… but no highlighting.
Notes
- php5 and WP2.8+ are required. The plug-in has not been tested with any other configuration.
- Be warned: there isn’t any options page (yet!). The plug-in can simply be activated or deactivated.
- Language files are in libs/geshi/. These are the supported languages: abap, actionscript, actionscript3, ada, apache, applescript, apt sources, asm, asp, autoit, avisynth, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, caddcl, cadlisp, cfdg, cfm, cil, c_mac, cmake, cobol, cpp, cpp-qt, csharp, css, d, dcs, delphi, diff, div, dos, dot, eiffel, email, erlang, fo, fortran, freebasic, genero, gettext, glsl, gml, gnuplot, groovy, haskell, hq9plus, html4strict, idl, ini, inno, intercal, io, java, java5, javascript, kixtart, klonec, klonecpp, latex, lisp, locobasic, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, make, matlab, mirc, modula3, mpasm, mxml, mysql, nsis, oberon2, objc, ocaml, ocaml-brief, oobas, oracle8, oracle11, pascal, per, perl, php, php-brief, pic16, pixelbender, plsql, povray, powershell, progress, prolog, properties, providex, python, qbasic, rails, rebol, reg, robots, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, tcl, teraterm, text, thinbasic, tsql, typoscript, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xml, xorg_conf, xpp, z80. If you need rules for any other language, you’ll need to create them yourself and upload to the libs/geshi folder. You could also contribute them to GeSHi!
Known issues
- You can’t place code blocks inside a code block
- If you switch to the Visual Editor while editing a post, it will mess with any code tags. The results will make you cry.
To do
Add options for…
- … configuring if you want to use my css sheet, your css sheet, both, or no one at all
- … configuring if you want to use GeSHi, or are happy with just plain preformatted text
- … configuring if you want to allow commenters to post syntax highlighted code snippets
[...] I made a new plug-in. It’s very minimalistic, starting with its name: SyHi. [...]
Thank you so much for building this plugin. I’m starting a Flash blog and have been looking for a simple way to input code snippets all night. Of the 4 plugins I installed, this is the only one that actually got the job done.
Thanks again,
Ryan
Thanks for the comments! I really love to hear it’s useful for more people. I’m also a little flattered to hear it’s the only one of 4 which got the job done. Please let me know if you would like to have any extra feature.
Hello,I have used your plugins and love it,I hope the SyHI will be perfect.I will be glade to see when it have the feature of line number. it will be very helpful.
Thanks again!!!
Thanks for the praise. But I don’t know where did you read it’s going to have line numbers… it’s highly unlikely that I will add support for line numbers, I think. This is short code snippets we’re talking about, not full programs.
Still, I’ll have a look and think about that :)