gitea: Relative links not working in asciidoc render

Description

I activated asciidoc file render based on https://docs.gitea.com/next/administration/external-renderers:

  • install asciidoctor via apt install asciidoctor
  • add external render in app.ini
[markup.asciidoc]
ENABLED = true
FILE_EXTENSIONS = .adoc,.asciidoc
RENDER_COMMAND = "asciidoctor -s -a showtitle --out-file=- -"
; Input is not a standard input but a file
IS_INPUT_FILE = false

Then I created a branch in one of my repositories and migrated Markdown files to adoc files. In the main *.adoc file I use relative links to link to other *.adoc files. Therefore I followed the asciidoctor documentation.

Example file docs/README.adoc:

= Network documentation

== Index

* link:general/[General]
** link:general/netplan.drawio.svg[Netplan]
** link:general/Patchpanels.adoc[Patchpanels]
** link:general/static-IPs.adoc[Static IPs]

I also tried other relative links:

= Network documentation

== Index

* link:./general/[General]
** link:./general/netplan.drawio.svg[Netplan]
** link:./general/Patchpanels.adoc[Patchpanels]
** link:./general/static-IPs.adoc[Static IPs]

In VSCode the links are working and I can navigate to the files in subdirectories by clicking the link in the main file.

The link is interpreted as it starts from the root of the branch. So /docs/ is missing. But as the README.adoc is in the folder docs, the links should be interpreted as starting from there.

This is shown in the screenshot below: gitea_relative_adoc_links_not_working_correctly

I discovered that issue also in another repository, where I first tried it.

When I use Markdown (currently my master branch), everything works as is should.

Example file doc/README.md:

# Network documentation

## Index

* [General](./general/)
  * [Netplan](./general/netplan.drawio.svg)
  * [Patchpanels](./general/Patchpanels.md)
  * [Static IPs](./general/static-IPs.md)

Working links, see screenshot: gitea_relative_md_links_working_correctly

Am I doing something wrong? Or is there maybe an issue with asciidoctor or the asciidoctor command in app.ini?

Would be great if anybody could help me.

Gitea Version

1.20.1

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

gitea_relative_adoc_links_not_working_correctly gitea_relative_md_links_working_correctly

Git Version

2.30.2

Operating System

Raspbian/Debian 11.7

How are you running Gitea?

Local install with binary and systemd service.

Database

MySQL

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 1
  • Comments: 26 (1 by maintainers)

Most upvoted comments

I’ve updated my PoC so that I have AsciiDoc and Markdown files with the same content:

$ ls -la
total 16
drwxr-xr-x   6 eedwards  staff  192  2 Nov 09:38 ./
drwxr-xr-x   3 eedwards  staff   96 25 Aug 18:12 ../
drwxr-xr-x  13 eedwards  staff  416  2 Nov 09:42 .git/
-rw-r--r--   1 eedwards  staff   69 25 Aug 18:15 README.adoc
-rw-r--r--   1 eedwards  staff   67  2 Nov 09:38 README.md
drwxr-xr-x  12 eedwards  staff  384  2 Nov 09:41 docs/
$ ls -la docs
total 80
drwxr-xr-x  12 eedwards  staff  384  2 Nov 09:41 ./
drwxr-xr-x   6 eedwards  staff  192  2 Nov 09:38 ../
-rw-r--r--   1 eedwards  staff   79  2 Nov 09:38 READ.md
-rw-r--r--   1 eedwards  staff   81 25 Aug 18:29 README.adoc
-rw-r--r--   1 eedwards  staff   30 25 Aug 18:14 development.adoc
-rw-r--r--   1 eedwards  staff   33  2 Nov 09:39 development.md
-rw-r--r--   1 eedwards  staff  139 25 Aug 18:15 index.adoc
-rw-r--r--   1 eedwards  staff  129  2 Nov 09:39 index.md
-rw-r--r--   1 eedwards  staff   31 25 Aug 18:14 install.adoc
-rw-r--r--   1 eedwards  staff   34  2 Nov 09:39 install.md
-rw-r--r--   1 eedwards  staff   26 25 Aug 18:14 support.adoc
-rw-r--r--   1 eedwards  staff   29  2 Nov 09:39 support.md

I used docs/READ.md instead of docs/README.md to avoid auto-rendering the Markdown file.

Then I compared the links rendered by Gitea in docs/index.adoc and docs/index.md. First, here is the markup for the links:

docs/index.adoc:

* link:install.adoc[Installation]

docs/index.md:

- [Installation](install.md)

As you can see, both implement relative links. When Gitea renders these:

docs/index.adoc:

<a href="install.adoc" rel="nofollow">Installation</a>

docs/index.md:

<a href="/eskwayrd/test/src/branch/main/docs/install.md" rel="nofollow">Installation</a>

As you can see, the rendered Asciidoc files have the relative links as defined in the file. Whereas the Markdown files have an absolute link from the document root. That’s the problem.

I don’t know if Gitea is making the rendered Markdown links absolute or whether the Markdown renderer used by Gitea is doing that. But nothing is making the AsciiDoc links absolute.

Either Gitea needs to add slashes after folder names, or it needs to make relative links absolute in rendered AsciiDoc files. Adding the slashes after folder names would avoid this issue for any other auto-rendered files. And there’s no reason both solutions couldn’t be applied.

ok, thanks. I’ll start with v1.11.0 until v1.19.x and do the first probe for the binary search at v1.16.1.

Currently I have limited access to the internet (and cannot download large files) due to a few days off. So I can start checking the issues earliest at end of september / beginning of october.

If this is too late, then probably somebody else could jump in? Otherwise I’ll let you all know when I have the first results.