1

I am using Drupal as a blog for posts about programming. Naturally, I have to post code samples.

When I post the code samples, Drupal renders them as actual HTML. How can I stop this from happening?

Example,

<h1 style="font-style: italic; font-variant: small-caps; font-weight: normal; font-size: 13px; line-height: 150%; font-family:Arial, Helvetica, sans-serif; color: #000;">Thank You</h1>

^ This gets displayed as the words "Thank You" with the listed formatting in the inline style.

 <!--[if gte mso 9]>
    <style type="text/css">
   .contact {
display:none;
}
    </style>
<![endif]-->

^ This doesn't get displayed at all.

Steps I have taken

I have created a new input format and turned off all the filters. I wrap the code in both <code> and <pre> tags.

I know Drupal has a filter called " Display any HTML as plain text". If I use this, then it works. But then all my formatting for the test of the post (e.g. paragraphs, links) get displayed as text making the post unreadable.

2 Answers 2

1

Try the Syntax Highlighter module

This module integrates the SyntaxHighlighter Javascript Library into Drupal for source code list syntax highlighting within any Drupal contents.

Image from project page

enter image description here

1

Looks like you're looking for Code Filter.

This module provides a simple text format (input filter) that handles <?php ?> and <code></code> tags so that users can post code without having to worry about manually escaping < and > characters with &lt; and &gt;.

It is the module used on Drupal.org for escaping markup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.