Avatar of Rohit Bajaj
Rohit Bajaj
Flag 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
HTMLJavaScriptjQuery

Avatar of undefined
Last Comment
Ryan Chong

8/22/2022 - Mon
Shaun Vermaak

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

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

Open in new window

Rohit Bajaj

ASKER
but i will need to parse the markdown text and detect script tag...is there any library to do that
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.