0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-26 00:52:46 +01:00
This commit is contained in:
Unknwon 2015-11-20 01:52:11 -05:00
parent 902b578465
commit 9b6c835715

View file

@ -231,9 +231,15 @@ func RenderRawMarkdown(body []byte, urlPrefix string) []byte {
return body return body
} }
var (
leftAngleBracket = []byte("</")
rightAngleBracket = []byte(">")
)
// PostProcessMarkdown treats different types of HTML differently, // PostProcessMarkdown treats different types of HTML differently,
// and only renders special links for plain text blocks. // and only renders special links for plain text blocks.
func PostProcessMarkdown(rawHtml []byte, urlPrefix string) []byte { func PostProcessMarkdown(rawHtml []byte, urlPrefix string) []byte {
var startTag string
var buf bytes.Buffer var buf bytes.Buffer
tokenizer := html.NewTokenizer(bytes.NewReader(rawHtml)) tokenizer := html.NewTokenizer(bytes.NewReader(rawHtml))
for html.ErrorToken != tokenizer.Next() { for html.ErrorToken != tokenizer.Next() {
@ -243,6 +249,7 @@ func PostProcessMarkdown(rawHtml []byte, urlPrefix string) []byte {
buf.Write(RenderSpecialLink([]byte(token.String()), urlPrefix)) buf.Write(RenderSpecialLink([]byte(token.String()), urlPrefix))
case html.StartTagToken: case html.StartTagToken:
startTag = token.Data
buf.WriteString(token.String()) buf.WriteString(token.String())
tagName := token.Data tagName := token.Data
// If this is an excluded tag, we skip processing all output until a close tag is encountered. // If this is an excluded tag, we skip processing all output until a close tag is encountered.
@ -258,6 +265,10 @@ func PostProcessMarkdown(rawHtml []byte, urlPrefix string) []byte {
} }
} }
case html.EndTagToken:
buf.Write(leftAngleBracket)
buf.WriteString(startTag)
buf.Write(rightAngleBracket)
default: default:
buf.WriteString(token.String()) buf.WriteString(token.String())
} }