CKEditor 4 Documentation

CKEDITOR.htmlWriter

Hierarchy

Files

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>'
Defined By

Properties

CKEDITOR.htmlWriter
view source
: String
The characters to be used for each indentation step. ...

The characters to be used for each indentation step.

// Use tab for indentation.
editorInstance.dataProcessor.writer.indentationChars = '\t';

Defaults to: '\t'

CKEDITOR.htmlWriter
view source
: String
The characters to be used for line breaks. ...

The characters to be used for line breaks.

// Use CRLF for line breaks.
editorInstance.dataProcessor.writer.lineBreakChars = '\r\n';

Defaults to: '\n'

CKEDITOR.htmlWriter
view source
: String
The characters to be used to close "self-closing" elements, like <br> or <img>. ...

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: ' />'

Defined By

Methods

Creates an htmlWriter class instance. ...

Creates an htmlWriter class instance.

Returns

Overrides: CKEDITOR.htmlParser.basicWriter.constructor

CKEDITOR.htmlWriter
view source
( attName, attValue )
Writes an attribute. ...

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.

Overrides: CKEDITOR.htmlParser.basicWriter.attribute

CKEDITOR.htmlWriter
view source
( tagName )
Writes a closer tag. ...

Writes a closer tag.

// Writes '</p>'.
writer.closeTag( 'p' );

Parameters

  • tagName : String

    The element name for this tag.

Overrides: CKEDITOR.htmlParser.basicWriter.closeTag

CKEDITOR.htmlWriter
view source
( comment )
Writes a comment. ...

Writes a comment.

// Writes "<!-- My comment -->".
writer.comment( ' My comment ' );

Parameters

  • comment : String

    The comment text.

Overrides: CKEDITOR.htmlParser.basicWriter.comment

Empties the current output buffer. ...

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.

CKEDITOR.htmlWriter
view source
( )
Writes the current indentation character. ...

Writes the current indentation character. It uses the indentationChars property, repeating it for the current indentation steps.

// Writes '\t' (e.g.).
writer.indentation();
CKEDITOR.htmlWriter
view source
( )
Writes a line break. ...

Writes a line break. It uses the lineBreakChars property for it.

// Writes '\n' (e.g.).
writer.lineBreak();
CKEDITOR.htmlWriter
view source
( tagName, attributes )
Writes the tag opening part for an opener tag. ...

Writes the tag opening part for an 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.

Overrides: CKEDITOR.htmlParser.basicWriter.openTag

CKEDITOR.htmlWriter
view source
( tagName, isSelfClose )
Writes the tag closing part for an opener tag. ...

Writes the tag closing part for an 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>.

Overrides: CKEDITOR.htmlParser.basicWriter.openTagClose

CKEDITOR.htmlWriter
view source
( )
Empties the current output buffer. ...

Empties the current output buffer. It also brings back the default values of the writer flags.

writer.reset();

Overrides: CKEDITOR.htmlParser.basicWriter.reset

CKEDITOR.htmlWriter
view source
( tagName, rules )
Sets formatting rules for a given element. ...

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 the breakAfterOpen rule set to true.

// 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.

CKEDITOR.htmlWriter
view source
( text )
Writes text. ...

Writes text.

// Writes 'Hello Word'.
writer.text( 'Hello Word' );

Parameters

  • text : String

    The text value

Overrides: CKEDITOR.htmlParser.basicWriter.text

Writes any kind of data to the ouput. ...

Writes any kind of data to the ouput.

writer.write( 'This is an <b>example</b>.' );

Parameters

  • data : String