Rohit Bajaj
asked on
How to escape unsafe HTML tags
HI,
I am making a markdown web application where user can type in a markdown and see its equivalent rendering.
The issue is for example if the user types :
<script>alert(10)</script> then on displaying the markdown as html this script will get executed...
I am using marked library to convert raw markdown to HTML
One solution is to remove all unsafe tags.. Other is to escape unsafe HTML tags...
The markdown that github uses... escapes the unsafe tags..
How does it do it ?
Any library or way where i can escape the unsafe HTML tags ?
This has to done using a js /jquery library...etc..
Thanks
I am making a markdown web application where user can type in a markdown and see its equivalent rendering.
The issue is for example if the user types :
<script>alert(10)</script>
I am using marked library to convert raw markdown to HTML
One solution is to remove all unsafe tags.. Other is to escape unsafe HTML tags...
The markdown that github uses... escapes the unsafe tags..
How does it do it ?
Any library or way where i can escape the unsafe HTML tags ?
This has to done using a js /jquery library...etc..
Thanks
Can you not use <pre></pre>?
<!-- (anything in here is treated as a comment -->
ASKER
but i will need to parse the markdown text and detect script tag...is there any library to do that
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.