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,amp';
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
68 entities
= entities
.replace( /\b(nbsp|shy|gt|lt|amp)(?:,|$)/g, function( match
, entity
)
70 var org
= reverse
? '&' + entity
+ ';' : specialTable
[ entity
],
71 result
= reverse
? specialTable
[ entity
] : '&' + entity
+ ';';
73 table
[ org
] = result
;
78 if ( !reverse
&& entities
)
80 // Transforms the entities string into an array.
81 entities
= entities
.split( ',' );
83 // Put all entities inside a DOM element, transforming them to their
85 var div
= document
.createElement( 'div' ),
87 div
.innerHTML
= '&' + entities
.join( ';&' ) + ';';
88 chars
= div
.innerHTML
;
91 // Add all chars to the table.
92 for ( var i
= 0 ; i
< chars
.length
; i
++ )
94 var charAt
= chars
.charAt( i
);
95 table
[ charAt
] = '&' + entities
[ i
] + ';';
100 table
.regex
= regex
.join( reverse
? '|' : '' );
105 CKEDITOR
.plugins
.add( 'entities',
107 afterInit : function( editor
)
109 var config
= editor
.config
;
111 var dataProcessor
= editor
.dataProcessor
,
112 htmlFilter
= dataProcessor
&& dataProcessor
.htmlFilter
;
116 // Mandatory HTML base entities.
117 var selectedEntities
= '';
119 if ( config
.basicEntities
!== false )
120 selectedEntities
+= htmlbase
;
122 if ( config
.entities
)
124 selectedEntities
+= ',' + entities
;
125 if ( config
.entities_latin
)
126 selectedEntities
+= ',' + latin
;
128 if ( config
.entities_greek
)
129 selectedEntities
+= ',' + greek
;
131 if ( config
.entities_additional
)
132 selectedEntities
+= ',' + config
.entities_additional
;
135 var entitiesTable
= buildTable( selectedEntities
);
137 // Create the Regex used to find entities in the text, leave it matches nothing if entities are empty.
138 var entitiesRegex
= entitiesTable
.regex
? '[' + entitiesTable
.regex
+ ']' : 'a^';
139 delete entitiesTable
.regex
;
141 if ( config
.entities
&& config
.entities_processNumerical
)
142 entitiesRegex
= '[^ -~]|' + entitiesRegex
;
144 entitiesRegex
= new RegExp( entitiesRegex
, 'g' );
146 function getEntity( character
)
148 return config
.entities_processNumerical
== 'force' || !entitiesTable
[ character
] ?
149 '&#' + character
.charCodeAt(0) + ';'
150 : entitiesTable
[ character
];
153 // Decode entities that the browsers has transformed
155 var baseEntitiesTable
= buildTable( [ htmlbase
, 'shy' ].join( ',' ) , true ),
156 baseEntitiesRegex
= new RegExp( baseEntitiesTable
.regex
, 'g' );
158 function getChar( character
)
160 return baseEntitiesTable
[ character
];
165 text : function( text
)
167 return text
.replace( baseEntitiesRegex
, getChar
)
168 .replace( entitiesRegex
, getEntity
);
177 * Whether to escape HTML preserved entities in text, including:
184 * <strong>Note:</strong> It should not be subjected to change unless you're outputting non-HTML data format like BBCode.
188 * config.basicEntities = false;
190 CKEDITOR
.config
.basicEntities
= true;
193 * Whether to use HTML entities in the output.
194 * @name CKEDITOR.config.entities
198 * config.entities = false;
200 CKEDITOR
.config
.entities
= true;
203 * Whether to convert some Latin characters (Latin alphabet No. 1, ISO 8859-1)
204 * to HTML entities. The list of entities can be found at the
205 * <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>.
206 * @name CKEDITOR.config.entities_latin
210 * config.entities_latin = false;
212 CKEDITOR
.config
.entities_latin
= true;
215 * Whether to convert some symbols, mathematical symbols, and Greek letters to
216 * HTML entities. This may be more relevant for users typing text written in Greek.
217 * The list of entities can be found at the
218 * <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>.
219 * @name CKEDITOR.config.entities_greek
223 * config.entities_greek = false;
225 CKEDITOR
.config
.entities_greek
= true;
228 * Whether to convert all remaining characters, not comprised in the ASCII
229 * character table, to their relative decimal numeric representation of HTML entity.
230 * When specified as the value 'force', it will simply convert all entities into the above form.
231 * For example, the phrase "This is Chinese: 汉语." is outputted
232 * as "This is Chinese: &#27721;&#35821;."
233 * @name CKEDITOR.config.entities_processNumerical
234 * @type Boolean|String
237 * config.entities_processNumerical = true;
238 * config.entities_processNumerical = 'force'; //Convert from " " into " ";
242 * An additional list of entities to be used. It's a string containing each
243 * entry separated by a comma. Entities names or number must be used, exclusing
244 * the "&" preffix and the ";" termination.
245 * @name CKEDITOR.config.entities_additional
246 * @default '#39' // The single quote (') character.
250 CKEDITOR
.config
.entities_additional
= '#39';