To display text characters including code, blank spaces, and line-breaks in a pre-formatted fashion on your Drupal 7 site without the use of a WYSIWYG editor,...

I do Not know. I welcome your CSS and HTML code editing instructions. JavaScript and/or PHP code instructions are welcomed if my quest is Not possible strictly using HTML/CSS] I will incorporate your ideas, suggestions, and solutions to this problem on the Handbook page:

Drupal 7 - Displaying pre-formatted text & code on your site - HowTo




Ineffective attempts


- You can create pages on your site, and choose the text-format "Plain text", but then you will not be able to use any HTML in your content body.

- You can Not simply place your pre-formatted text within thee element-tag set <pre></pre> nor <code></code>. [..or at least, "I can't yet.."]

- Pre-formatted text & code is displayed within posts at via the WYSIWYG [What-You-See-Is-What-You-Get] editor button "code". It wraps your input within <code></code>. However, I can Not replicate this functionality on my Drupal 7 site. And at the site, the use of the text "</code>" (without the double-quotation-marks) puts an end to my input.

I ought to be able to avoid the use of <code></code> in my preformatted text and code, but the question remains:

How can I most easily post text tutorials on my site with intersperced code snippets?

Note: A long and round-about solution is here..
..but I cannot believe all of that is necessary.

There has to ba a simpler solution.





Christopher James Francis Rodgers’s picture


All the best; intended.
-Chris (
"The number one stated objective for Drupal is improving usability." ~Dries Buytaert *

Christopher James Francis Rodgers’s picture

..just don't use the characters


or that will be the end of your <code>

All the best; intended.
-Chris (
"The number one stated objective for Drupal is improving usability." ~Dries Buytaert *

dnewkerk’s picture

Christopher James Francis Rodgers’s picture

@ keyz - Dear David: Thank you kindly for response.

The "Code Filter" module seemed like the perfect solution to my quest-- with only three outstanding D7 bug reports, and a the claim that it was being used on the site, I was confidently and happily on my way. The project page's lack of a link to its documentation handbook page, and JohnAlbins' desire to pass the administration of the module to someone else, however, did give me pause.

This could be 'great'. Just insert my-pre-formatted-text within <code></code>.

The module seems to work fine for Full-HTML, but I could not get it to display properly for Filtered-HTML.

The handbook page was fairly scant on configuration details regarding the "Filter processing order", but I figured I would 'by trial and error' eventually stumble upon a working combination.

I was wrong. Strangely though, just as the sun was showing in the East, when I substituted <code style=""> for <code>, Filtered-HTML displayed properly instead of displaying all 'inline'. That hurt my over-tired brain, so I re-checked it.. twice.

Heavy sigh. The all too common depression I have learned to associate with D7-- great ideas that fall short the mark.

[Note aside: Where is D8? That is the dream's leading edge. D7: the 'best forgotten' middle-child. By the way, is D7 work not largely headed to 'deprecation', or will ALL of it transfer to D8? END note Aside.]


Any other suggestions?


Syntax Highlighter 3.0.83 - by Alex Gorbatchev

I saw this before your post, but its installation instructions were scant, and they assumed a basic working knowledge of JavaScript-- and I know only HTML & CSS-- presently. When I later saw your post, I assumed that "Code Filter" functions similarly.

Syntax Highlighter is presently on my radar as the #1 most likely to be the easiest to implement and use for new Drupal 7 Admins; assuming I provide keystroke-by-keystroke/ mouseclick-by-mouse-click fully detailed tutorials. I hope I'm wrong.


Textarea HTML tag/ element.

Yesterday's welcomed discovery before I saw @keyz post: This presently is my best "it works", and my only "it works in one-step" solution to my quest. Ala-sent. (Like God-sent, but for the Eastern hemisphere)

It does involve my defining dimensions for the 'box' that is displayed, but it does display pre-formatted text exactly.

background-color: white; 
border: 2px solid yellow; 
width:500px; height:400px;

Note: If, as above, you edit HTML code with line-breaks, you must remove the default configuration check-mark "Convert line breaks into HTML (i.e. <br> and <p>) " for the text-format you are using on the page you intend to display pre-formatted HTML using the textarea element.


Google research Re keywords: "drupal 7"

1.) <![CDATA[Your <code> here]]>

This was claimed to work only with xHTML, yet since D7 appears to be xHTML, I tried it.. once, but it failed me.

2.) ..."Or you could put in an iframe that loads a plain old text file."

No additional notes or details were provided, so I did Not try that.


Escaping HTML

Or in other words, converting HTML code to its UnicodeValue This is a working solution, and was my only solution before yesterday's 'textarea' discovery. This solution is far from new-user-friendly, but I have in fact used it above on this very comment. For quick conversions, I found this additional converter, (and I know others exist) but strangely it required an extra step since "&" was converted to &amp; unnecessarily--my opinion. Steps required: 'conversion', 'posting on new D7 page', 'viewing', 'copying the viewed display', 'edit same page', 'replacing original conversion with copied display' ...if you follow that. And required the use of the configuration check-mark "Convert line breaks into HTML (i.e. <br> and <p>) ". - On the page above, click on the last link "Escape HTML symbols". - Paste your-code into the text-field; and click the button "Go". - The 'escaped' code is generated. Copy and paste the generated code into your Drupal 7 site page, and use as text-format "Full HTML" with "Convert line breaks into HTML (i.e. <br> and <p>) ". Then 'View' your new page, and 'copy' the display of the converted code. - "Edit" the page and 'paste'. Ie. Replace original conversion with copied display. --- Yeah. Hardly user-friendly-instructions, I know. I remember my last attempt to detail a conversion process using a different converter all-together at... A Drupal 7.4 substitute for the

Not pretty; I am fully aware. 


I can only shake my head in fond rememberance of the old <pre> tag. 

What to do next?

I guess I'll CSS my <textarea>, and hope you who read this will leave your input/ suggestions/ anything... help. 




"All the best; intended."

All the best; intended.
-Chris (
"The number one stated objective for Drupal is improving usability." ~Dries Buytaert *