2 Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
8 // Base HTML entities.
\r
9 var htmlbase = 'nbsp,gt,lt,amp';
\r
13 'quot,iexcl,cent,pound,curren,yen,brvbar,sect,uml,copy,ordf,laquo,' +
\r
14 'not,shy,reg,macr,deg,plusmn,sup2,sup3,acute,micro,para,middot,' +
\r
15 'cedil,sup1,ordm,raquo,frac14,frac12,frac34,iquest,times,divide,' +
\r
18 'fnof,bull,hellip,prime,Prime,oline,frasl,weierp,image,real,trade,' +
\r
19 'alefsym,larr,uarr,rarr,darr,harr,crarr,lArr,uArr,rArr,dArr,hArr,' +
\r
20 'forall,part,exist,empty,nabla,isin,notin,ni,prod,sum,minus,lowast,' +
\r
21 'radic,prop,infin,ang,and,or,cap,cup,int,there4,sim,cong,asymp,ne,' +
\r
22 'equiv,le,ge,sub,sup,nsub,sube,supe,oplus,otimes,perp,sdot,lceil,' +
\r
23 'rceil,lfloor,rfloor,lang,rang,loz,spades,clubs,hearts,diams,' +
\r
25 // Other Special Characters
\r
26 'circ,tilde,ensp,emsp,thinsp,zwnj,zwj,lrm,rlm,ndash,mdash,lsquo,' +
\r
27 'rsquo,sbquo,ldquo,rdquo,bdquo,dagger,Dagger,permil,lsaquo,rsaquo,' +
\r
30 // Latin Letters Entities
\r
32 'Agrave,Aacute,Acirc,Atilde,Auml,Aring,AElig,Ccedil,Egrave,Eacute,' +
\r
33 'Ecirc,Euml,Igrave,Iacute,Icirc,Iuml,ETH,Ntilde,Ograve,Oacute,Ocirc,' +
\r
34 'Otilde,Ouml,Oslash,Ugrave,Uacute,Ucirc,Uuml,Yacute,THORN,szlig,' +
\r
35 'agrave,aacute,acirc,atilde,auml,aring,aelig,ccedil,egrave,eacute,' +
\r
36 'ecirc,euml,igrave,iacute,icirc,iuml,eth,ntilde,ograve,oacute,ocirc,' +
\r
37 'otilde,ouml,oslash,ugrave,uacute,ucirc,uuml,yacute,thorn,yuml,' +
\r
38 'OElig,oelig,Scaron,scaron,Yuml';
\r
40 // Greek Letters Entities.
\r
42 'Alpha,Beta,Gamma,Delta,Epsilon,Zeta,Eta,Theta,Iota,Kappa,Lambda,Mu,' +
\r
43 'Nu,Xi,Omicron,Pi,Rho,Sigma,Tau,Upsilon,Phi,Chi,Psi,Omega,alpha,' +
\r
44 'beta,gamma,delta,epsilon,zeta,eta,theta,iota,kappa,lambda,mu,nu,xi,' +
\r
45 'omicron,pi,rho,sigmaf,sigma,tau,upsilon,phi,chi,psi,omega,thetasym,' +
\r
49 * Create a mapping table between one character and its entity form from a list of entity names.
\r
50 * @param reverse {Boolean} Whether to create a reverse map from the entity string form to an actual character.
\r
52 function buildTable( entities, reverse )
\r
57 // Entities that the browsers DOM don't transform to the final char
\r
61 nbsp : '\u00A0', // IE | FF
\r
62 shy : '\u00AD', // IE
\r
63 gt : '\u003E', // IE | FF | -- | Opera
\r
64 lt : '\u003C', // IE | FF | Safari | Opera
\r
65 amp : '\u0026', // ALL
\r
66 apos : '\u0027', // IE
\r
67 quot : '\u0022' // IE
\r
70 entities = entities.replace( /\b(nbsp|shy|gt|lt|amp|apos|quot)(?:,|$)/g, function( match, entity )
\r
72 var org = reverse ? '&' + entity + ';' : specialTable[ entity ],
\r
73 result = reverse ? specialTable[ entity ] : '&' + entity + ';';
\r
75 table[ org ] = result;
\r
80 if ( !reverse && entities )
\r
82 // Transforms the entities string into an array.
\r
83 entities = entities.split( ',' );
\r
85 // Put all entities inside a DOM element, transforming them to their
\r
87 var div = document.createElement( 'div' ),
\r
89 div.innerHTML = '&' + entities.join( ';&' ) + ';';
\r
90 chars = div.innerHTML;
\r
93 // Add all chars to the table.
\r
94 for ( var i = 0 ; i < chars.length ; i++ )
\r
96 var charAt = chars.charAt( i );
\r
97 table[ charAt ] = '&' + entities[ i ] + ';';
\r
98 regex.push( charAt );
\r
102 table.regex = regex.join( reverse ? '|' : '' );
\r
107 CKEDITOR.plugins.add( 'entities',
\r
109 afterInit : function( editor )
\r
111 var config = editor.config;
\r
113 var dataProcessor = editor.dataProcessor,
\r
114 htmlFilter = dataProcessor && dataProcessor.htmlFilter;
\r
118 // Mandatory HTML base entities.
\r
119 var selectedEntities = [];
\r
121 if ( config.basicEntities !== false )
\r
122 selectedEntities.push( htmlbase );
\r
124 if ( config.entities )
\r
126 if ( selectedEntities.length )
\r
127 selectedEntities.push( entities );
\r
129 if ( config.entities_latin )
\r
130 selectedEntities.push( latin );
\r
132 if ( config.entities_greek )
\r
133 selectedEntities.push( greek );
\r
135 if ( config.entities_additional )
\r
136 selectedEntities.push( config.entities_additional );
\r
139 var entitiesTable = buildTable( selectedEntities.join( ',' ) );
\r
141 // Create the Regex used to find entities in the text, leave it matches nothing if entities are empty.
\r
142 var entitiesRegex = entitiesTable.regex ? '[' + entitiesTable.regex + ']' : 'a^';
\r
143 delete entitiesTable.regex;
\r
145 if ( config.entities && config.entities_processNumerical )
\r
146 entitiesRegex = '[^ -~]|' + entitiesRegex ;
\r
148 entitiesRegex = new RegExp( entitiesRegex, 'g' );
\r
150 function getEntity( character )
\r
152 return config.entities_processNumerical == 'force' || !entitiesTable[ character ] ?
\r
153 '&#' + character.charCodeAt(0) + ';'
\r
154 : entitiesTable[ character ];
\r
157 // Decode entities that the browsers has transformed
\r
159 var baseEntitiesTable = buildTable( [ htmlbase, 'shy' ].join( ',' ) , true ),
\r
160 baseEntitiesRegex = new RegExp( baseEntitiesTable.regex, 'g' );
\r
162 function getChar( character )
\r
164 return baseEntitiesTable[ character ];
\r
167 htmlFilter.addRules(
\r
169 text : function( text )
\r
171 return text.replace( baseEntitiesRegex, getChar )
\r
172 .replace( entitiesRegex, getEntity );
\r
181 * Whether to escape basic HTML entities in the document, including:
\r
183 * <li><code>nbsp</code></li>
\r
184 * <li><code>gt</code></li>
\r
185 * <li><code>lt</code></li>
\r
186 * <li><code>amp</code></li>
\r
188 * <strong>Note:</strong> It should not be subject to change unless when outputting a non-HTML data format like BBCode.
\r
190 * @default <code>true</code>
\r
192 * config.basicEntities = false;
\r
194 CKEDITOR.config.basicEntities = true;
\r
197 * Whether to use HTML entities in the output.
\r
198 * @name CKEDITOR.config.entities
\r
200 * @default <code>true</code>
\r
202 * config.entities = false;
\r
204 CKEDITOR.config.entities = true;
\r
207 * Whether to convert some Latin characters (Latin alphabet No. 1, ISO 8859-1)
\r
208 * to HTML entities. The list of entities can be found in the
\r
209 * <a href="http://www.w3.org/TR/html4/sgml/entities.html#h-24.2.1">W3C HTML 4.01 Specification, section 24.2.1</a>.
\r
210 * @name CKEDITOR.config.entities_latin
\r
212 * @default <code>true</code>
\r
214 * config.entities_latin = false;
\r
216 CKEDITOR.config.entities_latin = true;
\r
219 * Whether to convert some symbols, mathematical symbols, and Greek letters to
\r
220 * HTML entities. This may be more relevant for users typing text written in Greek.
\r
221 * The list of entities can be found in the
\r
222 * <a href="http://www.w3.org/TR/html4/sgml/entities.html#h-24.3.1">W3C HTML 4.01 Specification, section 24.3.1</a>.
\r
223 * @name CKEDITOR.config.entities_greek
\r
225 * @default <code>true</code>
\r
227 * config.entities_greek = false;
\r
229 CKEDITOR.config.entities_greek = true;
\r
232 * Whether to convert all remaining characters not included in the ASCII
\r
233 * character table to their relative decimal numeric representation of HTML entity.
\r
234 * When set to <code>force</code>, it will convert all entities into this format.
\r
235 * For example the phrase "This is Chinese: 汉语." is output
\r
236 * as "This is Chinese: &#27721;&#35821;."
\r
237 * @name CKEDITOR.config.entities_processNumerical
\r
238 * @type Boolean|String
\r
239 * @default <code>false</code>
\r
241 * config.entities_processNumerical = true;
\r
242 * config.entities_processNumerical = 'force'; //Converts from " " into " ";
\r
246 * A comma separated list of additional entities to be used. Entity names
\r
247 * or numbers must be used in a form that excludes the "&" prefix and the ";" ending.
\r
248 * @name CKEDITOR.config.entities_additional
\r
249 * @default <code>'#39'</code> (The single quote (') character.)
\r
252 * config.entities_additional = '#1049'; // Adds Cyrillic capital letter Short I (Й).
\r
254 CKEDITOR.config.entities_additional = '#39';
\r