CKEDITOR.htmlParser
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'.
Filtering
Methods
-
constructor() → htmlParser
CKEDITOR.htmlParser#constructor
-
onCDATA( cdata )
CKEDITOR.htmlParser#onCDATA
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.
-
onComment( comment )
CKEDITOR.htmlParser#onComment
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.
-
onTagClose( tagName )
CKEDITOR.htmlParser#onTagClose
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.
-
onTagOpen( tagName, attributes, selfClosing )
CKEDITOR.htmlParser#onTagOpen
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.
-
onText( text )
CKEDITOR.htmlParser#onText
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.
-
parse( html )
CKEDITOR.htmlParser#parse
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.