I’m trying to print out HTML generated for user-submitter markdown, by
{{=markdown(post.message)}}
where markdown function is imported through
from gluon.contrib.markdown.markdown2 import markdown
We2Py seems to automatically encode HTML-Entities, so every < is converted into < and every > is converted into >. How do I prevent this from happening?
Are there any security concerns that I’ll need to keep in mind while doing so? Also, could anyone kindly tell me how can I strip the HTML when storing it in the database, while retaining the markdown?
You have to do this:
every string is sanitized by template render, if you pass
"<div>"it will be rendered as"<div>"it is to protect against malicious code.When you pass a string to
XMLhelperXML("<div>")it uses anXMLparser to render the string in to anXMLtree structure,XMLhas a method.xml()which returns the unescaped string to theresponse.bodyso the user’s browser have the correct html.you can control some parameters of
XMLrendering.