JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.0
[ckeditor.git] / _source / plugins / entities / plugin.js
diff --git a/_source/plugins/entities/plugin.js b/_source/plugins/entities/plugin.js
new file mode 100644 (file)
index 0000000..73d85c1
--- /dev/null
@@ -0,0 +1,200 @@
+/*\r
+Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+For licensing, see LICENSE.html or http://ckeditor.com/license\r
+*/\r
+\r
+(function()\r
+{\r
+       var entities =\r
+\r
+               // Base HTML entities.\r
+               'nbsp,gt,lt,quot,' +\r
+\r
+               // Latin-1 Entities\r
+               'iexcl,cent,pound,curren,yen,brvbar,sect,uml,copy,ordf,laquo,' +\r
+               'not,shy,reg,macr,deg,plusmn,sup2,sup3,acute,micro,para,middot,' +\r
+               'cedil,sup1,ordm,raquo,frac14,frac12,frac34,iquest,times,divide,' +\r
+\r
+               // Symbols\r
+               'fnof,bull,hellip,prime,Prime,oline,frasl,weierp,image,real,trade,' +\r
+               'alefsym,larr,uarr,rarr,darr,harr,crarr,lArr,uArr,rArr,dArr,hArr,' +\r
+               'forall,part,exist,empty,nabla,isin,notin,ni,prod,sum,minus,lowast,' +\r
+               'radic,prop,infin,ang,and,or,cap,cup,int,there4,sim,cong,asymp,ne,' +\r
+               'equiv,le,ge,sub,sup,nsub,sube,supe,oplus,otimes,perp,sdot,lceil,' +\r
+               'rceil,lfloor,rfloor,lang,rang,loz,spades,clubs,hearts,diams,' +\r
+\r
+               // Other Special Characters\r
+               'circ,tilde,ensp,emsp,thinsp,zwnj,zwj,lrm,rlm,ndash,mdash,lsquo,' +\r
+               'rsquo,sbquo,ldquo,rdquo,bdquo,dagger,Dagger,permil,lsaquo,rsaquo,' +\r
+               'euro';\r
+\r
+       // Latin Letters Entities\r
+       var latin =\r
+               'Agrave,Aacute,Acirc,Atilde,Auml,Aring,AElig,Ccedil,Egrave,Eacute,' +\r
+               'Ecirc,Euml,Igrave,Iacute,Icirc,Iuml,ETH,Ntilde,Ograve,Oacute,Ocirc,' +\r
+               'Otilde,Ouml,Oslash,Ugrave,Uacute,Ucirc,Uuml,Yacute,THORN,szlig,' +\r
+               'agrave,aacute,acirc,atilde,auml,aring,aelig,ccedil,egrave,eacute,' +\r
+               'ecirc,euml,igrave,iacute,icirc,iuml,eth,ntilde,ograve,oacute,ocirc,' +\r
+               'otilde,ouml,oslash,ugrave,uacute,ucirc,uuml,yacute,thorn,yuml,' +\r
+               'OElig,oelig,Scaron,scaron,Yuml';\r
+\r
+       // Greek Letters Entities.\r
+       var greek =\r
+               'Alpha,Beta,Gamma,Delta,Epsilon,Zeta,Eta,Theta,Iota,Kappa,Lambda,Mu,' +\r
+               'Nu,Xi,Omicron,Pi,Rho,Sigma,Tau,Upsilon,Phi,Chi,Psi,Omega,alpha,' +\r
+               'beta,gamma,delta,epsilon,zeta,eta,theta,iota,kappa,lambda,mu,nu,xi,' +\r
+               'omicron,pi,rho,sigmaf,sigma,tau,upsilon,phi,chi,psi,omega,thetasym,' +\r
+               'upsih,piv';\r
+\r
+       function buildTable( entities )\r
+       {\r
+               var table = {},\r
+                       regex = [];\r
+\r
+               // Entities that the browsers DOM don't transform to the final char\r
+               // automatically.\r
+               var specialTable =\r
+                       {\r
+                               nbsp    : '\u00A0',             // IE | FF\r
+                               shy             : '\u00AD',             // IE\r
+                               gt              : '\u003E',             // IE | FF |   --   | Opera\r
+                               lt              : '\u003C'              // IE | FF | Safari | Opera\r
+                       };\r
+\r
+               entities = entities.replace( /\b(nbsp|shy|gt|lt|amp)(?:,|$)/g, function( match, entity )\r
+                       {\r
+                               table[ specialTable[ entity ] ] = '&' + entity + ';';\r
+                               regex.push( specialTable[ entity ] );\r
+                               return '';\r
+                       });\r
+\r
+               // Transforms the entities string into an array.\r
+               entities = entities.split( ',' );\r
+\r
+               // Put all entities inside a DOM element, transforming them to their\r
+               // final chars.\r
+               var div = document.createElement( 'div' ),\r
+                       chars;\r
+               div.innerHTML = '&' + entities.join( ';&' ) + ';';\r
+               chars = div.innerHTML;\r
+               div = null;\r
+\r
+               // Add all chars to the table.\r
+               for ( var i = 0 ; i < chars.length ; i++ )\r
+               {\r
+                       var charAt = chars.charAt( i );\r
+                       table[ charAt ] = '&' + entities[ i ] + ';';\r
+                       regex.push( charAt );\r
+               }\r
+\r
+               table.regex = regex.join( '' );\r
+\r
+               return table;\r
+       }\r
+\r
+       CKEDITOR.plugins.add( 'entities',\r
+       {\r
+               afterInit : function( editor )\r
+               {\r
+                       var config = editor.config;\r
+\r
+                       if ( !config.entities )\r
+                               return;\r
+\r
+                       var dataProcessor = editor.dataProcessor,\r
+                               htmlFilter = dataProcessor && dataProcessor.htmlFilter;\r
+\r
+                       if ( htmlFilter )\r
+                       {\r
+                               var selectedEntities = entities;\r
+\r
+                               if ( config.entities_latin )\r
+                                       selectedEntities += ',' + latin;\r
+\r
+                               if ( config.entities_greek )\r
+                                       selectedEntities += ',' + greek;\r
+\r
+                               if ( config.entities_additional )\r
+                                       selectedEntities += ',' + config.entities_additional;\r
+\r
+                               var entitiesTable = buildTable( selectedEntities );\r
+\r
+                               // Create the Regex used to find entities in the text.\r
+                               var entitiesRegex = '[' + entitiesTable.regex + ']';\r
+                               delete entitiesTable.regex;\r
+\r
+                               if ( config.entities_processNumerical )\r
+                                       entitiesRegex = '[^ -~]|' + entitiesRegex ;\r
+\r
+                               entitiesRegex = new RegExp( entitiesRegex, 'g' );\r
+\r
+                               function getChar( character )\r
+                               {\r
+                                       return entitiesTable[ character ] || ( '&#' + character.charCodeAt(0) + ';' );\r
+                               }\r
+\r
+                               htmlFilter.addRules(\r
+                                       {\r
+                                               text : function( text )\r
+                                               {\r
+                                                       return text.replace( entitiesRegex, getChar );\r
+                                               }\r
+                                       });\r
+                       }\r
+               }\r
+       });\r
+})();\r
+\r
+/**\r
+ * Whether to use HTML entities in the output.\r
+ * @type Boolean\r
+ * @default true\r
+ * @example\r
+ * config.entities = false;\r
+ */\r
+CKEDITOR.config.entities = true;\r
+\r
+/**\r
+ * Whether to convert some Latin characters (Latin alphabet No&#46; 1, ISO 8859-1)\r
+ * to HTML entities. The list of entities can be found at the\r
+ * <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
+ * @type Boolean\r
+ * @default true\r
+ * @example\r
+ * config.entities_latin = false;\r
+ */\r
+CKEDITOR.config.entities_latin = true;\r
+\r
+/**\r
+ * Whether to convert some symbols, mathematical symbols, and Greek letters to\r
+ * HTML entities. This may be more relevant for users typing text written in Greek.\r
+ * The list of entities can be found at the\r
+ * <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
+ * @type Boolean\r
+ * @default true\r
+ * @example\r
+ * config.entities_greek = false;\r
+ */\r
+CKEDITOR.config.entities_greek = true;\r
+\r
+/**\r
+ * Whether to convert all remaining characters, not comprised in the ASCII\r
+ * character table, to their relative numeric representation of HTML entity.\r
+ * For example, the phrase "This is Chinese: &#27721;&#35821;." is outputted\r
+ * as "This is Chinese: &amp;#27721;&amp;#35821;."\r
+ * @type Boolean\r
+ * @default false\r
+ * @example\r
+ * config.entities_processNumerical = true;\r
+ */\r
+CKEDITOR.config.entities_processNumerical = false;\r
+\r
+/**\r
+ * An additional list of entities to be used. It's a string containing each\r
+ * entry separated by a comma. Entities names or number must be used, exclusing\r
+ * the "&amp;" preffix and the ";" termination.\r
+ * @default '#39'  // The single quote (') character.\r
+ * @type String\r
+ * @example\r
+ */\r
+CKEDITOR.config.entities_additional = '#39';\r