I have been trying to replace the default entry textarea by an HTML editor such as this one ( FCK Editor – FREE web based HTML editor )
Getting the editor to work is relatively straight forward. Just install the zip files in their destination on your website, edit the editor javascript (or .htc) files to point to the new location and copy/paste the HTML code from the test pages into the �edit_entry.tmpl� template (MT/tmpl/cms folder).
Problems showed up when I tried to edit an entry : all HTML codes were replaced by their escaped equivalent.
For example : </A> becomes & lt ;/A & gt ;
This makes WYSIWYG editing completely useless. But the good news is – I finally got it to work…
Explanation
After some digging around, here is what MT editor is doing : when you add a new link, it automatically creates the HTML code for that link. So what you see on your form is (for example).
<a href=”http://www.renderosity.com/homepage.ez?Who=agiel”>Personal gallery</a>
But if you look at the source of your page, what is actually in the page is :
< textarea class=”width500″ name=”text” rows=”20″ wrap=”virtual” >
& lt ; a href=”http://www.renderosity.com/homepage.ez?Who=agiel” & gt ;Personal gallery& glt ;/a & gt ;
< /textarea >
So, MT has to convert �<� �>� symbols to �& lt ;� and �& gt ;� in order to display them correctly in the editor and convert them back to their original value to be displayed correctly in the final HTML page.
Now, when you use a WYSIWYG editor, the editor is doing that conversion for you by displaying URLs as clickable links directly in the editor, and not just as HTML code.
So what I want to see in the source of the page is :
< open HTML editor >
<a href=”http://www.renderosity.com/homepage.ez?Who=agiel”>Personal gallery</a>
< closeHTML editor >
Two modules are involved in this HTML filtering.
MT/lib/mt/Utils.pm defines two procedures (encode_html and decode_html)
MT/lib/mt/App/CMS.pm applies �encode_html� before building the edit page from the �edit_entry.tmpl� template.
Solution
It took some time to figure it out, but the solution is relatively simple.
Just edit line 437 in the module CMS.pm:
unless ( ((($col) eq “text”) or (($col) eq “text_more”)) and ($type eq �entry�))
{ $param{$col} = encode_html($param{$col}, 1); }
and add �decode_html� to the list of procedures loaded by the same module:
line 11: use MT::Util qw( encode_html decode_html format_ts offset_time_list remove_html get_entry );
This will effectively disable the automatic HTML encoding for the �entry body� and �entry body more� fields and make it possible to replace the main textarea by an HTML editor.
The result is an enhanced HTML editor for MT, complete with image upload and formatting options.
Note that the line numbers will likely work only with MT 2.6.4 (my current version).
I know it is not ideal to edit one of the core modules, so if someone has another suggestion, I am open to apply it
4 comments for “How to replace the default entry textarea by an HTML editor”