Module:DecodeEncode/doc explained

Implements Lua functions mw.text.decode, mw.text.encode in a module.

<nowiki>{{#invoke:decodeEncode|decode|s=Source&amp;nbsp;text&amp;copy;}}</nowiki><nowiki>Source&nbsp;text&copy;</nowiki>

See List of XML and HTML character entity references.

Decode (→ ©)

Decodes Named Entities from entity name into a regular (unicode) character:

&amp;copy;&copy;

&amp;gt;>

All well-defined named entities are decoded (HTML Named character references, formally: as defined in the PHP table).

A regular, rendered sentence:

"At 100 °F, & with a "burning" sun above, we, we ⁄walked⁄."

In code:

"At 100&amp;nbsp;&amp;deg;F, &amp; with a &amp;quot;burning&amp;quot; sun above, we &amp;frasl;walked&amp;frasl;." -- wikitext

Processing:

<nowiki>{{#invoke:decodeEncode|decode|s=At 100&nbsp;&deg;F, &amp; with a &quot;burning&quot; sun above, we &frasl;walked&frasl;.}}</nowiki>

{{#invoke:decodeEncode|decode|s=At 100&nbsp;&deg;F, &amp; with a &quot;burning&quot; sun above, we &frasl;walked&frasl;.}} -- In code: straight characters, no named entities.

Renders, again:

"At 100 °F, & with a "burning" sun above, we ⁄walked⁄."

Decode a reduced set only

By setting, only these five entity names are decoded: '&lt;', '&gt;', '&amp;', '&quot;', '&nbsp;' (that is, into '<', '>', '&', '"', ' ').

Note: There is a difference with the relevant Lua parameter. (This only concerns your task if you also work directly with the Lua mw.text.decode function). Lua documentation defines parameter, having this effect: when omitted or false, only the reduced set of entities is recognized and decoded. This use of 'false' is inverted in using : = .

Also, this module ignores the "omitted" logic: should be set explicitly to 'true' to be effective.

Encode (© →)

Function encode encodes some entity-named characters into that name (for example: &&amp;amp;).

Regular sentence:

"At >100 °F, & with a "burning" sun above, we walked. ©"

In code:

"<nowiki>At >100 °F, & with a "burning" sun above, we walked. ©</nowiki>"

Encode:

<nowiki>{{#invoke:decodeEncode|encode|s=At >100 °F, & with a "burning" sun above, we walked. ©|charset=&<>{{!}}°"'&©}}</nowiki>

<nowiki>At &amp;gt;100 &amp;#176;F, &amp;amp; with a &amp;quot;burning&amp;quot; sun above, we walked. &amp;#169;</nowiki>

Renders as:

"At >100 °F, & with a "burning" sun above, we walked. ©"

character set to encode

Per Lua documentation, only a small set of characters is processed. The characterset can be set (expanded) by using .

Example: