Shared method for encoding HTML special chars.

By default don't double encode already existing HTML chars. by
@DarkSide666. Adaptation of 0522eeef6cf474214ac3b1105682bfdac868600d
from Master branch.