[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: HTML Encoding
- From: Petite Abeille <petite.abeille@...>
- Date: Sun, 13 Oct 2013 22:24:08 +0200
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 <, >, " and & 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?