mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
Add an option to strip <script> elements
Partially addresses issue #11.
This commit is contained in:
parent
b79e720a36
commit
fb923cdb78
4
html.go
4
html.go
|
@ -28,6 +28,7 @@ const (
|
||||||
HTML_SKIP_STYLE // skip embedded <style> elements
|
HTML_SKIP_STYLE // skip embedded <style> elements
|
||||||
HTML_SKIP_IMAGES // skip embedded images
|
HTML_SKIP_IMAGES // skip embedded images
|
||||||
HTML_SKIP_LINKS // skip all links
|
HTML_SKIP_LINKS // skip all links
|
||||||
|
HTML_SKIP_SCRIPT // skip embedded <script> elements
|
||||||
HTML_SAFELINK // only link to trusted protocols
|
HTML_SAFELINK // only link to trusted protocols
|
||||||
HTML_TOC // generate a table of contents
|
HTML_TOC // generate a table of contents
|
||||||
HTML_OMIT_CONTENTS // skip the main contents (for a standalone table of contents)
|
HTML_OMIT_CONTENTS // skip the main contents (for a standalone table of contents)
|
||||||
|
@ -460,6 +461,9 @@ func (options *Html) RawHtmlTag(out *bytes.Buffer, text []byte) {
|
||||||
if options.flags&HTML_SKIP_IMAGES != 0 && isHtmlTag(text, "img") {
|
if options.flags&HTML_SKIP_IMAGES != 0 && isHtmlTag(text, "img") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if options.flags&HTML_SKIP_SCRIPT != 0 && isHtmlTag(text, "script") {
|
||||||
|
return
|
||||||
|
}
|
||||||
out.Write(text)
|
out.Write(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,8 +70,20 @@ func TestRawHtmlTag(t *testing.T) {
|
||||||
|
|
||||||
"zz <STYLE>p {}</STYLE>\n",
|
"zz <STYLE>p {}</STYLE>\n",
|
||||||
"<p>zz p {}</p>\n",
|
"<p>zz p {}</p>\n",
|
||||||
|
|
||||||
|
"<SCRIPT>alert()</SCRIPT>\n",
|
||||||
|
"<p>alert()</p>\n",
|
||||||
|
|
||||||
|
"zz <SCRIPT>alert()</SCRIPT>\n",
|
||||||
|
"<p>zz alert()</p>\n",
|
||||||
|
|
||||||
|
"zz <script>alert()</script>\n",
|
||||||
|
"<p>zz alert()</p>\n",
|
||||||
|
|
||||||
|
" <script>alert()</script>\n",
|
||||||
|
"<p>alert()</p>\n",
|
||||||
}
|
}
|
||||||
doTestsInlineParam(t, tests, 0, HTML_SKIP_STYLE)
|
doTestsInlineParam(t, tests, 0, HTML_SKIP_STYLE|HTML_SKIP_SCRIPT)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmphasis(t *testing.T) {
|
func TestEmphasis(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user