CKEditor 4 Documentation

CKEDITOR.htmlParser.fragment

Files

A lightweight representation of an HTML DOM structure.

Defined By

Properties

CKEDITOR.htmlParser.fragment
view source
: Objectprivate
...

Defaults to: {isBlockLike: true, hasInlineStarted: false}

CKEDITOR.htmlParser.fragment
view source
: Array
The nodes contained in the root of this fragment. ...

The nodes contained in the root of this fragment.

var fragment = CKEDITOR.htmlParser.fragment.fromHtml( '<b>Sample</b> Text' );
alert( fragment.children.length ); // 2

Defaults to: []

CKEDITOR.htmlParser.fragment
view source
: Object
Get the fragment parent. ...

Get the fragment parent. Should always be null.

Defaults to: null

CKEDITOR.htmlParser.fragment
view source
: Numberreadonly
The node type. ...

The node type. This is a constant value set to CKEDITOR.NODE_DOCUMENT_FRAGMENT.

Defaults to: CKEDITOR.NODE_DOCUMENT_FRAGMENT

Methods

Defined By

Instance methods

Creates a fragment class instance. ...

Creates a fragment class instance.

Returns

CKEDITOR.htmlParser.fragment
view source
( node, [index] )
Adds a node to this fragment. ...

Adds a node to this fragment.

Parameters

CKEDITOR.htmlParser.fragment
view source
( filter )
Filter this fragment's content with given filter. ...

Filter this fragment's content with given filter.

Available since: 4.1

Parameters

CKEDITOR.htmlParser.fragment
view source
( filter, [filterRoot] )
Filter this fragment's children with given filter. ...

Filter this fragment's children with given filter.

Element's children may only be filtered once by one instance of filter.

Available since: 4.1

Parameters

  • filter : CKEDITOR.htmlParser.filter
  • filterRoot : Boolean (optional)

    Whether to apply the "root" filter rule specified in the filter.

CKEDITOR.htmlParser.fragment
view source
( callback, [type], [skipRoot] )
Execute callback on each node (of given type) in this document fragment. ...

Execute callback on each node (of given type) in this document fragment.

var fragment = CKEDITOR.htmlParser.fragment.fromHtml( '<p>foo<b>bar</b>bom</p>' );
fragment.forEach( function( node ) {
    console.log( node );
} );
// Will log:
// 1. document fragment,
// 2. <p> element,
// 3. "foo" text node,
// 4. <b> element,
// 5. "bar" text node,
// 6. "bom" text node.

Available since: 4.1

Parameters

  • callback : Function

    Function to be executed on every node. Since 4.3 if callback returned false descendants of current node will be ignored.

    Parameters

  • type : Number (optional)

    If specified callback will be executed only on nodes of this type.

  • skipRoot : Boolean (optional)

    Don't execute callback on this fragment.

CKEDITOR.htmlParser.fragment
view source
( writer, [filter], [filterRoot] )
Write and filtering the child nodes of this fragment. ...

Write and filtering the child nodes of this fragment.

Parameters

CKEDITOR.htmlParser.fragment
view source
( writer, [filter] )
Writes the fragment HTML to a CKEDITOR.htmlParser.basicWriter. ...

Writes the fragment HTML to a CKEDITOR.htmlParser.basicWriter.

var writer = new CKEDITOR.htmlWriter();
var fragment = CKEDITOR.htmlParser.fragment.fromHtml( '<P><B>Example' );
fragment.writeHtml( writer );
alert( writer.getHtml() ); // '<p><b>Example</b></p>'

Parameters

Defined By

Static methods

CKEDITOR.htmlParser.fragment
view source
( source ) : CKEDITOR.htmlParser.fragmentstatic
Creates a CKEDITOR.htmlParser.fragment from an HTML string. ...

Creates a CKEDITOR.htmlParser.fragment from an HTML string.

var fragment = CKEDITOR.htmlParser.fragment.fromHtml( '<b>Sample</b> Text' );
alert( fragment.children[ 0 ].name );       // 'b'
alert( fragment.children[ 1 ].value );  // ' Text'

Parameters

  • source : String

    The HTML to be parsed, filling the fragment.

Returns

CKEDITOR.htmlParser.fragment
view source
( fragmentHtml, [parent], [fixingBlock] ) : CKEDITOR.htmlParser.fragment/CKEDITOR.htmlParser.elementstatic
Creates a CKEDITOR.htmlParser.fragment from an HTML string. ...

Creates a CKEDITOR.htmlParser.fragment from an HTML string.

var fragment = CKEDITOR.htmlParser.fragment.fromHtml( '<b>Sample</b> Text' );
alert( fragment.children[ 0 ].name );       // 'b'
alert( fragment.children[ 1 ].value );  // ' Text'

Parameters

  • fragmentHtml : String

    The HTML to be parsed, filling the fragment.

  • parent : CKEDITOR.htmlParser.element/String (optional)

    Optional contextual element which makes the content been parsed as the content of this element and fix to match it. If not provided, then CKEDITOR.htmlParser.fragment will be used as the parent and it will be returned.

  • fixingBlock : String/Boolean (optional)

    When parent is a block limit element, and the param is a string value other than false, it is to avoid having block-less content as the direct children of parent by wrapping the content with a block element of the specified tag, e.g. when fixingBlock specified as p, the content <body><i>foo</i></body> will be fixed into <body><p><i>foo</i></p></body>.

Returns