summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-03-12 02:23:34 +0000
committertechknowlogick <matti@mdranta.net>2019-03-11 22:23:34 -0400
commitb2e9894988a8cb486f8838f4bf532401124802c4 (patch)
tree7fc62cb89d394f0edb026726c9a732b35ab47f19 /modules
parent663874e8bee253dcaa95b03adb519c5685774351 (diff)
downloadgitea-b2e9894988a8cb486f8838f4bf532401124802c4.tar.gz
gitea-b2e9894988a8cb486f8838f4bf532401124802c4.zip
Fix reported issue in repo description (#6306)
Diffstat (limited to 'modules')
-rw-r--r--modules/markup/html.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/modules/markup/html.go b/modules/markup/html.go
index 036b664b00..20a158b1c5 100644
--- a/modules/markup/html.go
+++ b/modules/markup/html.go
@@ -227,6 +227,23 @@ func RenderCommitMessage(
return ctx.postProcess(rawHTML)
}
+// RenderDescriptionHTML will use similar logic as PostProcess, but will
+// use a single special linkProcessor.
+func RenderDescriptionHTML(
+ rawHTML []byte,
+ urlPrefix string,
+ metas map[string]string,
+) ([]byte, error) {
+ ctx := &postProcessCtx{
+ metas: metas,
+ urlPrefix: urlPrefix,
+ procs: []processor{
+ descriptionLinkProcessor,
+ },
+ }
+ return ctx.postProcess(rawHTML)
+}
+
var byteBodyTag = []byte("<body>")
var byteBodyTagClosing = []byte("</body>")
@@ -658,3 +675,34 @@ func genDefaultLinkProcessor(defaultLink string) processor {
node.FirstChild, node.LastChild = ch, ch
}
}
+
+// descriptionLinkProcessor creates links for DescriptionHTML
+func descriptionLinkProcessor(ctx *postProcessCtx, node *html.Node) {
+ m := linkRegex.FindStringIndex(node.Data)
+ if m == nil {
+ return
+ }
+ uri := node.Data[m[0]:m[1]]
+ replaceContent(node, m[0], m[1], createDescriptionLink(uri, uri))
+}
+
+func createDescriptionLink(href, content string) *html.Node {
+ textNode := &html.Node{
+ Type: html.TextNode,
+ Data: content,
+ }
+ linkNode := &html.Node{
+ FirstChild: textNode,
+ LastChild: textNode,
+ Type: html.ElementNode,
+ Data: "a",
+ DataAtom: atom.A,
+ Attr: []html.Attribute{
+ {Key: "href", Val: href},
+ {Key: "target", Val: "_blank"},
+ {Key: "rel", Val: "noopener noreferrer"},
+ },
+ }
+ textNode.Parent = linkNode
+ return linkNode
+}