oEdit: valid (X)HTML

Questions about how to use the online - editors and suggestions how to improve them
Post Reply
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

oEdit: valid (X)HTML

Post by cmb » Fri Apr 05, 2013 11:12 pm

Hello Community,

the editor of classic CMSimple, oEdit, is often critized, as it sometimes fails to produce valid HTML and does completely ignore the setting of xhtml_endtags. While the latter had could been easily fixed by emitting an appropriate doctype in the "retrieve handling", the former is solely a problem of its simplicity. Like most (all?) other "online" editors, oEdit uses the so-called designMode of the browser. Contrary to several other editors (e.g. tinyMCE and CKEditor), oEdit doesn't clean up what the browser produces (which is quite different depending on the browser, as the interface is not standardized in any way).

So I've thought about a simple way to alleviate the situation, and the one with the best cost-benefit ratio is probably to do the most basic clean up server side using PHP's "tidy" extension. If you have PHP 5 with the "tidy" extension available (check phpinfo() or ask your provider) and want oEdit to produce valid (X)HTML, you can put the following code at the end of your cmsimple/functions.php (just before the closing ?>):

Code: Select all

function tidyHTM($htm)
{
    global $cf;

    if (class_exists('tidy') && version_compare(PHP_VERSION, '5', '>=')) {
        $tidy = new tidy();
        $mul = $cf['xhtml']['endtags'] == 'true'
            ? 'output-xhtml'
            : 'output-html';
        $config = array($mul => true, 'alt-text' => '', 'show-body-only' => true); // configuration
        $tidy->parseString($htm, $config, 'raw');
        if ($tidy->cleanRepair()) {
            return (string) $tidy;
        } else {
            return $htm;
        }
    } else {
        return $htm;
    }
} 
To activate this clean up function, you have to slightly modify line 276 of cmsimple/adm.php (what will trigger the clean up, when the page content is saved from the editor):

Code: Select all

    $c[$s] = preg_replace("/<h[1-".$cf['menu']['levels']."][^>]*>(\&nbsp;| )?<\/h[1-".$cf['menu']['levels']."]>/i", "", tidyHTM(stsl($text))); 
Please note, that I don't regard this to be the solution, but if you have or want to stick with oEdit and its limitations (as well as its benefits of being extremly lightweight), it seems to be a reasonable improvement, if you prefer valid (X)HTML.

And please note, that the chosen configuration of "tidy" is rather unobtrusive; you can force further clean up depending on your needs; see http://tidy.sourceforge.net/docs/quickref.html for details.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

svasti
Posts: 1659
Joined: Wed Dec 17, 2008 5:08 pm

Re: oEdit: valid (X)HTML

Post by svasti » Sat Apr 06, 2013 8:17 am

So are we going to see a tiny 1.6 with oEdit?

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: oEdit: valid (X)HTML

Post by cmb » Sat Apr 06, 2013 12:17 pm

svasti wrote:So are we going to see a tiny 1.6 with oEdit?
cmb wrote:Please note, that I don't regard this to be the solution, but if you have or want to stick with oEdit [...]
Actually I consider oEdit too limited for many purposes. Particularly missing is the possibility to add some styling in WYSIWYG mode. Having an alternative[1] lightweight editor available would be nice, but oEdit is definitely not my first choice. I'm having an eye on Whizzywing, which has another big advantage: it's using contentEditable instead of an IFrame, so all styles (even those of plugins) are available directly. If I'm not mistaken, this is available for CKEditor 4 and maybe even planned for tinyMCE 4.

I justed wanted to demonstrate, that some limitations of the lightweight editors can be worked around server side, and offer a hopefully working solution for users of CMSimple classic.

[1] I'd rather stick with tinyMCE (or maybe CKEditor) as default.
Christoph M. Becker – Plugins for CMSimple_XH

Tata
Posts: 3587
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: oEdit: valid (X)HTML

Post by Tata » Sat Apr 06, 2013 2:53 pm

A years ago, I used to install the WYSIWYG and I lied it much more than oEdit. However, comparing to FCK or TinyMCE, it is really only very simple editor with limited functions. But if used on websites with installed "media" plugins, it may match almost any requirements for text-content handling.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: oEdit: valid (X)HTML

Post by cmb » Sat Apr 06, 2013 5:07 pm

The openWYSIWYG editor was quite promising (I really was buffled when I saw the code: one of the cleanest I've ever seen); unfortunately its developement has ceased long ago (around 2007), and it doesn't work on Google Chrome, and as I've just noticed in FF 19.0.2: http://www.openwebware.com/wysiwyg/demo.shtml.

Whizzywing is quite comparable regarding the features. Its codebase is unreadable (beats even CMSimple < 2.8 ;)), the UI is questionable, but it's working quite well. It seems, that the development has also been discontinued a year ago, but at least its still working on recent browsers and it already uses contentEditable, which I consider a big bonus. And it seems to me, that Whizzywing produces quite good (X)HTML.

And there are quite some more editors, that may be interesting. Aloha editor looks very promising. The WYMeditor has an interesting approach by focussing on CSS classes instead of individual formatting. And of course there are alternative markup languages, which might also be used with CMSimple: markdown, textile, Wiki markup etc.
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply