[FEAT] Document links in wiki #12439

Open
opened 2026-05-06 17:27:21 +02:00 by ikcalb · 2 comments
ikcalb commented 2026-05-06 17:27:21 +02:00 (Migrated from codeberg.org)

Does your problem still exist on the latest Forgejo version?

Yes, the problem still exists (tested on a next instance)

About your usage of Forgejo

For many projects we like having an accompanying wiki.

Problem description

In this wiki we often like to link to documents/files directly, like so (i.e. in Home.md):

[document](doc/document.pdf)

Where the file document.pdf is pushed to the repository.wiki.git like so:

repository.wiki.git
|-doc
    |- document.pdf
 Home.md

It seems, currently this is not supported. When clicking on the link in the wiki, we're redirected to the wiki itself, the document is not opened.

Potential workarounds

Edit (@mahlzahn): Currently links to documents can be used with raw/ prefix, e.g.,

[document](raw/doc/document.pdf)

Forgejo Version

15.0.1

Other details about your environment (software names and versions)

Firefox esr 140.10

Solutions

Accepted solutions to address this problem will go here

### Does your problem still exist on the latest Forgejo version? Yes, the problem still exists (tested on a next instance) ### About your usage of Forgejo For many projects we like having an accompanying wiki. ### Problem description In this wiki we often like to link to documents/files directly, like so (i.e. `in Home.md`): ```md [document](doc/document.pdf) ``` Where the file `document.pdf` is pushed to the `repository.wiki.git` like so: ``` repository.wiki.git |-doc |- document.pdf Home.md ``` It seems, currently this is not supported. When clicking on the link in the wiki, we're redirected to the wiki itself, the document is not opened. ### Potential workarounds Edit (@mahlzahn): Currently links to documents can be used with `raw/` prefix, e.g., ```md [document](raw/doc/document.pdf) ``` ### Forgejo Version 15.0.1 ### Other details about your environment (software names and versions) Firefox esr 140.10 ### Solutions *Accepted solutions to address this problem will go here*
ikcalb commented 2026-05-07 08:55:21 +02:00 (Migrated from codeberg.org)

TL;DR: wiki module needs to insert .../raw/... to all links, not just images.

On further investigation I might have found the cause:

  • NOT working: document links. i.e.:
    [document](doc/document.pdf) --> https://host.com/repository/wiki/doc/document.pdf
    The generated path is MISSING .../raw/...

  • working: images
    ![image.png](images/image.png) --> https://host.com/repository/wiki/raw/images/image.png
    Here, the wiki module inserts .../raw/... so the link correctly points to the URL for the image

This is caused most likely by codeberg.org/forgejo/forgejo@69cf1f3333/modules/markup/html.go (L765-797)

For images, the path is resolved with:

		if image {
			if !absoluteLink {
				link = util.URLJoin(ctx.Links.ResolveMediaLink(ctx.IsWiki), link)
			}

while for non-images, the path is merely joined. no distinction for other file/media types is made:

		} else {
			if !absoluteLink {
				if ctx.IsWiki {
					link = util.URLJoin(ctx.Links.WikiLink(), link)
				} else {
					link = util.URLJoin(ctx.Links.SrcLink(), link)
				}
**TL;DR:** wiki module needs to insert `.../raw/...` to _all_ links, not just images. On further investigation I might have found the cause: - NOT working: document links. i.e.: `[document](doc/document.pdf)` --> `https://host.com/repository/wiki/doc/document.pdf` The generated path is MISSING `.../raw/...` - working: images `![image.png](images/image.png)` --> `https://host.com/repository/wiki/raw/images/image.png` Here, the wiki module inserts `.../raw/...` so the link correctly points to the URL for the image This is caused most likely by https://codeberg.org/forgejo/forgejo/src/commit/69cf1f3333cdb420dca6d07d74b5e0269c428057/modules/markup/html.go#L765-797 For images, the path is resolved with: ``` go if image { if !absoluteLink { link = util.URLJoin(ctx.Links.ResolveMediaLink(ctx.IsWiki), link) } ``` while for non-images, the path is merely joined. no distinction for other file/media types is made: ``` go } else { if !absoluteLink { if ctx.IsWiki { link = util.URLJoin(ctx.Links.WikiLink(), link) } else { link = util.URLJoin(ctx.Links.SrcLink(), link) } ```
mahlzahn commented 2026-05-07 18:21:12 +02:00 (Migrated from codeberg.org)

There are many related issues over there at Codeberg’s tracker, e.g., https://codeberg.org/Codeberg/Community/issues/1724 https://codeberg.org/Codeberg/Community/issues/554

And also Forgejo has these two related open issues: https://codeberg.org/forgejo/forgejo/issues/2752 https://codeberg.org/forgejo/forgejo/issues/5408

Indeed, the current workaround is

-[document](doc/document.pdf)
+[document](raw/doc/document.pdf)

But it is not very elegant. I agree that it would be good if doc/document.pdf links correctly instead, but it will need special care to not be a breaking change for people which are used to already use raw/doc/document.pdf.

There are many related issues over there at Codeberg’s tracker, e.g., https://codeberg.org/Codeberg/Community/issues/1724 https://codeberg.org/Codeberg/Community/issues/554 And also Forgejo has these two related open issues: https://codeberg.org/forgejo/forgejo/issues/2752 https://codeberg.org/forgejo/forgejo/issues/5408 Indeed, the current workaround is ```diff -[document](doc/document.pdf) +[document](raw/doc/document.pdf) ``` But it is not very elegant. I agree that it would be good if `doc/document.pdf` links correctly instead, but it will need special care to not be a breaking change for people which are used to already use `raw/doc/document.pdf`.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
sleepy/forgejo#12439
No description provided.