2 * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
7 // Basic HTML entities.
8 var htmlbase
= 'nbsp,gt,lt,amp';
12 'quot,iexcl,cent,pound,curren,yen,brvbar,sect,uml,copy,ordf,laquo,' +
13 'not,shy,reg,macr,deg,plusmn,sup2,sup3,acute,micro,para,middot,' +
14 'cedil,sup1,ordm,raquo,frac14,frac12,frac34,iquest,times,divide,' +
17 'fnof,bull,hellip,prime,Prime,oline,frasl,weierp,image,real,trade,' +
18 'alefsym,larr,uarr,rarr,darr,harr,crarr,lArr,uArr,rArr,dArr,hArr,' +
19 'forall,part,exist,empty,nabla,isin,notin,ni,prod,sum,minus,lowast,' +
20 'radic,prop,infin,ang,and,or,cap,cup,int,there4,sim,cong,asymp,ne,' +
21 'equiv,le,ge,sub,sup,nsub,sube,supe,oplus,otimes,perp,sdot,lceil,' +
22 'rceil,lfloor,rfloor,lang,rang,loz,spades,clubs,hearts,diams,' +
24 // Other special characters
25 'circ,tilde,ensp,emsp,thinsp,zwnj,zwj,lrm,rlm,ndash,mdash,lsquo,' +
26 'rsquo,sbquo,ldquo,rdquo,bdquo,dagger,Dagger,permil,lsaquo,rsaquo,' +
29 // Latin letters entities
30 var latin
= 'Agrave,Aacute,Acirc,Atilde,Auml,Aring,AElig,Ccedil,Egrave,Eacute,' +
31 'Ecirc,Euml,Igrave,Iacute,Icirc,Iuml,ETH,Ntilde,Ograve,Oacute,Ocirc,' +
32 'Otilde,Ouml,Oslash,Ugrave,Uacute,Ucirc,Uuml,Yacute,THORN,szlig,' +
33 'agrave,aacute,acirc,atilde,auml,aring,aelig,ccedil,egrave,eacute,' +
34 'ecirc,euml,igrave,iacute,icirc,iuml,eth,ntilde,ograve,oacute,ocirc,' +
35 'otilde,ouml,oslash,ugrave,uacute,ucirc,uuml,yacute,thorn,yuml,' +
36 'OElig,oelig,Scaron,scaron,Yuml';
38 // Greek letters entities.
39 var greek
= 'Alpha,Beta,Gamma,Delta,Epsilon,Zeta,Eta,Theta,Iota,Kappa,Lambda,Mu,' +
40 'Nu,Xi,Omicron,Pi,Rho,Sigma,Tau,Upsilon,Phi,Chi,Psi,Omega,alpha,' +
41 'beta,gamma,delta,epsilon,zeta,eta,theta,iota,kappa,lambda,mu,nu,xi,' +
42 'omicron,pi,rho,sigmaf,sigma,tau,upsilon,phi,chi,psi,omega,thetasym,' +
45 // Create a mapping table between one character and its entity form from a list of entity names.
46 // @param reverse {Boolean} Whether to create a reverse map from the entity string form to an actual character.
47 function buildTable( entities
, reverse
) {
51 // Entities that the browsers' DOM does not automatically transform to the
54 nbsp: '\u00A0', // IE | FF
56 gt: '\u003E', // IE | FF | -- | Opera
57 lt: '\u003C', // IE | FF | Safari | Opera
63 entities
= entities
.replace( /\b(nbsp|shy|gt|lt|amp|apos|quot)(?:,|$)/g, function( match
, entity
) {
64 var org
= reverse
? '&' + entity
+ ';' : specialTable
[ entity
],
65 result
= reverse
? specialTable
[ entity
] : '&' + entity
+ ';';
67 table
[ org
] = result
;
72 if ( !reverse
&& entities
) {
73 // Transforms the entities string into an array.
74 entities
= entities
.split( ',' );
76 // Put all entities inside a DOM element, transforming them to their
78 var div
= document
.createElement( 'div' ),
80 div
.innerHTML
= '&' + entities
.join( ';&' ) + ';';
81 chars
= div
.innerHTML
;
84 // Add all characters to the table.
85 for ( var i
= 0; i
< chars
.length
; i
++ ) {
86 var charAt
= chars
.charAt( i
);
87 table
[ charAt
] = '&' + entities
[ i
] + ';';
92 table
.regex
= regex
.join( reverse
? '|' : '' );
97 CKEDITOR
.plugins
.add( 'entities', {
98 afterInit: function( editor
) {
99 var config
= editor
.config
;
101 function getChar( character
) {
102 return baseEntitiesTable
[ character
];
105 function getEntity( character
) {
106 return config
.entities_processNumerical
== 'force' || !entitiesTable
[ character
] ? '&#' + character
.charCodeAt( 0 ) + ';'
107 : entitiesTable
[ character
];
110 var dataProcessor
= editor
.dataProcessor
,
111 htmlFilter
= dataProcessor
&& dataProcessor
.htmlFilter
;
114 // Mandatory HTML basic entities.
115 var selectedEntities
= [];
117 if ( config
.basicEntities
!== false )
118 selectedEntities
.push( htmlbase
);
120 if ( config
.entities
) {
121 if ( selectedEntities
.length
)
122 selectedEntities
.push( entities
);
124 if ( config
.entities_latin
)
125 selectedEntities
.push( latin
);
127 if ( config
.entities_greek
)
128 selectedEntities
.push( greek
);
130 if ( config
.entities_additional
)
131 selectedEntities
.push( config
.entities_additional
);
134 var entitiesTable
= buildTable( selectedEntities
.join( ',' ) );
136 // Create the Regex used to find entities in the text, leave it matches nothing if entities are empty.
137 var entitiesRegex
= entitiesTable
.regex
? '[' + entitiesTable
.regex
+ ']' : 'a^';
138 delete entitiesTable
.regex
;
140 if ( config
.entities
&& config
.entities_processNumerical
)
141 entitiesRegex
= '[^ -~]|' + entitiesRegex
;
143 entitiesRegex
= new RegExp( entitiesRegex
, 'g' );
145 // Decode entities that the browsers has transformed
147 var baseEntitiesTable
= buildTable( [ htmlbase
, 'shy' ].join( ',' ), true ),
148 baseEntitiesRegex
= new RegExp( baseEntitiesTable
.regex
, 'g' );
150 htmlFilter
.addRules( {
151 text: function( text
) {
152 return text
.replace( baseEntitiesRegex
, getChar
).replace( entitiesRegex
, getEntity
);
156 excludeNestedEditable: true
164 * Whether to escape basic HTML entities in the document, including:
171 * **Note:** This option should not be changed unless when outputting a non-HTML data format like BBCode.
173 * config.basicEntities = false;
175 * @cfg {Boolean} [basicEntities=true]
176 * @member CKEDITOR.config
178 CKEDITOR
.config
.basicEntities
= true;
181 * Whether to use HTML entities in the editor output.
183 * config.entities = false;
185 * @cfg {Boolean} [entities=true]
186 * @member CKEDITOR.config
188 CKEDITOR
.config
.entities
= true;
191 * Whether to convert some Latin characters (Latin alphabet No. 1, ISO 8859-1)
192 * to HTML entities. The list of entities can be found in the
193 * [W3C HTML 4.01 Specification, section 24.2.1](http://www.w3.org/TR/html4/sgml/entities.html#h-24.2.1).
195 * config.entities_latin = false;
197 * @cfg {Boolean} [entities_latin=true]
198 * @member CKEDITOR.config
200 CKEDITOR
.config
.entities_latin
= true;
203 * Whether to convert some symbols, mathematical symbols, and Greek letters to
204 * HTML entities. This may be more relevant for users typing text written in Greek.
205 * The list of entities can be found in the
206 * [W3C HTML 4.01 Specification, section 24.3.1](http://www.w3.org/TR/html4/sgml/entities.html#h-24.3.1).
208 * config.entities_greek = false;
210 * @cfg {Boolean} [entities_greek=true]
211 * @member CKEDITOR.config
213 CKEDITOR
.config
.entities_greek
= true;
216 * Whether to convert all remaining characters not included in the ASCII
217 * character table to their relative decimal numeric representation of HTML entity.
218 * When set to `force`, it will convert all entities into this format.
220 * For example the phrase: `'This is Chinese: 汉语.'` would be output
221 * as: `'This is Chinese: 汉语.'`
223 * config.entities_processNumerical = true;
224 * config.entities_processNumerical = 'force'; // Converts from ' ' into ' ';
226 * @cfg {Boolean/String} [entities_processNumerical=false]
227 * @member CKEDITOR.config
231 * A comma-separated list of additional entities to be used. Entity names
232 * or numbers must be used in a form that excludes the `'&'` prefix and the `';'` ending.
234 * config.entities_additional = '#1049'; // Adds Cyrillic capital letter Short I (Й).
236 * @cfg {String} [entities_additional='#39' (The single quote (') character)]
237 * @member CKEDITOR.config
239 CKEDITOR
.config
.entities_additional
= '#39';