2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
9 var htmlbase = 'nbsp,gt,lt';
13 'quot,iexcl,cent,pound,curren,yen,brvbar,sect,uml,copy,ordf,laquo,' +
14 'not,shy,reg,macr,deg,plusmn,sup2,sup3,acute,micro,para,middot,' +
15 'cedil,sup1,ordm,raquo,frac14,frac12,frac34,iquest,times,divide,' +
18 'fnof,bull,hellip,prime,Prime,oline,frasl,weierp,image,real,trade,' +
19 'alefsym,larr,uarr,rarr,darr,harr,crarr,lArr,uArr,rArr,dArr,hArr,' +
20 'forall,part,exist,empty,nabla,isin,notin,ni,prod,sum,minus,lowast,' +
21 'radic,prop,infin,ang,and,or,cap,cup,int,there4,sim,cong,asymp,ne,' +
22 'equiv,le,ge,sub,sup,nsub,sube,supe,oplus,otimes,perp,sdot,lceil,' +
23 'rceil,lfloor,rfloor,lang,rang,loz,spades,clubs,hearts,diams,' +
25 // Other Special Characters
26 'circ,tilde,ensp,emsp,thinsp,zwnj,zwj,lrm,rlm,ndash,mdash,lsquo,' +
27 'rsquo,sbquo,ldquo,rdquo,bdquo,dagger,Dagger,permil,lsaquo,rsaquo,' +
30 // Latin Letters Entities
32 'Agrave,Aacute,Acirc,Atilde,Auml,Aring,AElig,Ccedil,Egrave,Eacute,' +
33 'Ecirc,Euml,Igrave,Iacute,Icirc,Iuml,ETH,Ntilde,Ograve,Oacute,Ocirc,' +
34 'Otilde,Ouml,Oslash,Ugrave,Uacute,Ucirc,Uuml,Yacute,THORN,szlig,' +
35 'agrave,aacute,acirc,atilde,auml,aring,aelig,ccedil,egrave,eacute,' +
36 'ecirc,euml,igrave,iacute,icirc,iuml,eth,ntilde,ograve,oacute,ocirc,' +
37 'otilde,ouml,oslash,ugrave,uacute,ucirc,uuml,yacute,thorn,yuml,' +
38 'OElig,oelig,Scaron,scaron,Yuml';
40 // Greek Letters Entities.
42 'Alpha,Beta,Gamma,Delta,Epsilon,Zeta,Eta,Theta,Iota,Kappa,Lambda,Mu,' +
43 'Nu,Xi,Omicron,Pi,Rho,Sigma,Tau,Upsilon,Phi,Chi,Psi,Omega,alpha,' +
44 'beta,gamma,delta,epsilon,zeta,eta,theta,iota,kappa,lambda,mu,nu,xi,' +
45 'omicron,pi,rho,sigmaf,sigma,tau,upsilon,phi,chi,psi,omega,thetasym,' +
49 * Create a mapping table between one character and it's entity form from a list of entity names.
50 * @param reverse {Boolean} Whether create a reverse map from the entity string form to actual character.
52 function buildTable( entities, reverse )
57 // Entities that the browsers DOM don't transform to the final char
61 nbsp : '\u00A0', // IE | FF
63 gt : '\u003E', // IE | FF | -- | Opera
64 lt : '\u003C' // IE | FF | Safari | Opera
67 entities = entities.replace( /\b(nbsp|shy|gt|lt|amp)(?:,|$)/g, function( match, entity )
69 var org = reverse ? '&' + entity + ';' : specialTable[ entity ],
70 result = reverse ? specialTable[ entity ] : '&' + entity + ';';
72 table[ org ] = result;
77 if ( !reverse && entities )
79 // Transforms the entities string into an array.
80 entities = entities.split( ',' );
82 // Put all entities inside a DOM element, transforming them to their
84 var div = document.createElement( 'div' ),
86 div.innerHTML = '&' + entities.join( ';&' ) + ';';
87 chars = div.innerHTML;
90 // Add all chars to the table.
91 for ( var i = 0 ; i < chars.length ; i++ )
93 var charAt = chars.charAt( i );
94 table[ charAt ] = '&' + entities[ i ] + ';';
99 table.regex = regex.join( reverse ? '|' : '' );
104 CKEDITOR.plugins.add( 'entities',
106 afterInit : function( editor )
108 var config = editor.config;
110 var dataProcessor = editor.dataProcessor,
111 htmlFilter = dataProcessor && dataProcessor.htmlFilter;
115 // Mandatory HTML base entities.
116 var selectedEntities = htmlbase;
118 if ( config.entities )
120 selectedEntities += ',' + entities;
121 if ( config.entities_latin )
122 selectedEntities += ',' + latin;
124 if ( config.entities_greek )
125 selectedEntities += ',' + greek;
127 if ( config.entities_additional )
128 selectedEntities += ',' + config.entities_additional;
131 var entitiesTable = buildTable( selectedEntities );
133 // Create the Regex used to find entities in the text.
134 var entitiesRegex = '[' + entitiesTable.regex + ']';
135 delete entitiesTable.regex;
137 if ( config.entities && config.entities_processNumerical )
138 entitiesRegex = '[^ -~]|' + entitiesRegex ;
140 entitiesRegex = new RegExp( entitiesRegex, 'g' );
142 function getEntity( character )
144 return config.entities_processNumerical == 'force' || !entitiesTable[ character ] ?
145 '&#' + character.charCodeAt(0) + ';'
146 : entitiesTable[ character ];
149 // Decode entities that the browsers has transformed
151 var baseEntitiesTable = buildTable( [ htmlbase, 'shy' ].join( ',' ) , true ),
152 baseEntitiesRegex = new RegExp( baseEntitiesTable.regex, 'g' );
154 function getChar( character )
156 return baseEntitiesTable[ character ];
161 text : function( text )
163 return text.replace( baseEntitiesRegex, getChar )
164 .replace( entitiesRegex, getEntity );
173 * Whether to use HTML entities in the output.
177 * config.entities = false;
179 CKEDITOR.config.entities = true;
182 * Whether to convert some Latin characters (Latin alphabet No. 1, ISO 8859-1)
183 * to HTML entities. The list of entities can be found at the
184 * <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>.
188 * config.entities_latin = false;
190 CKEDITOR.config.entities_latin = true;
193 * Whether to convert some symbols, mathematical symbols, and Greek letters to
194 * HTML entities. This may be more relevant for users typing text written in Greek.
195 * The list of entities can be found at the
196 * <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>.
200 * config.entities_greek = false;
202 CKEDITOR.config.entities_greek = true;
205 * Whether to convert all remaining characters, not comprised in the ASCII
206 * character table, to their relative decimal numeric representation of HTML entity.
207 * When specified as the value 'force', it will simply convert all entities into the above form.
208 * For example, the phrase "This is Chinese: 汉语." is outputted
209 * as "This is Chinese: &#27721;&#35821;."
211 * @type Boolean|String
214 * config.entities_processNumerical = true;
215 * config.entities_processNumerical = 'force'; //Convert from " " into " ";
219 * An additional list of entities to be used. It's a string containing each
220 * entry separated by a comma. Entities names or number must be used, exclusing
221 * the "&" preffix and the ";" termination.
222 * @default '#39' // The single quote (') character.
226 CKEDITOR.config.entities_additional = '#39';