Something about everything…

Syntax Highlighter/Code Snippet/Plugin

<?php echo "Syntax Highlighter" . "/Code Snippet/Plugin"; ?> <br />

The one thing that I really needed was for easier editing and writing of my posts and putting source code onto my web-page/blog for viewing only, i.e. the code mustn’t be rendered (translated). Wordpress has one built-in, but it’s a little poor, something is translated, something isn’t and similar. I was looking for some add-on/plugin which would have the capability to highlight/color some parts of code, i.e. code can be easy readable without any “translation“ (for example <br> tag musn’t be rendered as a new line). I have found one interesting add-on called CodeHighlighter and from the beginning it seems quite good (also, it has the advantageous possibility to put line numbers at the left side of the code). But, when PHP code came up which contained HTML code (especially <br> tag) – it wasn’t translated properly, so the code which I didn’t wish to show wasn’t right, because the <br> tag wasn’t there. I tried to configure some files, add <br> tag in Visual layout, but all without any success – stupidly, he has translate it anyway.

Then, I was (again) looking for another plugin and found what I needed, simply named WP-Syntax. It can highlight/colour code, add lines at left side (from any number) and you can choose the code language (full list of supported languages) when you add it. Here is how you add some source code to a post:

Syntax Highlighter/Code Snippet/Plugin

The plugin which I wasn’t so enthusiastic about earlier (CodeHighlighter) and also the now mentioned WP-Syntax are based on GeSHi system which, as I have mentioned, support many avaliable languages.

Here are a few examples how it looks in real (codes are from CodeHighligher web-site).

C++

class nsScannerBufferList
{
public:
/**
  * Buffer objects are directly followed by a data segment. The start
  * of the data segment is determined by increment the |this| pointer
  * by 1 unit.
  */
class Buffer : public PRCList
{
public:
Buffer() {
++index_;
}

PHP (with start-line 5)

5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
for ($i = 0; $i < strlen( $utf8_string ); $i++ ) {
 
$value = ord( $utf8_string[ $i ] );
 
if ( $value &lt; 128 ) {
// ASCII
$unicode .= chr($value);
} else {
if ( count( $values ) == 0 ) {
$num_octets = ( $value < 224 ) ? 2 : 3;
}
$values[] = $value;

Perl (with start-line 1)

1
2
3
4
5
6
my ($class, $mail, $orig) = @_;
my $new_list = $class->_detect($orig) or return;
$new_list->add_to_posts({mail => $mail->id})
    unless Email::Store::List::Post->search( mail => $mail->id,
        list => $new_list->id
    );

CSS

pre {
border: 1px solid #ccc; padding: 0em 0.5em;
 
/* Browser specific (not valid) styles to make preformatted text wrap */
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
#
}
 
.strike {
text-decoration: line-through;
}
  • Google Bookmarks
  • Digg
  • Facebook
  • LinkedIn
  • Twitthis
  • del.icio.us
  • RSS

If you are interested in colon cleanse, you may want to check out this colon cleanse information page which will have all the free information you'll need about colon cleanse.

Leave a comment...


copyright © 2010 svebee | Wordpress | Sitemap