<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.pttlink.org/index.php?action=history&amp;feed=atom&amp;title=Module%3ADecodeEncode%2Fdoc</id>
	<title>Module:DecodeEncode/doc - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pttlink.org/index.php?action=history&amp;feed=atom&amp;title=Module%3ADecodeEncode%2Fdoc"/>
	<link rel="alternate" type="text/html" href="https://wiki.pttlink.org/index.php?title=Module:DecodeEncode/doc&amp;action=history"/>
	<updated>2026-05-04T22:54:34Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://wiki.pttlink.org/index.php?title=Module:DecodeEncode/doc&amp;diff=5927&amp;oldid=prev</id>
		<title>Kg7qin: Created page with &quot;{{Module rating |general}}  &lt;!-- Please place categories where indicated at the bottom of this page and interwikis at Wikidata (see Wikipedia:Wikidata) --&gt; Implements Lua...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.pttlink.org/index.php?title=Module:DecodeEncode/doc&amp;diff=5927&amp;oldid=prev"/>
		<updated>2022-01-20T23:03:01Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Module rating |general}}  &amp;lt;!-- Please place categories where indicated at the bottom of this page and interwikis at Wikidata (see &lt;a href=&quot;https://en.wikipedia.org/wiki/Wikidata&quot; class=&quot;extiw&quot; title=&quot;wikipedia:Wikidata&quot;&gt;Wikipedia:Wikidata&lt;/a&gt;) --&amp;gt; Implements Lua...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Module rating |general}} &lt;br /&gt;
&amp;lt;!-- Please place categories where indicated at the bottom of this page and interwikis at Wikidata (see [[Wikipedia:Wikidata]]) --&amp;gt;&lt;br /&gt;
Implements Lua functions [[:mw:Extension:Scribunto/Lua_reference_manual#mw.text.decode|mw.text.decode]], [[:mw:Extension:Scribunto/Lua_reference_manual#mw.text.encode|mw.text.encode]] in a module.&lt;br /&gt;
:&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#invoke:decodeEncode|decode|s=Source&amp;amp;amp;nbsp;text}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; &amp;amp;rarr; &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;Source&amp;amp;nbsp;text&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See [[List of XML and HTML character entity references]].&lt;br /&gt;
&lt;br /&gt;
== Decode (&amp;amp;amp;copy; &amp;amp;rarr; ©) ==&lt;br /&gt;
: '''Note 2021-09-26: Possible bug: Decoding &amp;lt;code&amp;gt;&amp;amp;amp;ThinSpace;&amp;lt;/code&amp;gt; works, but &amp;lt;code&amp;gt;&amp;amp;amp;thinsp;&amp;lt;/code&amp;gt; doesn't.'''&lt;br /&gt;
:Decodes [[List of XML and HTML character entity references|Named Entities]] ''from'' entity name ''into'' a regular (unicode) character:&lt;br /&gt;
:&amp;lt;code&amp;gt;&amp;amp;amp;copy;&amp;lt;/code&amp;gt; &amp;amp;rarr; &amp;lt;code&amp;gt;&amp;amp;copy;&amp;lt;/code&amp;gt;&lt;br /&gt;
:&amp;lt;code&amp;gt;&amp;amp;amp;gt;&amp;lt;/code&amp;gt; &amp;amp;rarr; &amp;lt;code&amp;gt;&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All welldefined named entities are decoded ([https://html.spec.whatwg.org/multipage/named-characters.html#named-character-references HTML Named character references], formally: as defined in the [https://www.php.net/get_html_translation_table PHP table]).&lt;br /&gt;
&lt;br /&gt;
:A regular, rendered sentence:&lt;br /&gt;
::&amp;quot;At 100 °F, &amp;amp; with a &amp;quot;burning&amp;quot; sun above, we , we ⁄walked⁄.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
:In code:&lt;br /&gt;
::&amp;quot;&amp;lt;code&amp;gt;At 100&amp;amp;amp;nbsp;&amp;amp;amp;deg;F, &amp;amp;amp; with a &amp;amp;amp;quot;burning&amp;amp;amp;quot; sun above, we &amp;amp;amp;frasl;walked&amp;amp;amp;frasl;.&amp;lt;/code&amp;gt;&amp;quot; -- wikitext&lt;br /&gt;
&lt;br /&gt;
:Processing:&lt;br /&gt;
:&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#invoke:decodeEncode|decode|s=At 100&amp;amp;nbsp;&amp;amp;deg;F, &amp;amp;amp; with a &amp;amp;quot;burning&amp;amp;quot; sun above, we &amp;amp;frasl;walked&amp;amp;frasl;.}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; &amp;amp;rarr;&lt;br /&gt;
::&amp;lt;code&amp;gt;{{#invoke:decodeEncode|decode|s=At 100&amp;amp;nbsp;&amp;amp;deg;F, &amp;amp;amp; with a &amp;amp;quot;burning&amp;amp;quot; sun above, we &amp;amp;frasl;walked&amp;amp;frasl;.}}&amp;lt;/code&amp;gt; -- In code: straight characters, no named entities.&lt;br /&gt;
&lt;br /&gt;
:Renders, again:&lt;br /&gt;
::&amp;quot;At 100 °F, &amp;amp; with a &amp;quot;burning&amp;quot; sun above, we ⁄walked⁄.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Decode a reduced set only===&lt;br /&gt;
By setting {{para|subset_only|true}}, only these five entity names are decoded: '&amp;amp;amp;lt;', '&amp;amp;amp;gt;', '&amp;amp;amp;amp;', '&amp;amp;amp;quot;', '&amp;amp;amp;nbsp;' (that is, into '&amp;amp;lt;', '&amp;amp;gt;', '&amp;amp;amp;', '&amp;amp;quot;', '&amp;amp;nbsp;').&lt;br /&gt;
&lt;br /&gt;
:'''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 {{para|decodeNamedEntities}}, 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 {{para|subset_only}}: {{para|decodeNamedEntities|false}} =  {{para|subset_only|true}}.&lt;br /&gt;
&lt;br /&gt;
:Also, this module ignores the &amp;quot;omitted&amp;quot; logic: {{para|subset_only}} should be set explicitly to 'true' to be effective.&lt;br /&gt;
&lt;br /&gt;
== Encode (© &amp;amp;rarr; &amp;amp;amp;copy;) ==&lt;br /&gt;
:Function &amp;lt;code&amp;gt;encode&amp;lt;/code&amp;gt; encodes some entity-named characters into that name (for example: &amp;lt;code&amp;gt;&amp;amp;&amp;lt;/code&amp;gt; &amp;amp;rarr; &amp;lt;code&amp;gt;&amp;amp;amp;amp;&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Regular sentence:&lt;br /&gt;
:&amp;quot;At &amp;gt;100 °F, &amp;amp; with a &amp;quot;burning&amp;quot; sun above, we walked. ©&amp;quot;&lt;br /&gt;
&lt;br /&gt;
In code:&lt;br /&gt;
:&amp;quot;&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;At &amp;gt;100 °F, &amp;amp; with a &amp;quot;burning&amp;quot; sun above, we walked. ©&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Encode:&lt;br /&gt;
:&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#invoke:decodeEncode|encode|s=At &amp;gt;100 °F, &amp;amp; with a &amp;quot;burning&amp;quot; sun above, we walked. ©|charset=&amp;amp;&amp;lt;&amp;gt;{{!}}°&amp;quot;'&amp;amp;©}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;amp;rarr;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;At &amp;amp;amp;gt;100 &amp;amp;amp;#176;F, &amp;amp;amp;amp; with a &amp;amp;amp;quot;burning&amp;amp;amp;quot; sun above, we walked. &amp;amp;amp;#169;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;!-- used Special:ExpandTemplate --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:Renders as:&lt;br /&gt;
&lt;br /&gt;
:&amp;quot;At &amp;amp;gt;100 &amp;amp;#176;F, &amp;amp;amp; with a &amp;amp;quot;burning&amp;amp;quot; sun above, we walked. &amp;amp;#169;&amp;quot;&lt;br /&gt;
===character set to encode===&lt;br /&gt;
&lt;br /&gt;
Per Lua documentation, only a small set of characters is processed. The characterset can be set (expanded) by using {{para|charset}}.&lt;br /&gt;
&lt;br /&gt;
:Example: {{para|charset|&amp;lt;nowiki&amp;gt;&amp;lt;&amp;gt;&amp;quot; \'&amp;amp;&amp;lt;/nowiki&amp;gt;}} (the default), {{para|charset|&amp;lt;nowiki&amp;gt;&amp;lt;&amp;gt;°&amp;quot;'&amp;amp;©{{!}}&amp;lt;/nowiki&amp;gt;}}; characters not in the default will be replaced by their decimal entity: &amp;lt;code&amp;gt;©&amp;lt;/code&amp;gt; &amp;amp;rarr; &amp;lt;code&amp;gt;&amp;amp;amp;#169;&amp;lt;/code&amp;gt; &amp;lt;small&amp;gt;(hexadecimal number, not decimal nor named &amp;amp;amp;copy;)&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Template==&lt;br /&gt;
'''NOTE: 2021-09-13: The encode function with user-supplied charset is now used productively  in {{tl|R/superscript}} and {{tl|R/ref}}. Before implementing breaking changes here, these templates need to be adjusted accordingly!'''&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[:mw:Extension:Scribunto/Lua_reference_manual#mw.text.decode|mw.text.decode]]&lt;br /&gt;
&lt;br /&gt;
* [[:mw:Extension:Scribunto/Lua_reference_manual#mw.text.encode|mw.text.encode]]&lt;br /&gt;
{{Navbox wikitext-handling templates}}&lt;br /&gt;
* [[:Module:Urldecode]]&lt;br /&gt;
&amp;lt;includeonly&amp;gt;{{sandbox other||&lt;br /&gt;
&amp;lt;!-- Categories below this line, please; interwikis at Wikidata --&amp;gt;&lt;br /&gt;
[[Category:Wikitext processing templates]]&lt;br /&gt;
[[Category:Modules that manipulate strings]]&lt;br /&gt;
&lt;br /&gt;
}}&amp;lt;/includeonly&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kg7qin</name></author>
	</entry>
</feed>