I am trying to escape HTML between ''' triple quotes ''' and ' single quotes '.
Here is my code:
import html
import re
#Replace triple backticks with escaped HTML
response = re.sub(r"'''([\s\S]*?)'''", lambda match: "'''" + html.escape(match.group(1)) + "'''", response)
#Replace single quotes with escaped HTML
response = re.sub(r"'(.*?)'", lambda match: "'" + html.escape(match.group(1)) + "'", response)
but the HTML is not escaping and ends up running the actual HTML on the screen.