CKEDITOR.htmlParser.fragment
A lightweight representation of an HTML DOM structure.
Filtering
Properties
children : ArrayCKEDITOR.htmlParser.fragment#childrenThe nodes contained in the root of this fragment.
var fragment = CKEDITOR.htmlParser.fragment.fromHtml( '<b>Sample</b> Text' ); alert( fragment.children.length ); // 2Defaults to
[]parent : ObjectCKEDITOR.htmlParser.fragment#parent-
The node type. This is a constant value set to CKEDITOR.NODE_DOCUMENT_FRAGMENT.
Defaults to
CKEDITOR.NODE_DOCUMENT_FRAGMENT -
Defaults to
{isBlockLike: true, hasInlineStarted: false}
Methods
constructor() → fragmentCKEDITOR.htmlParser.fragment#constructoradd( node, [ index ] )CKEDITOR.htmlParser.fragment#addAdds a node to this fragment.
Parameters
node : nodeThe node to be added.
[ index ] : NumberFrom where the insertion happens.
Filter this fragment's children with given filter.
Element's children may only be filtered once by one instance of filter.
Parameters
filter : filter[ filterRoot ] : BooleanWhether to apply the "root" filter rule specified in the
filter.Execute callback on each node (of a 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.Parameters
callback : FunctionFunction to be executed on every node. Since 4.3.0 if
callbackreturnedfalsedescendants of current node will be ignored.[ type ] : NumberIf specified
callbackwill be executed only on nodes of this type.[ skipRoot ] : BooleanDon't execute
callbackon this fragment.writeChildrenHtml( writer, [ filter ], [ filterRoot ] )CKEDITOR.htmlParser.fragment#writeChildrenHtmlWrite and filtering the child nodes of this fragment.
Parameters
writer : basicWriterThe writer to which write the HTML.
[ filter ] : filterThe filter to use when writing the HTML.
[ filterRoot ] : BooleanWhether to apply the "root" filter rule specified in the
filter.writeHtml( writer, [ filter ] )CKEDITOR.htmlParser.fragment#writeHtmlWrites 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
writer : basicWriterThe writer to which write the HTML.
[ filter ] : filterThe filter to use when writing the HTML.
Static methods
-
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 : StringThe HTML to be parsed, filling the fragment.
Returns
fragmentThe fragment created.
static
fromHtml( fragmentHtml, [ parent ], [ fixingBlock ] ) → fragment | elementCKEDITOR.htmlParser.fragment#fromHtmlCreates 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 : StringThe HTML to be parsed, filling the fragment.
[ parent ] : element | StringOptional 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 | BooleanWhen
parentis a block limit element, and the param is a string value other thanfalse, 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. whenfixingBlockspecified asp, the content<body><i>foo</i></body>will be fixed into<body><p><i>foo</i></p></body>.Returns
fragment | elementThe created fragment or passed
parent.
-