
This was an explanation of how I wrote a Drupal5.n module to filter javascript code so that it displayed syntax highlighted. Drupal 7 has been released, this site has been upgraded and I decided to display programming code syntax highlighted using the GeShi PHP library. It caters for most languages and there is a geshifilter module to integrate the library into Drupal. Here are some examples:
Javascript
/* * comment block * */ // single line comment function example(a,c) { return a * c * 59; } document.writeln("this is a text string"); document.writeln('so is this, single quoted');
span.js_comment { color: Purple; font-style: italic; } span.js_string { color: Red; } span.js_keyword { color: Blue; } span.js_number { color: Green; }
/** * Implementation of hook_form_alter(). */ function pos_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'comment_node_blog_form') { // print '<pre>' . htmlspecialchars(print_r($form['author'], TRUE)) . '</pre>'; die; $form['author']['name']['#prefix'] = '<div class="pos-comment-label">'. $form['author']['name']['#title'] .'</div><div class="pos-comment-input">'; $form['author']['name']['#suffix'] = '</div>'; $form['author']['name']['#title'] = ''; } $form['author']['mail']['#prefix'] = '<div class="pos-comment-label">'. $form['author']['mail']['#title'] .'</div><div class="pos-comment-input">'; $form['author']['mail']['#suffix'] = '</div>'; $form['author']['mail']['#title'] = ''; } $form['author']['homepage']['#prefix'] = '<div class="pos-comment-label">'. $form['author']['homepage']['#title'] .'</div><div class="pos-comment-input">'; $form['author']['homepage']['#suffix'] = '</div>'; $form['author']['homepage']['#title'] = ''; } $form['subject']['#prefix'] = '<div class="pos-comment-label">'. $form['subject']['#title'] .'</div><div class="pos-comment-input">'; $form['subject']['#suffix'] = '</div>'; $form['subject']['#title'] = ''; } $form['comment_body']['und']['0']['#prefix'] = '<div class="pos-comment-label">'. $form['comment_body']['und']['0']['#title'] .'</div><div class="pos-comment-input">'; $form['comment_body']['und']['0']['#suffix'] = '</div>'; $form['comment_body']['und']['0']['#title'] = ''; } } // comment_form }
Undefined
Tag(s):