CKEditor 4 Documentation

CKEDITOR.htmlParser

Files

Provides an "event like" system to parse strings of HTML data.

var parser = new CKEDITOR.htmlParser();
parser.onTagOpen = function( tagName, attributes, selfClosing ) {
    alert( tagName );
};
parser.parse( '<p>Some <b>text</b>.</p>' ); // Alerts 'p', 'b'.
Defined By

Methods

Creates a htmlParser class instance. ...

Creates a htmlParser class instance.

Returns

CKEDITOR.htmlParser
view source
( cdata )
Function to be fired when CDATA section is found. ...

Function to be fired when CDATA section is found. This function should be overriden when using this class.

var parser = new CKEDITOR.htmlParser();
parser.onCDATA = function( cdata ) {
    alert( cdata ); // 'var hello;'
} );
parser.parse( '<script>var hello;</script>' );

Parameters

  • cdata : String

    The CDATA been found.

CKEDITOR.htmlParser
view source
( comment )
Function to be fired when a commend is found. ...

Function to be fired when a commend is found. This function should be overriden when using this class.

var parser = new CKEDITOR.htmlParser();
parser.onComment = function( comment ) {
    alert( comment ); // ' Example '
} );
parser.parse( '<!-- Example --><b>Hello</b>' );

Parameters

  • comment : String

    The comment text.

CKEDITOR.htmlParser
view source
( tagName )
Function to be fired when a tag closer is found. ...

Function to be fired when a tag closer is found. This function should be overriden when using this class.

var parser = new CKEDITOR.htmlParser();
parser.onTagClose = function( tagName ) {
    alert( tagName ); // 'b'
} );
parser.parse( '<!-- Example --><b>Hello</b>' );

Parameters

  • tagName : String

    The tag name. The name is guarantted to be lowercased.

CKEDITOR.htmlParser
view source
( tagName, attributes, selfClosing )
Function to be fired when a tag opener is found. ...

Function to be fired when a tag opener is found. This function should be overriden when using this class.

var parser = new CKEDITOR.htmlParser();
parser.onTagOpen = function( tagName, attributes, selfClosing ) {
    alert( tagName ); // e.g. 'b'
} );
parser.parse( '<!-- Example --><b>Hello</b>' );

Parameters

  • tagName : String

    The tag name. The name is guarantted to be lowercased.

  • attributes : Object

    An object containing all tag attributes. Each property in this object represent and attribute name and its value is the attribute value.

  • selfClosing : Boolean

    true if the tag closes itself, false if the tag doesn't.

CKEDITOR.htmlParser
view source
( text )
Function to be fired when text is found. ...

Function to be fired when text is found. This function should be overriden when using this class.

var parser = new CKEDITOR.htmlParser();
parser.onText = function( text ) {
    alert( text ); // 'Hello'
} );
parser.parse( '<!-- Example --><b>Hello</b>' );

Parameters

  • text : String

    The text found.

CKEDITOR.htmlParser
view source
( html )
Parses text, looking for HTML tokens, like tag openers or closers, or comments. ...

Parses text, looking for HTML tokens, like tag openers or closers, or comments. This function fires the onTagOpen, onTagClose, onText and onComment function during its execution.

var parser = new CKEDITOR.htmlParser();
// The onTagOpen, onTagClose, onText and onComment should be overriden
// at this point.
parser.parse( '<!-- Example --><b>Hello</b>' );

Parameters

  • html : String

    The HTML to be parsed.