Extend escape option for user-defined functions

Allows the use of a user-defined custom escaping function to be passed
into the 'escape' option, adds a unit test, and updates the
documentation.