]>
git.immae.eu Git - perso/Immae/Projets/packagist/ludivine-ckeditor-component.git/blob - sources/core/htmlparser/basicwriter.js
2 * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
12 CKEDITOR
.htmlParser
.basicWriter
= CKEDITOR
.tools
.createClass( {
14 * Creates a basicWriter class instance.
26 * Writes the tag opening part for a opener tag.
29 * writer.openTag( 'p', { class : 'MyClass', id : 'MyId' } );
31 * @param {String} tagName The element name for this tag.
32 * @param {Object} attributes The attributes defined for this tag. The
33 * attributes could be used to inspect the tag.
35 openTag: function( tagName
) {
36 this._
.output
.push( '<', tagName
);
40 * Writes the tag closing part for a opener tag.
43 * writer.openTagClose( 'p', false );
46 * writer.openTagClose( 'br', true );
48 * @param {String} tagName The element name for this tag.
49 * @param {Boolean} isSelfClose Indicates that this is a self-closing tag,
50 * like `<br>` or `<img>`.
52 openTagClose: function( tagName
, isSelfClose
) {
54 this._
.output
.push( ' />' );
56 this._
.output
.push( '>' );
60 * Writes an attribute. This function should be called after opening the
61 * tag with {@link #openTagClose}.
63 * // Writes ' class="MyClass"'.
64 * writer.attribute( 'class', 'MyClass' );
66 * @param {String} attName The attribute name.
67 * @param {String} attValue The attribute value.
69 attribute: function( attName
, attValue
) {
70 // Browsers don't always escape special character in attribute values. (#4683, #4719).
71 if ( typeof attValue
== 'string' )
72 attValue
= CKEDITOR
.tools
.htmlEncodeAttr( attValue
);
74 this._
.output
.push( ' ', attName
, '="', attValue
, '"' );
78 * Writes a closer tag.
81 * writer.closeTag( 'p' );
83 * @param {String} tagName The element name for this tag.
85 closeTag: function( tagName
) {
86 this._
.output
.push( '</', tagName
, '>' );
92 * // Writes 'Hello Word'.
93 * writer.text( 'Hello Word' );
95 * @param {String} text The text value.
97 text: function( text
) {
98 this._
.output
.push( text
);
104 * // Writes '<!-- My comment -->'.
105 * writer.comment( ' My comment ' );
107 * @param {String} comment The comment text.
109 comment: function( comment
) {
110 this._
.output
.push( '<!--', comment
, '-->' );
114 * Writes any kind of data to the ouput.
116 * writer.write( 'This is an <b>example</b>.' );
118 * @param {String} data
120 write: function( data
) {
121 this._
.output
.push( data
);
125 * Empties the current output buffer.
131 this._
.indent
= false;
135 * Empties the current output buffer.
137 * var html = writer.getHtml();
139 * @param {Boolean} reset Indicates that the {@link #reset} method is to
140 * be automatically called after retrieving the HTML.
141 * @returns {String} The HTML written to the writer so far.
143 getHtml: function( reset
) {
144 var html
= this._
.output
.join( '' );