Syntax Highlighting For Code In Posts

Syntax Highlighting For Code In Posts

Trying the GeSHi Filter for Drupal 7 to get pretty syntax colored code in posts like:

  1. <?php
  2. $query = new EntityFieldQuery();
  3.  
  4. $query->entityCondition('entity_type', 'node')
  5. ->entityCondition('bundle', 'article')
  6. ->propertyCondition('status', 1)
  7. ->fieldCondition('field_news_types', 'value', 'spotlight', '=')
  8. ->fieldCondition('field_photo', 'fid', 'NULL', '!=')
  9. ->fieldCondition('field_faculty_tag', 'tid', $value)
  10. ->fieldCondition('field_news_publishdate', 'value', $year. '%', 'like')
  11. ->fieldOrderBy('field_photo', 'fid', 'DESC')
  12. ->range(0, 10)
  13. ->addMetaData('account', user_load(1)); // Run the query as user 1.
  14.  
  15. $result = $query->execute();
  16.  
  17. if (isset($result['node'])) {
  18. $news_items_nids = array_keys($result['node']);
  19. $news_items = entity_load('node', $news_items_nids);
  20. }
  21. ?>

It even has the ability to print line numbers. The instructions are fairly simple. The main hang up I had is that I missed the fact that the GeSHi filter had to be enabled for the Text Format that I wish to use it with which in my case is Full HTML.

I also tried using the Syntax Highlighter module, but it failed when I found that I needed the Wysiwyg module which is not in use here.