The Code Filter module allows users to post and display code using <code></code> and <?php ?> tags without having to worry about manually escaping < and > characters with &lt; and &gt;. The Code Filter is enabled on Drupal.org for input formats Filtered HTML, Full HTML, and Documentation.

Examples

Type in the following:
<code><h2>Example HTML heading</h2></code>
Code Filter displays:
<h2>Example HTML heading</h2>
(rather than turning Example HTML heading into an actual H2 heading)

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:
print 'Example PHP code.';

Installation

  1. Download and unzip the module.
  2. Copy the codefilter folder to the Drupal sites/all/modules/ directory, so that all files are in sites/all/modules/codefilter.
  3. Go to the Modules administration page and enable the Code Filter module
  4. Go to the Input Formats or Text Formats administration screen (depending on your version of Drupal). Click 'configure' for the format you wish to enable codefilter in, and check the Code Filter checkbox on the next page.
  5. 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."
  6. (optional) Edit your theme to provide a div.codeblock style for blocks of code.