mw.html

Utility functions for aiding the construction of HTML.

Show:

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

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

...

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

(static) escape(s) → {string}

...

Escape a string for HTML.

Converts special characters to HTML entities.

mw.html.escape( '< > \' & "' );
// Returns &lt; &gt; &#039; &amp; &quot;
Parameters:
Name Type Description
s string

The string to escape

Source:
Returns:

HTML

Type
string