- (11/14) Getting output from shell_exec() at all timesTAGS:Web ProgrammingWeb Server Admin
- (06/12) View Layer - Getting count of Entities in View in Cakephp 3TAGS:CakephpCake3
- (05/23) Changing URL in beforeRedirect() in Component - Cakephp 3TAGS:CakephpCake3Web Programming
- (01/28) Foundation CSS Framework ResourcesTAGS:FoundationCss
- (01/27) Change View File from Controller in CakePHP 3TAGS:CakephpCake3UsageWeb Programming
- (01/13) Loading Model/Table Anywhere in Cake3TAGS:Cake3Cakephp
- (10/06) CURL PHP 5.5 Issue on Windows (Using Twilio SDK)
Subscribe to my feed
Preformatted Text in TinyMCE <pre></pre>
Posted on 04/21/2009 at 10:26 am by Kevin Wentworth
Viewed 14,832 times | 1 comment
Now that I've got my blog up and running, I've been playing around with syntax highlighting of source code. I really appreciate sites that serve up code samples in a nice format, so I've tried to comply with my own version of this best practice.
So now I had Site Avenger running TinyMCE v18.104.22.168 with all my custom-built bells and whistles. I got down to writing my blog entries and started seeing some weird behavior- if I pasted content (through the plain-text dialog window) into a <pre> tag, the spacing/tabbing would be perfect. If I began to edit the code within the <pre> tags (through the TinyMCE editor), especially adding new lines, my line feeds would be turned into line breaks (<br />). Not good... I also found that if I went in and edited an article I had already posted (say for a typo) then the <pre> contents would all get <br /> added. I figured it was the way I was doing it.
Turns out, a lot of people are frustrated with TinyMCE's handling of content within <pre></pre> tags. Someone finally got fed up enough to provide a plugin, aptly named, prelementfix. All you do is add this to your plugins directory, and your plugin config line, and TinyMCE starts acting exactly how I need it to. Hitting the tab key tabs the content. No extraneous <br /> getting stuffed in the code. The code within the pre tags was staying intact and properly formatted. Thank you T Andersen!
I was only pasting PHP code snippets, so I wasn't running into issues with html entity encoding like many people do. I'd love to see this preelementfix plugin functionality be the default. Maybe incorporate the htmlentityencoding that the TinyMCE developers insist <pre> tagged content needs.