CKEDITOR.htmlWriter
The class used to write HTML data.
var writer = new CKEDITOR.htmlWriter();
writer.openTag( 'p' );
writer.attribute( 'class', 'MyClass' );
writer.openTagClose( 'p' );
writer.text( 'Hello' );
writer.closeTag( 'p' );
alert( writer.getHtml() ); // '<p class="MyClass">Hello</p>'
Filtering
Properties
-
indentationChars : String
CKEDITOR.htmlWriter#indentationChars
The characters to be used for each indentation step.
// Use tab for indentation. editorInstance.dataProcessor.writer.indentationChars = '\t';
Defaults to
'\t'
-
lineBreakChars : String
CKEDITOR.htmlWriter#lineBreakChars
The characters to be used for line breaks.
// Use CRLF for line breaks. editorInstance.dataProcessor.writer.lineBreakChars = '\r\n';
Defaults to
'\n'
-
selfClosingEnd : String
CKEDITOR.htmlWriter#selfClosingEnd
The characters to be used to close "self-closing" elements, like
<br>
or<img>
.// Use HTML4 notation for self-closing elements. editorInstance.dataProcessor.writer.selfClosingEnd = '>';
Defaults to
' />'
Methods
-
-
Writes an attribute. This function should be called after opening the tag with openTagClose.
// Writes ' class="MyClass"'. writer.attribute( 'class', 'MyClass' );
Parameters
attName : String
The attribute name.
attValue : String
The attribute value.
-
Writes a closer tag.
// Writes '</p>'. writer.closeTag( 'p' );
Parameters
tagName : String
The element name for this tag.
-
Writes a comment.
// Writes '<!-- My comment -->'. writer.comment( ' My comment ' );
Parameters
comment : String
The comment text.
-
Empties the current output buffer.
var html = writer.getHtml();
Parameters
reset : Boolean
Indicates that the reset method is to be automatically called after retrieving the HTML.
Returns
String
The HTML written to the writer so far.
-
indentation()
CKEDITOR.htmlWriter#indentation
Writes the current indentation character. It uses the indentationChars property, repeating it for the current indentation steps.
// Writes '\t' (e.g.). writer.indentation();
-
lineBreak()
CKEDITOR.htmlWriter#lineBreak
Writes a line break. It uses the lineBreakChars property for it.
// Writes '\n' (e.g.). writer.lineBreak();
-
Writes the tag opening part for a opener tag.
// Writes '<p'. writer.openTag( 'p', { class : 'MyClass', id : 'MyId' } );
Parameters
tagName : String
The element name for this tag.
attributes : Object
The attributes defined for this tag. The attributes could be used to inspect the tag.
-
Writes the tag closing part for a opener tag.
// Writes '>'. writer.openTagClose( 'p', false ); // Writes ' />'. writer.openTagClose( 'br', true );
Parameters
tagName : String
The element name for this tag.
isSelfClose : Boolean
Indicates that this is a self-closing tag, like
<br>
or<img>
.
-
-
setRules( tagName, rules )
CKEDITOR.htmlWriter#setRules
Sets formatting rules for a given element. Possible rules are:
indent
– indent the element content.breakBeforeOpen
– break line before the opener tag for this element.breakAfterOpen
– break line after the opener tag for this element.breakBeforeClose
– break line before the closer tag for this element.breakAfterClose
– break line after the closer tag for this element.
All rules default to
false
. Each function call overrides rules that are already present, leaving the undefined ones untouched.By default, all elements available in the CKEDITOR.dtd.$block, CKEDITOR.dtd.$listItem, and CKEDITOR.dtd.$tableContent lists have all the above rules set to
true
. Additionaly, the<br>
element has thebreakAfterOpen
rule set totrue
.// Break line before and after "img" tags. writer.setRules( 'img', { breakBeforeOpen: true breakAfterOpen: true } ); // Reset the rules for the "h1" tag. writer.setRules( 'h1', {} );
Parameters
tagName : String
The name of the element for which the rules are set.
rules : Object
An object containing the element rules.
-
Writes text.
// Writes 'Hello Word'. writer.text( 'Hello Word' );
Parameters
text : String
The text value.
-
Writes any kind of data to the ouput.
writer.write( 'This is an <b>example</b>.' );
Parameters
data : String