Link to home
Start Free TrialLog in
Avatar of Rohit Bajaj
Rohit BajajFlag for India

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
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Can you not use <pre></pre>?
Avatar of Dr. Klahn
Dr. Klahn

<!-- (anything in here is treated as a comment -->

Open in new window

Avatar of Rohit Bajaj

ASKER

but i will need to parse the markdown text and detect script tag...is there any library to do that
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial