Module:DecodeEncode

require('strict')local p = {}local function _getBoolean( boolean_str )-- from: module:String; adapted-- requires an explicit truelocal boolean_valueif type( boolean_str ) == 'string' thenboolean_str = boolean_str:lower()if boolean_str == 'true' or boolean_str == 'yes' or boolean_str == '1' thenboolean_value = trueelseboolean_value = falseendelseif type( boolean_str ) == 'boolean' thenboolean_value = boolean_strelseboolean_value = falseendreturn boolean_valueendfunction p.decode( frame )local s = frame.args['s'] or ''local subset_only = _getBoolean(frame.args['subset_only'] or false)return p._decode( s, subset_only )endfunction p._decode( s, subset_only )-- U+2009 THIN SPACE: workaround for bug: HTML entity &thinsp; is decoded incorrect. Entity &ThinSpace; gets decoded properlys = mw.ustring.gsub( s, '&thinsp;', '&ThinSpace;' )-- U+03B5 ε GREEK SMALL LETTER EPSILON: workaround for bug (phab:T328840): HTML entity &epsilon; is decoded incorrect for gsub(). Entity &epsi; gets decoded properlys = mw.ustring.gsub( s, '&epsilon;', '&epsi;' )local ret = mw.text.decode( s, not subset_only )return retendfunction p.encode( frame )local s = frame.args['s'] or ''local charset = frame.args['charset']return p._encode( s, charset )endfunction p._encode( s, charset )-- example: charset = '_&©−°\\\"\'\=' -- do escape with backslash not %;local retif charset and charset ~= '' thenret = mw.text.encode( s, charset )else-- use default: chartset = '<>&"\' ' (outer quotes = lua required; space = NBSP)ret = mw.text.encode( s )end return retendreturn p