Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can I use the tinyMCE cleanup algorithms without using the editor?

I'm using tinyMCE to edit content, and it has the cleanup rules set for what to scrub before posting the data back. but in other areas of my app, I need to display that same content... and I dont want to count on the fact that it was correctly scrubbed before it was put INTO the database (it may have been edited by another app).

so for consistency sake (and not having to duplicate effort) is there a way for me to use the tinyMCE cleanup/scrubber directly in javascript so that I can scrub other content before placing it into the DOM just for viewing? something like:

var data = getDataViaAjax(); 
var content = tinymce.scrubber.cleanup(data); 
$("someElement").append(content);

UPDATE - example of how to do it

function parse(html) {
    var settings = { 
       invalid_elements : "script,object,embed,link,style,form,input,iframe",
       valid_elements:"a[href],img[src],li,ul,ol,span,div,p,br,blockquote,h1,h2,h3,h4,h5,h6,strong/b,em/i,li,ul,ol"
    };

    var schema = new tinymce.html.Schema(settings);
    var parser = new tinymce.html.DomParser({}, schema);
    var serializer = new tinymce.html.Serializer({}, schema);

    return serializer.serialize(parser.parse(html));
}
like image 797
Nick Franceschina Avatar asked Apr 11 '12 19:04

Nick Franceschina


1 Answers

There is no predefined way to use this functionality. In order to get the mceCleanup-Action to work without tinymce you will have to write it yourself, but you should be able to use the predefined javascript classes with a few changes. Have a look at the developer tinymce version (uncompressed). There you may start with the function serialize in the File Serializer.js which can be found in the classes/dom directory.

like image 124
Thariama Avatar answered Nov 13 '22 06:11

Thariama