From 1b0d525d3bbcd0efefbfdda4a3ed202fd6c1d970 Mon Sep 17 00:00:00 2001 From: LER0ever Date: Sat, 11 Aug 2018 19:34:45 -0500 Subject: [PATCH 1/4] Fix markdown image with link --- modules/markup/markdown/markdown.go | 31 +++++++++++++++-------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/modules/markup/markdown/markdown.go b/modules/markup/markdown/markdown.go index 3f94aa08b43b..247d25495105 100644 --- a/modules/markup/markdown/markdown.go +++ b/modules/markup/markdown/markdown.go @@ -38,7 +38,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 pointint to ifself by default out.WriteString(``) From fdd8ceb593df27dfb16ef2d5fe14a26ce0fd9d08 Mon Sep 17 00:00:00 2001 From: LER0ever Date: Sat, 11 Aug 2018 19:51:14 -0500 Subject: [PATCH 2/4] Add gitea copyright notice --- modules/markup/markdown/markdown.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/markup/markdown/markdown.go b/modules/markup/markdown/markdown.go index 247d25495105..b00348c32a84 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. From 3b7d5ae99686635d438c86fc7e38321b67113e7a Mon Sep 17 00:00:00 2001 From: LER0ever Date: Tue, 14 Aug 2018 03:00:33 -0500 Subject: [PATCH 3/4] add a test for markdown image with link --- modules/markup/markdown/markdown.go | 2 +- modules/markup/markdown/markdown_test.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/markup/markdown/markdown.go b/modules/markup/markdown/markdown.go index b00348c32a84..fbe8448ab93f 100644 --- a/modules/markup/markdown/markdown.go +++ b/modules/markup/markdown/markdown.go @@ -121,7 +121,7 @@ func (r *Renderer) Image(out *bytes.Buffer, link []byte, title []byte, alt []byt link = []byte(lnk) } - // Put a link around it pointint to ifself by default + // 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 605094df4627..a5ab84e0ec14 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 { From faade68f3cff5186270f1155e23504a40a9500d6 Mon Sep 17 00:00:00 2001 From: "L.E.R" Date: Tue, 30 Oct 2018 16:38:37 -0500 Subject: [PATCH 4/4] remove svg related variables --- modules/markup/markdown/markdown.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/modules/markup/markdown/markdown.go b/modules/markup/markdown/markdown.go index fbe8448ab93f..5022e0e23567 100644 --- a/modules/markup/markdown/markdown.go +++ b/modules/markup/markdown/markdown.go @@ -100,13 +100,6 @@ func (r *Renderer) ListItem(out *bytes.Buffer, text []byte, flags int) { r.Renderer.ListItem(out, text, flags) } -// Note: this section is for purpose of increase performance and -// reduce memory allocation at runtime since they are constant literals. -var ( - svgSuffix = []byte(".svg") - svgSuffixWithMark = []byte(".svg?") -) - // Image defines how images should be processed to produce corresponding HTML elements. func (r *Renderer) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte) { prefix := r.URLPrefix