-
Notifications
You must be signed in to change notification settings - Fork 1
/
Markdown.Sanitizer.min.js
13 lines (13 loc) · 1.43 KB
/
Markdown.Sanitizer.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
// Markdown sanitizer
// ** Some changes've been made to support youtube video
!function(){function r(r){return r.replace(/<[^>]*>?/gi,t)}function t(r){return r.match(o)||r.match(s)||r.match(a)||r.match(c)?r:""}function e(r){if(""==r)return""
var t=/<\/?\w+[^>]*(\s|$|>)/g,e=r.toLowerCase().match(t),i=(e||[]).length
if(0==i)return r
for(var n,o,s,a="<p><img><br><li><hr>",c=[],h=[],f=!1,u=0;i>u;u++)if(n=e[u].replace(/<\/?(\w+).*/,"$1"),!(c[u]||a.search("<"+n+">")>-1)){if(o=e[u],s=-1,!/^<\//.test(o))for(var p=u+1;i>p;p++)if(!c[p]&&e[p]=="</"+n+">"){s=p
break}-1==s?f=h[u]=!0:c[s]=!0}if(!f)return r
var u=0
return r=r.replace(t,function(r){var t=h[u]?"":r
return u++,t})}var i,n
"object"==typeof exports&&"function"==typeof require?(i=exports,n=require("./Markdown.Converter").Converter):(i=window.Markdown,n=i.Converter),i.getSanitizingConverter=function(){var t=new n
return t.hooks.chain("postConversion",r),t.hooks.chain("postConversion",e),t}
var o=/^(<\/?(b|blockquote|code|del|dd|dl|dt|em|h1|h2|h3|i|kbd|li|ol(?: start="\d+")?|p|pre|s|sup|sub|strong|strike|ul)>|<(br|hr)\s?\/?>)$/i,s=/^(<a\shref="((https?|ftp):\/\/|\/)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)*[\]$]+"(\stitle="[^"<>]+")?\s?>|<\/a>)$/i,a=/^(<img\ssrc="(https?:\/\/|\/)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)*[\]$]+"(\swidth="\d{1,3}")?(\sheight="\d{1,3}")?(\salt="[^"<>]*")?(\stitle="[^"<>]*")?\s?\/?>)$/i,c=/^(<iframe\ssrc="(https?:\/\/|\/)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)*[\]$]+"?\s?>|<\/iframe>)$/i}();