mw.html

HTML construction helper functions.

Source:

Example

var Html, output;

Html = mw.html;
output = Html.element( 'div', {}, new Html.Raw(
    Html.element( 'img', { src: '<' } )
) );
mw.log( output ); // <div><img src="&lt;"/></div>

Classes

Raw

Methods

element(name, attrsopt, contentsopt) → {string}static #

Create an HTML element string, with safe escaping.

Parameters:

Name Type Attributes Default Description
name string

The tag name.

attrs Object <optional>

An object with members mapping element names to values

contents string | mw.html.Raw | null <optional>
null

The contents of the element.

  • string: Text to be escaped.
  • null: The element is treated as void with short closing form, e.g. <br/>.
  • this.Raw: The raw value is directly included.
Source:

Returns:

HTML

Type
string
Create an HTML element string, with safe escaping.

escape(s) → {string}static #

Escape a string for HTML.

Converts special characters to HTML entities.

Example

mw.html.escape( '< > \' & "' );
// Returns &lt; &gt; &#039; &amp; &quot;

Parameters:

Name Type Description
s string

The string to escape

Source:

Returns:

HTML

Type
string
Escape a string for HTML.