mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 14:56:20 +00:00
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
|
/**
|
||
|
* Static object with HTML generation helpers.
|
||
|
*/
|
||
|
es.Html = {
|
||
|
'escapeText': function( text ) {
|
||
|
return text
|
||
|
.replace( /&/g, '&' )
|
||
|
.replace( /</g, '<' )
|
||
|
.replace( />/g, '>' )
|
||
|
.replace( /"/g, '"' )
|
||
|
.replace( /'/g, ''' );
|
||
|
},
|
||
|
'makeAttributeList': function( attributes, prespace ) {
|
||
|
var attr = [];
|
||
|
var name;
|
||
|
if ( attributes ) {
|
||
|
for ( name in attributes ) {
|
||
|
attr.push( name + '="' + attributes[name] + '"' );
|
||
|
}
|
||
|
}
|
||
|
return ( prespace && attr.length ? ' ' : '' ) + attr.join( ' ' );
|
||
|
},
|
||
|
'makeOpeningTag': function( name, attributes ) {
|
||
|
return '<' + name + es.Html.makeAttributeList( attributes, true ) + '>';
|
||
|
},
|
||
|
'makeClosingTag': function( name ) {
|
||
|
return '</' + name + '>';
|
||
|
},
|
||
|
'makeTag': function( name, attributes, value, escape ) {
|
||
|
if ( value === false ) {
|
||
|
return '<' + name + es.Html.makeAttributeList( attributes, true ) + ' />';
|
||
|
} else {
|
||
|
if ( escape ) {
|
||
|
value = wiki.util.xml.esc( value );
|
||
|
}
|
||
|
return '<' + name + es.Html.makeAttributeList( attributes, true ) + '>' +
|
||
|
value + '</' + name + '>';
|
||
|
}
|
||
|
}
|
||
|
};
|