On this page
Code Filter
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 < and >. 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
- Install as you would normally install a contributed Drupal module
- Go to the Modules administration page and enable the Code Filter module
- Go to the Text Formats administration page. Click 'configure' for the format you wish to enable codefilter in, and enable the Code Filter checkbox on the next page.
- 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." - (optional) Edit your theme to provide a div.codeblock style for blocks of code.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion