2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
6 CKEDITOR.htmlParser.basicWriter = CKEDITOR.tools.createClass(
\r
19 * Writes the tag opening part for a opener tag.
\r
20 * @param {String} tagName The element name for this tag.
\r
21 * @param {Object} attributes The attributes defined for this tag. The
\r
22 * attributes could be used to inspect the tag.
\r
24 * // Writes "<p".
\r
25 * writer.openTag( 'p', { class : 'MyClass', id : 'MyId' } );
\r
27 openTag : function( tagName, attributes )
\r
29 this._.output.push( '<', tagName );
\r
33 * Writes the tag closing part for a opener tag.
\r
34 * @param {String} tagName The element name for this tag.
\r
35 * @param {Boolean} isSelfClose Indicates that this is a self-closing tag,
\r
36 * like "br" or "img".
\r
39 * writer.openTagClose( 'p', false );
\r
41 * // Writes " />".
\r
42 * writer.openTagClose( 'br', true );
\r
44 openTagClose : function( tagName, isSelfClose )
\r
47 this._.output.push( ' />' );
\r
49 this._.output.push( '>' );
\r
53 * Writes an attribute. This function should be called after opening the
\r
54 * tag with {@link #openTagClose}.
\r
55 * @param {String} attName The attribute name.
\r
56 * @param {String} attValue The attribute value.
\r
58 * // Writes ' class="MyClass"'.
\r
59 * writer.attribute( 'class', 'MyClass' );
\r
61 attribute : function( attName, attValue )
\r
63 // Browsers don't always escape special character in attribute values. (#4683, #4719).
\r
64 if ( typeof attValue == 'string' )
\r
65 attValue = CKEDITOR.tools.htmlEncodeAttr( attValue );
\r
67 this._.output.push( ' ', attName, '="', attValue, '"' );
\r
71 * Writes a closer tag.
\r
72 * @param {String} tagName The element name for this tag.
\r
74 * // Writes "</p>".
\r
75 * writer.closeTag( 'p' );
\r
77 closeTag : function( tagName )
\r
79 this._.output.push( '</', tagName, '>' );
\r
84 * @param {String} text The text value
\r
86 * // Writes "Hello Word".
\r
87 * writer.text( 'Hello Word' );
\r
89 text : function( text )
\r
91 this._.output.push( text );
\r
96 * @param {String} comment The comment text.
\r
98 * // Writes "<!-- My comment -->".
\r
99 * writer.comment( ' My comment ' );
\r
101 comment : function( comment )
\r
103 this._.output.push( '<!--', comment, '-->' );
\r
107 * Writes any kind of data to the ouput.
\r
109 * writer.write( 'This is an <b>example</b>.' );
\r
111 write : function( data )
\r
113 this._.output.push( data );
\r
117 * Empties the current output buffer.
\r
123 this._.output = [];
\r
124 this._.indent = false;
\r
128 * Empties the current output buffer.
\r
129 * @param {Boolean} reset Indicates that the {@link reset} function is to
\r
130 * be automatically called after retrieving the HTML.
\r
131 * @returns {String} The HTML written to the writer so far.
\r
133 * var html = writer.getHtml();
\r
135 getHtml : function( reset )
\r
137 var html = this._.output.join( '' );
\r