WP-GeSHi-Highlight Demo

WP-GeSHi-Highlight Demonstration

A WordPress plugin for syntax highlighting

Plugin documentation: https://gehrcke.de/wp-geshi-highlight
Plugin @ wordpress.org: https://wordpress.org/plugins/wp-geshi-highlight

Examples

For each example, I have included the applied options. For example, lang="javascript" means that I have actually written:

<pre lang="javascript">
    ... code ...
</pre>

Python
lang="python"

self._validate()
with self._lock:
    if timeout:
        # Wait for ready-to-read event.
        h = gevent.get_hub()
        h.wait(h.loop.io(self._fd, 1))
        timeout.cancel()
    msize, = struct.unpack("!i", self._recv_in_buffer(4).getvalue())
    bindata = self._recv_in_buffer(msize).getvalue()
return self._decoder(bindata)

PHP
lang="php"

function wp_geshi_filter_and_replace_code_snippets() {
    global $wp_query;
    global $wp_geshi_comments;
    // Iterate over all posts in this query.
    foreach ($wp_query->posts as $post) {
        // Extract code snippets from the content. Replace them.
        $post->post_content = wp_geshi_filter_replace_code($post->post_content);
        // Iterate over all approved comments belonging to this post.
        // Store comments with uuid (code replacement) in `$wp_geshi_comments`.
        $comments = get_approved_comments($post->ID);
        foreach ($comments as $comment) {
            $wp_geshi_comments[$comment->comment_ID] =
                wp_geshi_filter_replace_code($comment->comment_content);
            }
        }
    }

JavaScript
lang="javascript"

function base64_to_uint8array(s) {
  var byteChars = atob(s);
  var l = byteChars.length;
  var byteNumbers = new Array(l);
  for (var i = 0; i < l; i++) {
    byteNumbers[i] = byteChars.charCodeAt(i);
  }
  return new Uint8Array(byteNumbers);
}

Python, with line numbering
lang="python" line="1"

  1. seen = set()
  2. for line in stdin:
  3.     timestamp, name, mail = line.strip().split(";")
  4.     if name not in seen:
  5.         seen.add(name)
  6.         day = time.strftime("%Y-%m-%d", time.gmtime(float(timestamp)))
  7.         stdout.write("%04d (%s): %s (%s)\n" % (len(seen), day, name, mail))

Just text
lang="text"

0001 (1990-08-09): Guido van Rossum (guido@python.org)
0002 (1992-08-04): Sjoerd Mullender (sjoerd@acm.org)
0003 (1992-08-13): Jack Jansen (jack.jansen@cwi.nl)
0004 (1993-01-10): cvs2svn (tools@python.org)
0005 (1994-07-25): Barry Warsaw (barry@python.org)
0006 (1996-07-23): Fred Drake (fdrake@acm.org)
0007 (1996-12-09): Roger E. Masse (rmasse@newcnri.cnri.reston.va.us)
0008 (1997-08-13): Jeremy Hylton (jeremy@alum.mit.edu)

Bash, without block style (w/o including wp-geshi-highlight.css)
lang="bash" cssfile="none"

TMPFILE="$(mktemp --tmpdir=${TMPDIR} response.html.XXXX)"
echo "GET ${CURRENTURL} (use auth cookie), store response."
wget --no-verbose --load-cookies=${COOKIESFILE} \
    --output-document ${TMPFILE} ${CURRENTURL}

HTML, without decoding HTML entities
lang="html4strict"

&lt;pre&gt;
    This is almost the way to have pre blocks in your code snippets :-).
&lt;/pre&gt;

HTML, like above, but with decoding HTML entities
lang="html4strict" escaped="true"

<pre>
    This is *exactly* the way to have pre blocks included in your snippet :-).
</pre>

PHP with angled brackets (no HTML entity representation required in the input)
lang="php"

<?php
    $this->load('Articles');
?>