2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
10 // Base HTML entities.
\r
11 'nbsp,gt,lt,quot,' +
\r
14 'iexcl,cent,pound,curren,yen,brvbar,sect,uml,copy,ordf,laquo,' +
\r
15 'not,shy,reg,macr,deg,plusmn,sup2,sup3,acute,micro,para,middot,' +
\r
16 'cedil,sup1,ordm,raquo,frac14,frac12,frac34,iquest,times,divide,' +
\r
19 'fnof,bull,hellip,prime,Prime,oline,frasl,weierp,image,real,trade,' +
\r
20 'alefsym,larr,uarr,rarr,darr,harr,crarr,lArr,uArr,rArr,dArr,hArr,' +
\r
21 'forall,part,exist,empty,nabla,isin,notin,ni,prod,sum,minus,lowast,' +
\r
22 'radic,prop,infin,ang,and,or,cap,cup,int,there4,sim,cong,asymp,ne,' +
\r
23 'equiv,le,ge,sub,sup,nsub,sube,supe,oplus,otimes,perp,sdot,lceil,' +
\r
24 'rceil,lfloor,rfloor,lang,rang,loz,spades,clubs,hearts,diams,' +
\r
26 // Other Special Characters
\r
27 'circ,tilde,ensp,emsp,thinsp,zwnj,zwj,lrm,rlm,ndash,mdash,lsquo,' +
\r
28 'rsquo,sbquo,ldquo,rdquo,bdquo,dagger,Dagger,permil,lsaquo,rsaquo,' +
\r
31 // Latin Letters Entities
\r
33 'Agrave,Aacute,Acirc,Atilde,Auml,Aring,AElig,Ccedil,Egrave,Eacute,' +
\r
34 'Ecirc,Euml,Igrave,Iacute,Icirc,Iuml,ETH,Ntilde,Ograve,Oacute,Ocirc,' +
\r
35 'Otilde,Ouml,Oslash,Ugrave,Uacute,Ucirc,Uuml,Yacute,THORN,szlig,' +
\r
36 'agrave,aacute,acirc,atilde,auml,aring,aelig,ccedil,egrave,eacute,' +
\r
37 'ecirc,euml,igrave,iacute,icirc,iuml,eth,ntilde,ograve,oacute,ocirc,' +
\r
38 'otilde,ouml,oslash,ugrave,uacute,ucirc,uuml,yacute,thorn,yuml,' +
\r
39 'OElig,oelig,Scaron,scaron,Yuml';
\r
41 // Greek Letters Entities.
\r
43 'Alpha,Beta,Gamma,Delta,Epsilon,Zeta,Eta,Theta,Iota,Kappa,Lambda,Mu,' +
\r
44 'Nu,Xi,Omicron,Pi,Rho,Sigma,Tau,Upsilon,Phi,Chi,Psi,Omega,alpha,' +
\r
45 'beta,gamma,delta,epsilon,zeta,eta,theta,iota,kappa,lambda,mu,nu,xi,' +
\r
46 'omicron,pi,rho,sigmaf,sigma,tau,upsilon,phi,chi,psi,omega,thetasym,' +
\r
49 function buildTable( entities )
\r
54 // Entities that the browsers DOM don't transform to the final char
\r
58 nbsp : '\u00A0', // IE | FF
\r
59 shy : '\u00AD', // IE
\r
60 gt : '\u003E', // IE | FF | -- | Opera
\r
61 lt : '\u003C' // IE | FF | Safari | Opera
\r
64 entities = entities.replace( /\b(nbsp|shy|gt|lt|amp)(?:,|$)/g, function( match, entity )
\r
66 table[ specialTable[ entity ] ] = '&' + entity + ';';
\r
67 regex.push( specialTable[ entity ] );
\r
71 // Transforms the entities string into an array.
\r
72 entities = entities.split( ',' );
\r
74 // Put all entities inside a DOM element, transforming them to their
\r
76 var div = document.createElement( 'div' ),
\r
78 div.innerHTML = '&' + entities.join( ';&' ) + ';';
\r
79 chars = div.innerHTML;
\r
82 // Add all chars to the table.
\r
83 for ( var i = 0 ; i < chars.length ; i++ )
\r
85 var charAt = chars.charAt( i );
\r
86 table[ charAt ] = '&' + entities[ i ] + ';';
\r
87 regex.push( charAt );
\r
90 table.regex = regex.join( '' );
\r
95 CKEDITOR.plugins.add( 'entities',
\r
97 afterInit : function( editor )
\r
99 var config = editor.config;
\r
101 if ( !config.entities )
\r
104 var dataProcessor = editor.dataProcessor,
\r
105 htmlFilter = dataProcessor && dataProcessor.htmlFilter;
\r
109 var selectedEntities = entities;
\r
111 if ( config.entities_latin )
\r
112 selectedEntities += ',' + latin;
\r
114 if ( config.entities_greek )
\r
115 selectedEntities += ',' + greek;
\r
117 if ( config.entities_additional )
\r
118 selectedEntities += ',' + config.entities_additional;
\r
120 var entitiesTable = buildTable( selectedEntities );
\r
122 // Create the Regex used to find entities in the text.
\r
123 var entitiesRegex = '[' + entitiesTable.regex + ']';
\r
124 delete entitiesTable.regex;
\r
126 if ( config.entities_processNumerical )
\r
127 entitiesRegex = '[^ -~]|' + entitiesRegex ;
\r
129 entitiesRegex = new RegExp( entitiesRegex, 'g' );
\r
131 function getChar( character )
\r
133 return entitiesTable[ character ] || ( '&#' + character.charCodeAt(0) + ';' );
\r
136 htmlFilter.addRules(
\r
138 text : function( text )
\r
140 return text.replace( entitiesRegex, getChar );
\r
149 * Whether to use HTML entities in the output.
\r
153 * config.entities = false;
\r
155 CKEDITOR.config.entities = true;
\r
158 * Whether to convert some Latin characters (Latin alphabet No. 1, ISO 8859-1)
\r
159 * to HTML entities. The list of entities can be found at the
\r
160 * <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
164 * config.entities_latin = false;
\r
166 CKEDITOR.config.entities_latin = true;
\r
169 * Whether to convert some symbols, mathematical symbols, and Greek letters to
\r
170 * HTML entities. This may be more relevant for users typing text written in Greek.
\r
171 * The list of entities can be found at the
\r
172 * <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
176 * config.entities_greek = false;
\r
178 CKEDITOR.config.entities_greek = true;
\r
181 * Whether to convert all remaining characters, not comprised in the ASCII
\r
182 * character table, to their relative numeric representation of HTML entity.
\r
183 * For example, the phrase "This is Chinese: 汉语." is outputted
\r
184 * as "This is Chinese: &#27721;&#35821;."
\r
188 * config.entities_processNumerical = true;
\r
190 CKEDITOR.config.entities_processNumerical = false;
\r
193 * An additional list of entities to be used. It's a string containing each
\r
194 * entry separated by a comma. Entities names or number must be used, exclusing
\r
195 * the "&" preffix and the ";" termination.
\r
196 * @default '#39' // The single quote (') character.
\r
200 CKEDITOR.config.entities_additional = '#39';
\r