[]RSS

About Archives Artwork Comic Contact Philosophy Projects Tags

Syntax highlighting for WordPress

[Comment]

December 19th, 2007 in Micro Blog

I finally got around to adding syntax highlighting to the site today, a feature I’ve been meaning to add for several months now. I decided to use the Google code prettify script, via a handy-dandy Wordpress plugin.1

To make it easier to post prettified things, I also hacked the plugin so it automatically adds a prettyprint class to indented pre/code and backtick2 blocks:

function _doCodeBlocks_callback($matches) {
    $codeblock = $matches[1];

    $codeblock = $this->encodeCode($this->outdent($codeblock));
    $codeblock = $this->detab($codeblock);
    # trim leading newlines and trailing whitespace
    $codeblock = preg_replace(array('/\A\n+/', '/\n+\z/'), '', $codeblock);

    $result = "\n\n".$this->hashBlock("<pre><code class='prettyprint'>" 
            . $codeblock . "\n</code></pre>")."\n\n";

    return $result;
}

While I was at it, I fixed an old bug in my SimpleLink plugin too, as it was munging array syntax like $a[9] in pre blocks. Some day I’ll rewrite the plugin as a full parser, merging it with Markdown (and RestructuredText).3 But not today.

  1. While I don’t strictly need the plugin (adding it to the template header would be enough), it may be a handy way to hook it into my RSS feed in the future
  2. The backtick hack is similar to the indented pre/code here
  3. Markdown has a similar set of parsing bugs, as it hacks parsing the posts too

SimpleLink .5 Features

[Comment]

June 11th, 2005 in Design. Projects. Weblog

While not quite finished yet, I’ve finalized the features that will be available in the next release of . All of the existing functions will continue to be available, as well as the following improvements:

  • Correct, semantic tagging. Allows all links to be used by for categorizing posts by cleaning up all outbound links. Example: A search that normally looks like http://google.com?q=term+term will now look like http://warpedvisions.org/tags/google/term+term (site based on WP configuration).
  • All link targets are configurable with a new administration page.
  • Link generation is template-based, in plain PHP. Templates can access key (and custom) WP variables.
  • Link clicks are tracked for site usage analysis. Allows site admin to track downloads, specific image clicks, or abuse.
  • Targets can be used to inject content into posts (like templates). This makes it possible to use the proxy to insert images, template content based on WP settings/posts, or other dynamic content (like a scrape of another site). Example: You could generate an IMDB/Amazon combined div that contained a table of data taken from both sites (images, summary stats, etc.).
  • Targets can also be used to generate WP admin-specific content into posts. This allows WP admins to see edit links for locally linked articles and image upload/update forms inline to their posts.
  • Link injection allows writers to insert chunks of AJAX easily into posts. This will allow WP users to display inline graphs ([sparklines]), and other real-time content.
  • Improved handling for pre and code blocks.

Updated Syntax

  • [!!target: term1 term2 term3|param1|param2|param3]. Targets can either be links or injections, as defined in the SimpleLink WP admin panel.
  • [!![localtarget|param1|param2|param3]]. Local targets are also links or injections, but format is consistent with . Can also be a direct link: [!![http://test.org]].
  • {{Templatename|param1|param2}}. Template targets provide a pure injection syntax similar to the ] template syntax.

Generated URLs

URLs will be generated to point to a local proxy, based on your site url. Examples (syntax/rules subject to change):

  • http://warpedvisions.org/tags/google/test1. A simple google-search link.
  • http://warpedvisions.org/tags/amazon/warpedid/0045354. An amazon link with a referal . id as a parameter.
  • http://warpedvisions.org/tags/injection/sitestats. Returns a chunk of JavaScript that is used to inject content into a post.

Planning SimpleLink .5

[Comment]

June 7th, 2005 in Design. Projects. Weblog

I’m reworking my plugin based on some feedback and code contributed by a few users. This release will also fix a sticky bug found by a developer at , where search-based links do not form useful semantic tags. The main goal of the release will be to make the link generation configurable and to properly reflect the of the links.

Tagspaces

Tagged links are used by tools like to figure out what weblog articles are about, based on tagged s in the content. Tagged urls are elements that use the rel="tag" attribute to indicate that the url portion of the href has meaning. The tagspace of an article then, is defined by all of the tagged links found in the content. Tagged links are automatically generated by the plugin.

Unfortunately, many targets (like ) produce useless , as the generated urls are crusty. For example, the [!!this is a test] markup generates a link to a search with the terms this+is+a+test. The url is crusty, though, as it contains words and characters that are not related to the search terms. Notice all of the line noise before, between, and after the search terms:

http://google.com/search?q=this%20is%20a%20test&amp;btnI=

Instead, a useful tagged link would look more like:

http://google.com/feelinglucky/search/this+is+a+test

Most search-based links are crusty, making them useless as tagged links (even though it’s a really handy way to write an article).

Approach

This version of the plugin will split the plugin into two parts: a simplified plugin and a link proxy. Splitting the functionallity allows for a few neat improvements:

  • Tagspaces can be represented for any type of link, as the proxy can normalize all urls and redirect them to the right search
  • We can move the messy (and expensive) parts of the processing out of the WordPress rendering loop, as all links will point to the local proxy script. This allows us to delay database lookups for targets (and other magic) until the user actually clicks a link
  • It will allow for a new JavaScript injection target that will allow using the local proxy as a site interface for accessing other objects (like pictures, downloads, etc.)
  • It also allows the linking logic to be used from other Weblogging systems (and some of my non-weblog sites), as the proxy contains the useful logic

The proxy will be a simple script and rewrite rule. The rewrite rule will transmogrify a clean url into the required Php script parameters as follows:

http://site-url.domain/tags/google/term1+term2+term3

Will be converted to:

/simplelink-proxy.php?target=google&terms=term1+term2+term3

The plugin portion will translate the SimpleLink syntax into html or javascript that references the proxy. Search links will reference the proxy directly, and content links will either generate html directly or generate Javascript injection code to grab data from the proxy. The js injection method will be useful for images and thumbnails, especially for Flickr images.

The target definitions will move from code to the database, and a simple administration panel will be added to the WP admin tools.

SimpleLink .04 released

[Comment]

May 1st, 2005 in Projects. WP-Plugins. Weblog

A few more improvements for my SimpleLink

  • Fixed _ parsing bug ([Markdown] was munging underscores, now plays nicer with Markdown)
  • Added open links in new window for pkzip.

You can download wp-simplelink-0.4.tar.gz, or visit the SimpleLink page for more details.

SimpleLink .03 released

[Comment]

April 30th, 2005 in Projects. WP-Plugins. Weblog

I did a bit of work on SimpleLink today, mostly cleanup and random features. SimpleLink is a that makes linking to things simple.

  • Added tag='rel' attribute to all text links, which allows semantic scraping by and .
  • Fixed img generation for product links for fixed-size images with overflow (fixed dimension thumbnails without scaling thumbnail).
  • Added search links with techo: and tag: targets, which generates links to Technorati searches and tag searches.
  • Added image linking with flickr: target, making it easier to embed to Flickr images on your site

You can download wp-simplelink-0.3.tar.gz, or visit the SimpleLink home page for more details.

Easier weblog linking

[Comment]

January 8th, 2005 in WP-Plugins

I added a few features to my link plugin. I had been calling it MagicLink, but am thinking of changing the name to SimpleLink. People fear magic, even though it can be a lot of fun.

Here’s what can be done with Simple Links:

MarkupResulting text
[http://warpedvisions.org]
[http://warpedvisions.org|test]
[test google search]
[google: more google]
[foldoc: usb]
[imdb: star wars IV]
[perldoc: cgi]
[here: Google be gone]
[wiki: tsunami]
Image linking
[asin: 0898799279]
[0898799279]
[image: trees.png]trees.png
Special text
[abbr: CSS - Cascading Style Sheets]CSS
[note: You are here.]
You are here.
[comment: Test comment.]
Test comment.
[warning: Don't!]
Don’t
[tip: A tip.]
A tip.