Ticket #5769: 5769_2.patch
File 5769_2.patch, 5.9 KB (added by , 13 years ago) |
---|
-
_source/plugins/entities/plugin.js
1 /* 1 /* 2 2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. 3 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 4 */ 5 5 6 6 (function() 7 7 { 8 var entities = 9 10 // Base HTML entities. 11 'nbsp,gt,lt,quot,' + 12 8 // Base HTML entities. 9 var htmlbase = 'nbsp,gt,lt,quot'; 10 11 var entities = 13 12 // Latin-1 Entities 14 13 'iexcl,cent,pound,curren,yen,brvbar,sect,uml,copy,ordf,laquo,' + 15 14 'not,shy,reg,macr,deg,plusmn,sup2,sup3,acute,micro,para,middot,' + … … 46 45 'omicron,pi,rho,sigmaf,sigma,tau,upsilon,phi,chi,psi,omega,thetasym,' + 47 46 'upsih,piv'; 48 47 49 function buildTable( entities ) 48 /** 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. 51 */ 52 function buildTable( entities, reverse ) 50 53 { 51 54 var table = {}, 52 55 regex = []; … … 63 66 64 67 entities = entities.replace( /\b(nbsp|shy|gt|lt|amp)(?:,|$)/g, function( match, entity ) 65 68 { 66 table[ specialTable[ entity ] ] = '&' + entity + ';'; 67 regex.push( specialTable[ entity ] ); 69 var org = reverse ? '&' + entity + ';' : specialTable[ entity ], 70 result = reverse ? specialTable[ entity ] : '&' + entity + ';'; 71 72 table[ org ] = result; 73 regex.push( org ); 68 74 return ''; 69 75 }); 70 76 71 // Transforms the entities string into an array. 72 entities = entities.split( ',' ); 77 if ( !reverse ) 78 { 79 // Transforms the entities string into an array. 80 entities = entities.split( ',' ); 73 81 74 // Put all entities inside a DOM element, transforming them to their75 // final chars.76 var div = document.createElement( 'div' ),77 chars;78 div.innerHTML = '&' + entities.join( ';&' ) + ';';79 chars = div.innerHTML;80 div = null;82 // Put all entities inside a DOM element, transforming them to their 83 // final chars. 84 var div = document.createElement( 'div' ), 85 chars; 86 div.innerHTML = '&' + entities.join( ';&' ) + ';'; 87 chars = div.innerHTML; 88 div = null; 81 89 82 // Add all chars to the table. 83 for ( var i = 0 ; i < chars.length ; i++ ) 84 { 85 var charAt = chars.charAt( i ); 86 table[ charAt ] = '&' + entities[ i ] + ';'; 87 regex.push( charAt ); 88 } 90 // Add all chars to the table. 91 for ( var i = 0 ; i < chars.length ; i++ ) 92 { 93 var charAt = chars.charAt( i ); 94 table[ charAt ] = '&' + entities[ i ] + ';'; 95 regex.push( charAt ); 96 } 97 } 89 98 90 table.regex = regex.join( '' );99 table.regex = regex.join( reverse ? '|' : '' ); 91 100 92 101 return table; 93 102 } … … 98 107 { 99 108 var config = editor.config; 100 109 101 if ( !config.entities )102 return;103 104 110 var dataProcessor = editor.dataProcessor, 105 111 htmlFilter = dataProcessor && dataProcessor.htmlFilter; 106 112 107 113 if ( htmlFilter ) 108 114 { 109 var selectedEntities = entities; 115 // Mandatory HTML base entities. 116 var selectedEntities = htmlbase; 110 117 111 if ( config.entities_latin ) 112 selectedEntities += ',' + latin; 118 if ( config.entities ) 119 { 120 selectedEntities += ',' + entities; 121 122 if ( config.entities_latin ) 123 selectedEntities += ',' + latin; 113 124 114 if ( config.entities_greek )115 selectedEntities += ',' + greek;125 if ( config.entities_greek ) 126 selectedEntities += ',' + greek; 116 127 117 if ( config.entities_additional ) 118 selectedEntities += ',' + config.entities_additional; 128 if ( config.entities_additional ) 129 selectedEntities += ',' + config.entities_additional; 130 } 119 131 120 132 var entitiesTable = buildTable( selectedEntities ); 121 133 … … 123 135 var entitiesRegex = '[' + entitiesTable.regex + ']'; 124 136 delete entitiesTable.regex; 125 137 126 if ( config.entities _processNumerical )138 if ( config.entities && config.entities_processNumerical ) 127 139 entitiesRegex = '[^ -~]|' + entitiesRegex ; 128 140 129 141 entitiesRegex = new RegExp( entitiesRegex, 'g' ); 130 142 143 function getEntity( character ) 144 { 145 return config.entities_processNumerical == 'force' || !entitiesTable[ character ] ? 146 '&#' + character.charCodeAt(0) + ';' 147 : entitiesTable[ character ]; 148 } 149 150 // Decode entities that the browsers has transformed 151 // at first place. 152 var baseEntitiesTable = buildTable( [ htmlbase, 'shy' ].join( ',' ) , true ), 153 baseEntitiesRegex = new RegExp( baseEntitiesTable.regex, 'g' ); 154 131 155 function getChar( character ) 132 156 { 133 return entitiesTable[ character ] || ( '&#' + character.charCodeAt(0) + ';' );157 return baseEntitiesTable[ character ]; 134 158 } 135 159 136 160 htmlFilter.addRules( 137 161 { 138 162 text : function( text ) 139 163 { 140 return text.replace( entitiesRegex, getChar ); 164 return text.replace( baseEntitiesRegex, getChar ) 165 .replace( entitiesRegex, getEntity ); 141 166 } 142 167 }); 143 168 } … … 179 204 180 205 /** 181 206 * Whether to convert all remaining characters, not comprised in the ASCII 182 * character table, to their relative numeric representation of HTML entity. 207 * character table, to their relative decimal numeric representation of HTML entity. 208 * When specified as the value 'force', it will simply convert all entities into the above form. 183 209 * For example, the phrase "This is Chinese: 汉语." is outputted 184 210 * as "This is Chinese: &#27721;&#35821;." 185 * @type Boolean 211 * @type Boolean|String 186 212 * @default false 187 213 * @example 188 214 * config.entities_processNumerical = true; 215 * config.entities_processNumerical = 'force'; //Convert from " " into " "; 189 216 */ 190 217 CKEDITOR.config.entities_processNumerical = false; 191 218