mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
parent
fb923cdb78
commit
dcaaa9b5dc
16
html.go
16
html.go
|
@ -168,10 +168,24 @@ func (options *Html) BlockHtml(out *bytes.Buffer, text []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
doubleSpace(out)
|
doubleSpace(out)
|
||||||
out.Write(text)
|
if options.flags&HTML_SKIP_SCRIPT != 0 {
|
||||||
|
out.Write(stripTag(string(text), "script", "p"))
|
||||||
|
} else {
|
||||||
|
out.Write(text)
|
||||||
|
}
|
||||||
out.WriteByte('\n')
|
out.WriteByte('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is a trivial implementation for the simplest possible case
|
||||||
|
func stripTag(text, tag, newTag string) []byte {
|
||||||
|
openTag := fmt.Sprintf("<%s>", tag)
|
||||||
|
closeTag := fmt.Sprintf("</%s>", tag)
|
||||||
|
openNewTag := fmt.Sprintf("<%s>", newTag)
|
||||||
|
closeNewTag := fmt.Sprintf("</%s>", newTag)
|
||||||
|
noOpen := strings.Replace(text, openTag, openNewTag, -1)
|
||||||
|
return []byte(strings.Replace(noOpen, closeTag, closeNewTag, -1))
|
||||||
|
}
|
||||||
|
|
||||||
func (options *Html) HRule(out *bytes.Buffer) {
|
func (options *Html) HRule(out *bytes.Buffer) {
|
||||||
doubleSpace(out)
|
doubleSpace(out)
|
||||||
out.WriteString("<hr")
|
out.WriteString("<hr")
|
||||||
|
|
|
@ -82,6 +82,9 @@ func TestRawHtmlTag(t *testing.T) {
|
||||||
|
|
||||||
" <script>alert()</script>\n",
|
" <script>alert()</script>\n",
|
||||||
"<p>alert()</p>\n",
|
"<p>alert()</p>\n",
|
||||||
|
|
||||||
|
"<script>alert()</script>\n",
|
||||||
|
"<p>alert()</p>\n",
|
||||||
}
|
}
|
||||||
doTestsInlineParam(t, tests, 0, HTML_SKIP_STYLE|HTML_SKIP_SCRIPT)
|
doTestsInlineParam(t, tests, 0, HTML_SKIP_STYLE|HTML_SKIP_SCRIPT)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user