Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative path in Org files does not link to raw files #12831

Closed
2 of 7 tasks
0Pranav opened this issue Sep 14, 2020 · 1 comment · Fixed by #12997
Closed
2 of 7 tasks

Relative path in Org files does not link to raw files #12831

0Pranav opened this issue Sep 14, 2020 · 1 comment · Fixed by #12997
Labels
Milestone

Comments

@0Pranav
Copy link

0Pranav commented Sep 14, 2020

Description

In the example repo you can see org file in the master branch has the link https://try.gitea.io/0Pranav/vulkan-tutorial/src/branch/master/demo/vulkan.gif while in markdown the same link links to https://try.gitea.io/0Pranav/vulkan-tutorial/raw/branch/readme-test/demo/vulkan.gif, which results in the gif not being displayed in the org file

Screenshots

Markdown
Screenshot from 2020-09-14 10-49-32

Org
Screenshot from 2020-09-14 10-49-41

@zeripath
Copy link
Contributor

OK the code that deals with orgmode is:

https://github.com/go-gitea/gitea/blob/master/modules/markup/orgmode/orgmode.go

Likely this code:

func (r *Renderer) WriteRegularLink(l org.RegularLink) {
link := []byte(html.EscapeString(l.URL))
if l.Protocol == "file" {
link = link[len("file:"):]
}
if len(link) > 0 && !markup.IsLink(link) &&
link[0] != '#' && !bytes.HasPrefix(link, byteMailto) {
lnk := string(link)
if r.IsWiki {
lnk = util.URLJoin("wiki", lnk)
}
link = []byte(util.URLJoin(r.URLPrefix, lnk))
}
description := string(link)
if l.Description != nil {
description = r.WriteNodesAsString(l.Description...)
}
switch l.Kind() {
case "image":
r.WriteString(fmt.Sprintf(`<img src="%s" alt="%s" title="%s" />`, link, description, description))
case "video":
r.WriteString(fmt.Sprintf(`<video src="%s" title="%s">%s</video>`, link, description, description))
default:
r.WriteString(fmt.Sprintf(`<a href="%s" title="%s">%s</a>`, link, description, description))
}
}

Probably needs to have changed inspired by:

case *ast.Image:
// Images need two things:
//
// 1. Their src needs to munged to be a real value
// 2. If they're not wrapped with a link they need a link wrapper
// Check if the destination is a real link
link := v.Destination
if len(link) > 0 && !markup.IsLink(link) {
prefix := pc.Get(urlPrefixKey).(string)
if pc.Get(isWikiKey).(bool) {
prefix = giteautil.URLJoin(prefix, "wiki", "raw")
}
prefix = strings.Replace(prefix, "/src/", "/media/", 1)
lnk := string(link)
lnk = giteautil.URLJoin(prefix, lnk)
link = []byte(lnk)
}
v.Destination = link
parent := n.Parent()
// Create a link around image only if parent is not already a link
if _, ok := parent.(*ast.Link); !ok && parent != nil {
wrap := ast.NewLink()
wrap.Destination = link
wrap.Title = v.Title
parent.ReplaceChild(parent, n, wrap)
wrap.AppendChild(wrap, n)
}
case *ast.Link:

@lafriks lafriks added this to the 1.13.0 milestone Oct 2, 2020
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants