user123445656
user123445656

Reputation: 3

CKEditor parsing html to nodes

I'm looking for a way to create a new node in CKEDITOR from some html.

to get a new span node I can do

var x = new CKEditor.dom.element('span');

but I want the span node to initialize with html similar to span below

<span class='link' isPop='false'>Single quote's and special character!</span>    

so question is:

is there anything available in CKEDITOR which creates a new node from existing html e.g

var spanHTML = '<span class='link' isPop='false'>Single quote's and special character!</span>';

var newNode = new CKEditor.dom.element('span', spanHTML);

or something like

var parser = new CKEDITOR.htmlParser();
parser.node = function( tagName, html )
{
    // do something here
};

var newNode = parse.node('span', spanHTML);

Upvotes: 0

Views: 2994

Answers (2)

Reinmar
Reinmar

Reputation: 22013

There's a CKEDITOR.dom.element#createFromHtml method - you can use it to create one element from given outerHtml. Docs http://docs.ckeditor.com/#!/api/CKEDITOR.dom.element-static-method-createFromHtml

var el = CKEDITOR.dom.element.createFromHtml( '<span class="a">x</span>' );
el.hasClass( 'a' ); // true

Upvotes: 0

xavier.seignard
xavier.seignard

Reputation: 11144

There is a appendHtml method you can use to do that : http://docs.ckeditor.com/#!/api/CKEDITOR.dom.element-method-appendHtml

Upvotes: 2

Related Questions