Daikini

We're human after all.

SimpleHighlight - Syntax highlighting for SimpleLog

Posted by Jonathan on June 14, 2007 at 10:02 AM

SimpleHighlight uses the ultraviolet library for syntax highlighting of code inside posts. You must have ultraviolet installed and working for SimpleHighlight to work.

Installation

To install SimpleHighlight you can:

./script/plugin install svn://svn.roundhaus.com/daikini/plugins/simple_highlight

or if you prefer piston:

piston import svn://svn.roundhaus.com/daikini/plugins/simple_highlight vendor/plugins/simple_highlight

You will also need to include the css for the particular theme you are using. The css files are included as part of the ultraviolet library.

Usage

To use SimpleHighlight you just add code tags around whatever code you want to have highlighted. You can optionally specify the language to use with by adding a class on to the code tag with the language you want. By default code uses the ruby_on_rails language. SimpleHighlight also defaults to using the “all_hallows_eve” theme. Right now the only way to change the theme is to change it in the plugin code itself.

Here is some RubyOnRails code:

   1  class Post
   2    has_many :comments
   3  end

Here is some Javascript code:

   1  function init()
   2  // init vars, run some initial functions
   3  {
   4      body_container = document.getElementById('wrapper');
   5      search_field = document.getElementById('q');
   6      search_div = document.getElementById('search');
   7      results_wrapper_div = document.getElementById('search_results');
   8      loading_msg_span = document.getElementById('loading');
   9      results_span = document.getElementById('results');
  10      tag_block = document.getElementById('tags');
  11      author_block = document.getElementById('authors');
  12  
  13      default_field_value = 'Enter your terms, hit enter';
  14      message_when_searching = 'Searching...';
  15      message_when_done = '';
  16      results_when_searching = '';
  17  
  18      passive_search_text_color = '#777';
  19      active_search_text_color = '#000';
  20  
  21      isIE = false;
  22  
  23      searchInit(search_field); // capture key events
  24      clearSearch(); // set everything right with search field / areas
  25  }

Here is some CSS code:

   1  /**
   2   * =Body
   3   ***************************/
   4  body {
   5      font: normal 14px/22px Helvetica, Arial, Helvetica, Sans-serif;
   6      margin: 0;
   7      padding: 0;
   8      color: #4c4c4c;
   9      background-color: #273d4a;
  10      text-align: center;
  11  }
Hierarchy: previous, next

Comments

There are 4 comments on this post. Post yours →

Noname

Drop-dead-gorgeous!

Very beautiful and elegant, great work guys. I’m also actually considering simple_highlight on a Rails Code Repository Project of mine.

Regarding your note…

“Right now the only way to change the theme is to change it in the plugin code itself.”

You can actually change the default theme in environment.rb by adding the line (replacing newtheme with your favourite)…

SimpleHighlight::THEME = “newtheme”

This must be after the Rails::Initializer.run block (ie. after the plugin gets loaded).

Cheers (and thanks for the useful plug-in!)

–Brent

Hye, your useful plugin seems to broke simplelog application.

On a clean install of simplelog, installing the plugin broke 2 tests: testdestroypost and testauthordestroy. In fact, it seems to be related to the acts as taggable functionality. In the app, you cannot create or update any post anymore.

Did anyone reported this issue?

Post a comment

Required fields in bold.