From b686bd0c9467885308a8e45214e75ee270c084e2 Mon Sep 17 00:00:00 2001 From: "L.E.R" Date: Tue, 30 Oct 2018 17:26:28 -0500 Subject: [PATCH] Fix markdown image with link (#4675) * Fix markdown image with link * Add gitea copyright notice * add a test for markdown image with link * remove svg related variables --- modules/markup/markdown/markdown.go | 39 +++++++++++------------- modules/markup/markdown/markdown_test.go | 4 +++ 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/modules/markup/markdown/markdown.go b/modules/markup/markdown/markdown.go index 3f94aa08b4..5022e0e235 100644 --- a/modules/markup/markdown/markdown.go +++ b/modules/markup/markdown/markdown.go @@ -1,4 +1,5 @@ // Copyright 2014 The Gogs Authors. All rights reserved. +// Copyright 2018 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -38,7 +39,16 @@ func (r *Renderer) Link(out *bytes.Buffer, link []byte, title []byte, content [] link = []byte(mLink) } - r.Renderer.Link(out, link, title, content) + if len(content) > 10 && string(content[0:9]) == " 0 { - if markup.IsLink(link) { - // External link with .svg suffix usually means CI status. - // TODO: define a keyword to allow non-svg images render as external link. - if bytes.HasSuffix(link, svgSuffix) || bytes.Contains(link, svgSuffixWithMark) { - r.Renderer.Image(out, link, title, alt) - return - } - } else { - lnk := string(link) - lnk = util.URLJoin(prefix, lnk) - lnk = strings.Replace(lnk, " ", "+", -1) - link = []byte(lnk) - } + if len(link) > 0 && !markup.IsLink(link) { + lnk := string(link) + lnk = util.URLJoin(prefix, lnk) + lnk = strings.Replace(lnk, " ", "+", -1) + link = []byte(lnk) } + // Put a link around it pointing to itself by default out.WriteString(``) diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go index 605094df46..a5ab84e0ec 100644 --- a/modules/markup/markdown/markdown_test.go +++ b/modules/markup/markdown/markdown_test.go @@ -73,6 +73,7 @@ func TestRender_Images(t *testing.T) { url := "../../.images/src/02/train.jpg" title := "Train" + href := "https://gitea.io" result := util.URLJoin(AppSubURL, url) test( @@ -82,6 +83,9 @@ func TestRender_Images(t *testing.T) { test( "[["+title+"|"+url+"]]", `

`+title+`

`) + test( + "[!["+title+"]("+url+")]("+href+")", + `

`+title+`

`) } func testAnswers(baseURLContent, baseURLImages string) []string {