Code Filter

Last modified: October 23, 2009 - 20:47

This is a simple filter module to handle <code></code> and <?php ?> tags so that users can post code without having to worry about escaping with < and >.

Code Filter is on at drupal.org. When you contribute documentation, you can select input formats of Filtered HTML or Documentation and both accept <code></code> plus <?php ?> tags.

Examples

Type in the following:
<code><h2>Example HTML heading</h2></code>
Code Filter displays:
<h2>Example HTML heading</h2>

Type in the following:
<code><?php print 'Example PHP code.'; ?></code>
Code Filter displays:
<?php print 'Example PHP code.'; ?>

Type in the following:
<?php print 'Example PHP code.'; ?>
Code Filter displays:

<?php
print 'Example PHP code.';
?>

Installation

  1. Copy the codefilter folder to the Drupal modules/ directory, so that all files are in modules/codefilter.
  2. Go to administer > modules, and enable the codefilter.module
  3. Go to administer > input formats. Click 'configure' for the format you wish to enable codefilter in, and check the codefilter checkbox on the next page.
  4. Go to the input format's ordering page and rearrange the filtering chain to resolve any conflicts. For example, to prevent invalid XHTML in the form of '<p><div class="codefilter">' make sure "Code filter" comes before the "Line break converter."
  5. (optionally) Edit your theme to provide a div.codeblock style for blocks of code.
 
 

Drupal is a registered trademark of Dries Buytaert.