diff --git a/modules/markup/html_codepreview.go b/modules/markup/html_codepreview.go index e668b38702968..cfef2f9ab0d39 100644 --- a/modules/markup/html_codepreview.go +++ b/modules/markup/html_codepreview.go @@ -70,10 +70,13 @@ func codePreviewPatternProcessor(ctx *RenderContext, node *html.Node) { continue } next := node.NextSibling - nodeText := node.Data - node.Data = nodeText[:urlPosStart] + textBefore := node.Data[:urlPosStart] + textAfter := node.Data[urlPosEnd:] + node.Data = textBefore node.Parent.InsertBefore(&html.Node{Type: html.RawNode, Data: string(h)}, next) - node.Parent.InsertBefore(&html.Node{Type: html.TextNode, Data: nodeText[urlPosEnd:]}, next) + if textAfter != "" { + node.Parent.InsertBefore(&html.Node{Type: html.TextNode, Data: textAfter}, next) + } node = next } } diff --git a/modules/markup/sanitizer.go b/modules/markup/sanitizer.go index ce7e97727c540..77fbdf4520fc6 100644 --- a/modules/markup/sanitizer.go +++ b/modules/markup/sanitizer.go @@ -65,6 +65,7 @@ func createDefaultPolicy() *bluemonday.Policy { policy.AllowAttrs("class").Matching(regexp.MustCompile(`^lines-num$`)).OnElements("td") policy.AllowAttrs("data-line-number").OnElements("span") policy.AllowAttrs("class").Matching(regexp.MustCompile(`^lines-code chroma$`)).OnElements("td") + policy.AllowAttrs("class").Matching(regexp.MustCompile(`^code-inner$`)).OnElements("code") // For code preview (unicode escape) policy.AllowAttrs("class").Matching(regexp.MustCompile(`^file-view( unicode-escaped)?$`)).OnElements("table") diff --git a/templates/base/markup_codepreview.tmpl b/templates/base/markup_codepreview.tmpl index 91b3842a305ca..f95581688cdbe 100644 --- a/templates/base/markup_codepreview.tmpl +++ b/templates/base/markup_codepreview.tmpl @@ -13,7 +13,7 @@ {{- $lineEscapeStatus := index $.LineEscapeStatus $idx -}}
{{$line.FormattedContent}}