Implements Lua functions mw.text.decode, mw.text.encode in a module.
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| This Lua module is used on approximately 148,000 pages. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
Implements Lua functions mw.text.decode, mw.text.encode in a module.
{{#invoke:decodeEncode|decode|s=Source text©}} → Source text©See List of XML and HTML character entity references.
© → ©> → >All well-defined named entities are decoded (HTML Named character references, formally: as defined in the PHP table).
At 100 °F, & with a "burning" sun above, we ⁄walked⁄." -- wikitext{{#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.By setting |subset_only=true, only these five entity names are decoded: '<', '>', '&', '"', ' ' (that is, into '<', '>', '&', '"', ' ').
|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.|subset_only= should be set explicitly to 'true' to be effective.encode encodes some entity-named characters into that name (for example: & → &).Regular sentence:
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 >100 °F, & with a "burning" sun above, we walked. ©Per Lua documentation, only a small set of characters is processed. The characterset can be set (expanded) by using |charset=.
|charset=<>" \'& (the default), |charset=<>°"'&©{{!}}; characters not in the default will be replaced by their decimal entity: © → © (hexadecimal number, not decimal nor named ©)  works, but   doesn't.Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.