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() → htmlParserCKEDITOR.htmlParser#constructor -
onCDATA( cdata )CKEDITOR.htmlParser#onCDATAFunction 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 : StringThe CDATA been found.
-
onComment( comment )CKEDITOR.htmlParser#onCommentFunction 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 : StringThe comment text.
-
onTagClose( tagName )CKEDITOR.htmlParser#onTagCloseFunction 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 : StringThe tag name. The name is guarantted to be lowercased.
-
onTagOpen( tagName, attributes, selfClosing )CKEDITOR.htmlParser#onTagOpenFunction 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 : StringThe tag name. The name is guarantted to be lowercased.
attributes : ObjectAn object containing all tag attributes. Each property in this object represent and attribute name and its value is the attribute value.
selfClosing : Booleantrueif the tag closes itself, false if the tag doesn't.
-
onText( text )CKEDITOR.htmlParser#onTextFunction 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 : StringThe text found.
-
parse( html )CKEDITOR.htmlParser#parseParses 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 : StringThe HTML to be parsed.