marked icon indicating copy to clipboard operation
marked copied to clipboard

Is there a way to white-list specific HTML tags when sanitize is true?

Open AlexAllocated opened this issue 13 years ago • 18 comments

I love the sanitize feature and most markdown libraries don't include it or do it very badly. However, there is one feature that Marked does not have that my previous library did, the ability to white-list specific tags or a default set of tags (see node-markdown). Is it possible to have this added to Marked?

This library is the best javascript markdown library I've seen. The main attraction for me is the ability to use it on the server and on the client so I can generate Markdown previews for the user without making ajax calls or having differences between the client library and the server library. If I can just enable specific tags when sanitize is true that would complete the library for me.

AlexAllocated avatar Mar 07 '13 16:03 AlexAllocated

This should actually be fairly simple. I'll mess around with something.

chjj avatar Mar 30 '13 16:03 chjj

+1

matthewmueller avatar Apr 20 '13 06:04 matthewmueller

+1. This would be fantastic.

martindale avatar Jul 20 '13 15:07 martindale

+1 push

passsy avatar Jul 24 '13 15:07 passsy

+1

jonathanong avatar Sep 20 '13 04:09 jonathanong

+1

AdrianoFerrari avatar Oct 03 '13 13:10 AdrianoFerrari

Seeing as how this isn't in there quite yet I'll try and take a stab at doing it myself sometime this week for you guys. I don't know the code yet so be patient. Hopefully I can figure out how to white-list specific tags and make this the most complete JS markdown library out there :D. I'll link to the fork here when I'm finished.

AlexAllocated avatar Oct 03 '13 14:10 AlexAllocated

yes please, :+1: for whitelist of tags i want to enable markdown for and others (e.g. images using ![text](link) I don't want to support)

Soleone avatar Nov 25 '13 20:11 Soleone

Why exactly was this issue closed? Seems still to be relevant to me!

adius avatar Jul 21 '14 11:07 adius

Wondered that myself. sad face

AlexAllocated avatar Jul 21 '14 12:07 AlexAllocated

Well it's not closed, but it was supposedly simple to implement.

AlexAllocated avatar Jul 21 '14 12:07 AlexAllocated

Oh right, the referenced issue is closed. Got it =P. Well, then I'll just give a +1 cause I'd still like to see this feature implemented! =)

adius avatar Jul 21 '14 12:07 adius

Another +1 on this.

gkoberger avatar Aug 31 '14 04:08 gkoberger

+1

markstos avatar Feb 11 '15 13:02 markstos

This feature would be very useful.

j127 avatar Jul 25 '17 01:07 j127

A workaround is to not use the sanitize feature of Markdown, but instead pass the resulting HTML through a tool that focuses just on HTML sanitizing, like the insane module. It works out being about the same amount of code and configuration, and yes the insane module supports custom whitelists both tags and attributes.

The Markdown spec does not include any notion of HTML sanitizing. Sanitizing is a separate task that is well served by using a separate module.

markstos avatar Jul 25 '17 11:07 markstos

@markstos - thanks

j127 avatar Jul 25 '17 20:07 j127

I think @markstos is correct, using a 3rd party sanitizer is the solution here instead of adding a new feature.

I'm closing this in favor of #1232 which is a discussion about external sanitizers and deprecation of the internal sanitizer.

styfle avatar Aug 20 '18 14:08 styfle