Jump to content
Wikipedia The Free Encyclopedia

Module:DecodeEncode/doc: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Line 1: Line 1:
{{Module rating |pre-alpha<!-- Values: pre-alpha • alpha • beta • release • protected -- If a rating not needed/relevant, delete this template call -->}}
{{Module rating |pre-alpha<!-- Values: pre-alpha • alpha • beta • release • protected -- If a rating not needed/relevant, delete this template call -->}}(追記) (追記ここまで)
'''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!'''

<!-- Please place categories where indicated at the bottom of this page and interwikis at Wikidata (see [[Wikipedia:Wikidata]]) -->
<!-- Please place categories where indicated at the bottom of this page and interwikis at Wikidata (see [[Wikipedia:Wikidata]]) -->
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.
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.
Line 60: Line 62:
==Template==
==Template==
{{As of|Dec 2020}}, there are no tempates implementing this module.
{{As of|Dec 2020}}, there are no tempates implementing this module.

'''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!'''


==See also==
==See also==

Revision as of 12:13, 13 September 2021

This module is rated as pre-alpha. It is incomplete and may or may not be in active development. Do not use it in article namespace pages. A module remains in pre-alpha until its developer, or another editor who adopts it if it is abandoned for some time, considers the basic structure complete.

NOTE: 2021年09月13日: The encode function with user-supplied charset is now used productively in {{R/superscript }} and {{R/ref }}. Before implementing breaking changes here, these templates need to be adjusted accordingly!

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

{{#invoke:decode|s=Source&nbsp;text}}Source text

See List of XML and HTML character entity references.

Decode (&copy; → ©)

Decodes Named Entities from entity name into a regular (unicode) character:
&copy;©
&gt;>

All welldefined 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&nbsp;&deg;F, & with a &quot;burning&quot; sun above, we &frasl;walked&frasl;." -- wikitext
Processing:
{{#invoke:decodeEncode|decode|s=At 100 °F, & with a "burning" sun above, we ⁄walked⁄.}}
At 100 °F, & with a "burning" sun above, we ⁄walked⁄. -- 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 |subset_only=true, 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 |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 |subset_only=: |decodeNamedEntities=false = |subset_only=true.
Also, this module ignores the "omitted" logic: |subset_only= should be set explicitly to 'true' to be effective.

Encode (© → &copy;)

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

Regular sentence:

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

In code:

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

Encode:

{{#invoke:decodeEncode|encode|s=At >100 °F, & with a "burning" sun above, we walked. ©|charset=&<>{{!}}°"'&©}}
At &gt;100 &#176;F, &amp; with a &quot;burning&quot; sun above, we walked. &#169;
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 |charset=.

Example: |charset=<>" \'& (the default), |charset=<>°"'&©{{!}}; characters not in the default will be replaced by their decimal entity: ©&#169; (hexadecimal number, not decimal nor named &copy;)

Template

As of Dec 2020[update] , there are no tempates implementing this module.

NOTE: 2021年09月13日: The encode function with user-supplied charset is now used productively in {{R/superscript }} and {{R/ref }}. Before implementing breaking changes here, these templates need to be adjusted accordingly!

See also

AltStyle によって変換されたページ (->オリジナル) /