lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Oct 13, 2013, at 9:45 PM, Chris Datfung <chris.datfung@gmail.com> wrote:

> Are there any Lua libraries available that handle HTML encoding (not URL
> encoding) a variable?

HTML encoding? You mean converting into &lt;, &gt;, &quot; and &amp;  or numerical equivalent? Perhaps a simple gsub would do, no?

function Encode( aValue )
    local anEncoder = function( aValue ) 
        return ( '&#%02d;' ):format( aValue:byte() ) 
    end
    
    return ( tostring( aValue or '' ):gsub( '([<>&\'"])', anEncoder ) )
end

Or do you mean something else?