Module:DecodeEncode/doc: Difference between revisions
Appearance
From Wikipedia, the free encyclopedia
Line 33:
Line 33:
:Function <code>encode</code> encodes some entity-named characters into that name (for example: <code>&</code> → <code>&amp;</code>).
:Function <code>encode</code> encodes some entity-named characters into that name (for example: <code>&</code> → <code>&amp;</code>).
(追記) Regular (追記ここまで) sentence:
⚫
:"At >100 °F, & with a "burning" sun above, we walked(追記) . (追記ここまで) ©|charset=&<>{{!}}°"'&©"
In code:
⚫
:<code><nowiki>(追記) {{#invoke:decodeEncode|encode|s=:" (追記ここまで){{#invoke:decodeEncode|encode|s=At >100 °F, & with a "burning" sun above, we walked(追記) . (追記ここまで) ©(追記) |charset=&<>{{!}}°"'&©}}" (追記ここまで)|charset=&<>{{!}}°"'&©}}</nowiki></code>
⚫
:(削除) <code> (削除ここまで)"(削除) {{#invoke:decodeEncode|encode|s= (削除ここまで)At >100 °F, & with a "burning" sun above, we walked ©|charset=&<>{{!}}°"'&©(削除) }} (削除ここまで)"(削除) </code>; to process: (削除ここまで)
⚫
:<code><nowiki>{{#invoke:decodeEncode|encode|s=At >100 °F, & with a "burning" sun above, we walked ©|charset=&<>{{!}}°"'&©}}</nowiki></code>
::→ "<code>At 100 °F, &amp; with a &quot;burning&quot; sun above, we walked</code>" -- in code
::→ "<code>At 100 °F, &amp; with a &quot;burning&quot; sun above, we walked</code>" -- in code
;Per Lua documentation, only a small set of characters is processed. The charset can be set ({{para|charset}}). Format:
;Per Lua documentation, only a small set of characters is processed. The charset can be set ({{para|charset}}). Format:
Revision as of 00:06, 26 December 2020
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.
Implements Lua functions mw.text.decode, mw.text.encode in a module.
{{#invoke:decode|s=Source text}}
→Source text
See List of XML and HTML character entity references.
Decode (© → ©)
- Decodes Named Entities from entity name into a regular (unicode) character:
©
→©
>
→>
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 walked"
- In code:
- "
At 100 °F, & with a "burning" sun above, we walked
"-- in code
- "
- 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: no named entities
Decode a reduced set only
By setting |subset_only=true
, only these five entity names are decoded: '<', '>', '&', '"', ' ' (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 (© → ©)
- Function
encode
encodes some entity-named characters into that name (for example:&
→&
).
Regular sentence:
- "At >100 °F, & with a "burning" sun above, we walked. ©|charset=&<>|°"'&©"
In code:
{{#invoke:decodeEncode|encode|s=:"{{#invoke:decodeEncode|encode|s=At >100 °F, & with a "burning" sun above, we walked. ©|charset=&<>{{!}}°"'&©}}"|charset=&<>{{!}}°"'&©}}
- → "
At 100 °F, & with a "burning" sun above, we walked
" -- in code
- → "
- Per Lua documentation, only a small set of characters is processed. The charset can be set (
|charset=
). Format - Use escape character is '
\
' (backslash; not "%" then). Example:|charset=<>" \'&
(the default),|charset=<>\|\°\"\'\&©
; characters not in the default will be replaced by their decimal entity:©
→©
(hexadecimal number, not decimal nor named ©)
Template
As of Dec 2020[update] , there are no tempates implementing this module.