Index: trunk/extensions/VisualEditor/modules/es/es.Html.js |
— | — | @@ -0,0 +1,40 @@ |
| 2 | +/** |
| 3 | + * Static object with HTML generation helpers. |
| 4 | + */ |
| 5 | +es.Html = { |
| 6 | + 'escapeText': function( text ) { |
| 7 | + return text |
| 8 | + .replace( /&/g, '&' ) |
| 9 | + .replace( /</g, '<' ) |
| 10 | + .replace( />/g, '>' ) |
| 11 | + .replace( /"/g, '"' ) |
| 12 | + .replace( /'/g, ''' ); |
| 13 | + }, |
| 14 | + 'makeAttributeList': function( attributes, prespace ) { |
| 15 | + var attr = []; |
| 16 | + var name; |
| 17 | + if ( attributes ) { |
| 18 | + for ( name in attributes ) { |
| 19 | + attr.push( name + '="' + attributes[name] + '"' ); |
| 20 | + } |
| 21 | + } |
| 22 | + return ( prespace && attr.length ? ' ' : '' ) + attr.join( ' ' ); |
| 23 | + }, |
| 24 | + 'makeOpeningTag': function( name, attributes ) { |
| 25 | + return '<' + name + es.Html.makeAttributeList( attributes, true ) + '>'; |
| 26 | + }, |
| 27 | + 'makeClosingTag': function( name ) { |
| 28 | + return '</' + name + '>'; |
| 29 | + }, |
| 30 | + 'makeTag': function( name, attributes, value, escape ) { |
| 31 | + if ( value === false ) { |
| 32 | + return '<' + name + es.Html.makeAttributeList( attributes, true ) + ' />'; |
| 33 | + } else { |
| 34 | + if ( escape ) { |
| 35 | + value = wiki.util.xml.esc( value ); |
| 36 | + } |
| 37 | + return '<' + name + es.Html.makeAttributeList( attributes, true ) + '>' + |
| 38 | + value + '</' + name + '>'; |
| 39 | + } |
| 40 | + } |
| 41 | +}; |