cannot create *relative* link to *raw* view in markdown. #14332

Closed
opened 2025-11-02 11:10:03 -06:00 by GiteaMirror · 5 comments
Owner

Originally created by @juleskers on GitHub (Apr 2, 2025).

Feature Description

I'm trying to generate relative README.md links to the raw-views for some files in a self-hosted repo.
(That keep working if someone forks, or if I move my project from personal playground to team-org).

Gitea supports relative links (e.g. [config example](config.example), which turns into https://gitea.local/$USER/$REPO/src/branch/main/config.example)
Gitea also supports raw views, i.e. https://gitea.local/$USER/$REPO/raw/branch/main/config.example. (replacing src in link with raw)

What I cannot get working is relative links to raw.

  • [config example](raw/config.example) -> HTTP 404:
    (turns into https://gitea.local/$USER/$REPO/src/branch/main/raw/config.example`, i.e. "raw" is interpreted as a relative folder (which is the only sensible thing to do)
  • [config example](/raw/config.example) (leading slash) turns into gitea.local/raw/config.example (i.e. makes it an absolute link from base-url. Again this is the sensible, HTTP-spec-conforming thing to do.
  • appending ?raw=1 (the way github solves it, according to stackOverflow) -> opens the normal, non-raw view.

Is there any way to tell the link-rewriter to use 'raw' instead of 'src'?
If so: where did I overlook the documentation?
If not: can we add something (preferably a redirect if &raw=1 is present, for github compatibility, though alternatives welcome)

Side note: I run into exactly the same problem in GitLab, where GL uses /-/blob/ where gitea has /src/, and GL:/-/raw/ for gitea:/raw/.
GitLab also doesn't handle ?raw=1.

Screenshots

No response

Originally created by @juleskers on GitHub (Apr 2, 2025). ### Feature Description I'm trying to generate _relative_ README.md links to the raw-views for some files in a self-hosted repo. (That keep working if someone forks, or if I move my project from personal playground to team-org). Gitea supports relative links (e.g. `[config example](config.example)`, which turns into `https://gitea.local/$USER/$REPO/src/branch/main/config.example`) Gitea also supports raw views, i.e. `https://gitea.local/$USER/$REPO/raw/branch/main/config.example`. (replacing `src` in link with `raw`) What I cannot get working is relative links _to_ raw. - `[config example](raw/config.example)` -> HTTP 404: (turns into https://gitea.local/$USER/$REPO/src/branch/main/raw/config.example`, i.e. "raw" is interpreted as a relative folder (which is the only sensible thing to do) - `[config example](/raw/config.example)` (leading slash) turns into `gitea.local/raw/config.example` (i.e. makes it an absolute link from base-url. Again this is the sensible, HTTP-spec-conforming thing to do. - appending `?raw=1` (the way github solves it, [according to stackOverflow](https://stackoverflow.com/questions/58417387/how-can-i-create-relative-links-from-my-markdown-to-github-raw-files?rq=3)) -> opens the normal, non-raw view. Is there any way to tell the link-rewriter to use 'raw' instead of 'src'? If so: where did I overlook the documentation? If not: can we add something (preferably a redirect if `&raw=1` is present, for github compatibility, though alternatives welcome) Side note: I run into exactly the same problem in GitLab, where GL uses `/-/blob/` where gitea has `/src/`, and GL:`/-/raw/` for gitea:`/raw/`. GitLab also doesn't handle `?raw=1`. ### Screenshots _No response_
GiteaMirror added the type/proposal label 2025-11-02 11:10:03 -06:00
Author
Owner

@wxiaoguang commented on GitHub (Apr 2, 2025):

It's the same behavior as GitHub: the "root path" of the rendered content is the repo's src path.

@wxiaoguang commented on GitHub (Apr 2, 2025): It's the same behavior as GitHub: the "root path" of the rendered content is the repo's src path.
Author
Owner

@wxiaoguang commented on GitHub (Apr 2, 2025):

See this: https://github.com/wxiaoguang/playground/blob/main/dir/test.md

@wxiaoguang commented on GitHub (Apr 2, 2025): See this: https://github.com/wxiaoguang/playground/blob/main/dir/test.md
Author
Owner

@juleskers commented on GitHub (Apr 2, 2025):

Thanks for the response 🧡

I have no trouble with the current behaviour of the "root path == repo/src/".
Your playground test, as far as I am concerned, is 100% correct, it is just missing an additional feature I'd like to see.

My request is that, like github, appending &raw=1 magically makes "root path == repo/raw/" (for that specific link)

I've forked your test to demonstrate: https://github.com/juleskers/playground/blob/patch-1/dir/test.md

@juleskers commented on GitHub (Apr 2, 2025): Thanks for the response 🧡 I have no trouble with the current behaviour of the "root path == repo/src/". Your playground test, as far as I am concerned, is 100% correct, it is just missing an additional feature I'd like to see. My request is that, like github, appending `&raw=1` magically makes "root path == repo/raw/" (for that specific link) I've forked your test to demonstrate: https://github.com/juleskers/playground/blob/patch-1/dir/test.md
Author
Owner

@wxiaoguang commented on GitHub (Apr 2, 2025):

Oh I see, get your point now.

Maybe it's not difficult to support it, let me try.

@wxiaoguang commented on GitHub (Apr 2, 2025): Oh I see, get your point now. Maybe it's not difficult to support it, let me try.
Author
Owner

@wxiaoguang commented on GitHub (Apr 2, 2025):

-> Support creating relative link to raw path in markdown #34105

@wxiaoguang commented on GitHub (Apr 2, 2025): -> Support creating relative link to raw path in markdown #34105
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#14332