2 Copyright (c) 2003-2011, 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';
\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 it's entity form from a list of entity names.
\r
50 * @param reverse {Boolean} Whether create a reverse map from the entity string form to 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
67 entities = entities.replace( /\b(nbsp|shy|gt|lt|amp)(?:,|$)/g, function( match, entity )
\r
69 var org = reverse ? '&' + entity + ';' : specialTable[ entity ],
\r
70 result = reverse ? specialTable[ entity ] : '&' + entity + ';';
\r
72 table[ org ] = result;
\r
77 if ( !reverse && entities )
\r
79 // Transforms the entities string into an array.
\r
80 entities = entities.split( ',' );
\r
82 // Put all entities inside a DOM element, transforming them to their
\r
84 var div = document.createElement( 'div' ),
\r
86 div.innerHTML = '&' + entities.join( ';&' ) + ';';
\r
87 chars = div.innerHTML;
\r
90 // Add all chars to the table.
\r
91 for ( var i = 0 ; i < chars.length ; i++ )
\r
93 var charAt = chars.charAt( i );
\r
94 table[ charAt ] = '&' + entities[ i ] + ';';
\r
95 regex.push( charAt );
\r
99 table.regex = regex.join( reverse ? '|' : '' );
\r
104 CKEDITOR.plugins.add( 'entities',
\r
106 afterInit : function( editor )
\r
108 var config = editor.config;
\r
110 var dataProcessor = editor.dataProcessor,
\r
111 htmlFilter = dataProcessor && dataProcessor.htmlFilter;
\r
115 // Mandatory HTML base entities.
\r
116 var selectedEntities = htmlbase;
\r
118 if ( config.entities )
\r
120 selectedEntities += ',' + entities;
\r
121 if ( config.entities_latin )
\r
122 selectedEntities += ',' + latin;
\r
124 if ( config.entities_greek )
\r
125 selectedEntities += ',' + greek;
\r
127 if ( config.entities_additional )
\r
128 selectedEntities += ',' + config.entities_additional;
\r
131 var entitiesTable = buildTable( selectedEntities );
\r
133 // Create the Regex used to find entities in the text.
\r
134 var entitiesRegex = '[' + entitiesTable.regex + ']';
\r
135 delete entitiesTable.regex;
\r
137 if ( config.entities && config.entities_processNumerical )
\r
138 entitiesRegex = '[^ -~]|' + entitiesRegex ;
\r
140 entitiesRegex = new RegExp( entitiesRegex, 'g' );
\r
142 function getEntity( character )
\r
144 return config.entities_processNumerical == 'force' || !entitiesTable[ character ] ?
\r
145 '&#' + character.charCodeAt(0) + ';'
\r
146 : entitiesTable[ character ];
\r
149 // Decode entities that the browsers has transformed
\r
151 var baseEntitiesTable = buildTable( [ htmlbase, 'shy' ].join( ',' ) , true ),
\r
152 baseEntitiesRegex = new RegExp( baseEntitiesTable.regex, 'g' );
\r
154 function getChar( character )
\r
156 return baseEntitiesTable[ character ];
\r
159 htmlFilter.addRules(
\r
161 text : function( text )
\r
163 return text.replace( baseEntitiesRegex, getChar )
\r
164 .replace( entitiesRegex, getEntity );
\r
173 * Whether to use HTML entities in the output.
\r
177 * config.entities = false;
\r
179 CKEDITOR.config.entities = true;
\r
182 * Whether to convert some Latin characters (Latin alphabet No. 1, ISO 8859-1)
\r
183 * to HTML entities. The list of entities can be found at the
\r
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>.
\r
188 * config.entities_latin = false;
\r
190 CKEDITOR.config.entities_latin = true;
\r
193 * Whether to convert some symbols, mathematical symbols, and Greek letters to
\r
194 * HTML entities. This may be more relevant for users typing text written in Greek.
\r
195 * The list of entities can be found at the
\r
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>.
\r
200 * config.entities_greek = false;
\r
202 CKEDITOR.config.entities_greek = true;
\r
205 * Whether to convert all remaining characters, not comprised in the ASCII
\r
206 * character table, to their relative decimal numeric representation of HTML entity.
\r
207 * When specified as the value 'force', it will simply convert all entities into the above form.
\r
208 * For example, the phrase "This is Chinese: 汉语." is outputted
\r
209 * as "This is Chinese: &#27721;&#35821;."
\r
211 * @type Boolean|String
\r
214 * config.entities_processNumerical = true;
\r
215 * config.entities_processNumerical = 'force'; //Convert from " " into " ";
\r
219 * An additional list of entities to be used. It's a string containing each
\r
220 * entry separated by a comma. Entities names or number must be used, exclusing
\r
221 * the "&" preffix and the ";" termination.
\r
222 * @default '#39' // The single quote (') character.
\r
226 CKEDITOR.config.entities_additional = '#39';
\r