Ticket #5769: 5769_3.patch
File 5769_3.patch, 5.5 KB (added by , 13 years ago) |
---|
-
_source/plugins/entities/plugin.js
5 5 6 6 (function() 7 7 { 8 var entities = 9 10 // Base HTML entities. 11 'nbsp,gt,lt,quot,' + 8 // Base HTML entities. 9 var htmlbase = 'nbsp,gt,lt,quot'; 12 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 if ( config.entities_latin ) 122 selectedEntities += ',' + latin; 113 123 114 if ( config.entities_greek )115 selectedEntities += ',' + greek;124 if ( config.entities_greek ) 125 selectedEntities += ',' + greek; 116 126 117 if ( config.entities_additional ) 118 selectedEntities += ',' + config.entities_additional; 127 if ( config.entities_additional ) 128 selectedEntities += ',' + config.entities_additional; 129 } 119 130 120 131 var entitiesTable = buildTable( selectedEntities ); 121 132 … … 123 134 var entitiesRegex = '[' + entitiesTable.regex + ']'; 124 135 delete entitiesTable.regex; 125 136 126 if ( config.entities _processNumerical )137 if ( config.entities && config.entities_processNumerical ) 127 138 entitiesRegex = '[^ -~]|' + entitiesRegex ; 128 139 129 140 entitiesRegex = new RegExp( entitiesRegex, 'g' ); 130 141 142 function getEntity( character ) 143 { 144 return config.entities_processNumerical == 'force' || !entitiesTable[ character ] ? 145 '&#' + character.charCodeAt(0) + ';' 146 : entitiesTable[ character ]; 147 } 148 149 // Decode entities that the browsers has transformed 150 // at first place. 151 var baseEntitiesTable = buildTable( [ htmlbase, 'shy' ].join( ',' ) , true ), 152 baseEntitiesRegex = new RegExp( baseEntitiesTable.regex, 'g' ); 153 131 154 function getChar( character ) 132 155 { 133 return entitiesTable[ character ] || ( '&#' + character.charCodeAt(0) + ';' );156 return baseEntitiesTable[ character ]; 134 157 } 135 158 136 159 htmlFilter.addRules( 137 160 { 138 161 text : function( text ) 139 162 { 140 return text.replace( entitiesRegex, getChar ); 163 return text.replace( baseEntitiesRegex, getChar ) 164 .replace( entitiesRegex, getEntity ); 141 165 } 142 166 }); 143 167 } … … 179 203 180 204 /** 181 205 * Whether to convert all remaining characters, not comprised in the ASCII 182 * character table, to their relative numeric representation of HTML entity. 206 * character table, to their relative decimal numeric representation of HTML entity. 207 * When specified as the value 'force', it will simply convert all entities into the above form. 183 208 * For example, the phrase "This is Chinese: 汉语." is outputted 184 209 * as "This is Chinese: &#27721;&#35821;." 185 210 * @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