Wiki heading anchors don't work for HTML headings #8483

Open
opened 2025-11-02 08:08:04 -06:00 by GiteaMirror · 5 comments
Owner

Originally created by @fnetX on GitHub (Feb 3, 2022).

Gitea Version

1.17.0+dev-92-g90b4d385d

Git Version

No response

Operating System

No response

How are you running Gitea?

confirmed on try.gitea.io + codeberg.org

Database

No response

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Description

A user on Codeberg reported, that the auto-generated anchor links for headings in the Wiki apparently only work for Markdown. When using HTML headings in the wiki source, the rendered href attribute only contains "#".

Confirmed at https://try.gitea.io/fnetx/wikitesting/wiki/Home#.

Orignal report: https://codeberg.org/Codeberg/Community/issues/489

Normally a header within article is converted to an <hX> HTML tag containing an <a>. The href attribute would contain the header title shaped to be conformant as an URL string. Like this:

## Second-level heading

<h2 id="user-content-second-level-heading">          ← id attribute is present
    <a href="#second-level-heading">                 ← anchor is in place
        Second-level heading
    </a>
</h2>

However, if we’d use HTML markup in the source file, e.g. to put the heading at the centre, the href attribute will contain only the hash sign, #.

<h2 align="center">
   Second-level heading
</h2>

<h2 align="center">                                  ← id attribute is missing!
    <a href="#">                                     ← anchor is empty!
        Second-level heading
    </a>
</h2>

It breaks cross-references between articles, making them much less useful, and breaks compatibility with at least Github, where it works.

Screenshots

No response

Originally created by @fnetX on GitHub (Feb 3, 2022). ### Gitea Version 1.17.0+dev-92-g90b4d385d ### Git Version _No response_ ### Operating System _No response_ ### How are you running Gitea? confirmed on try.gitea.io + codeberg.org ### Database _No response_ ### Can you reproduce the bug on the Gitea demo site? Yes ### Log Gist _No response_ ### Description A user on Codeberg reported, that the auto-generated anchor links for headings in the Wiki apparently only work for Markdown. When using HTML headings in the wiki source, the rendered href attribute only contains "#". Confirmed at https://try.gitea.io/fnetx/wikitesting/wiki/Home#. Orignal report: https://codeberg.org/Codeberg/Community/issues/489 > Normally a header within article is converted to an `<hX>` HTML tag containing an `<a>`. The `href` attribute would contain the header title shaped to be conformant as an URL string. Like this: > > `## Second-level heading` > ↓ > ``` > <h2 id="user-content-second-level-heading"> ← id attribute is present > <a href="#second-level-heading"> ← anchor is in place > Second-level heading > </a> > </h2> > ``` > > However, if we’d use HTML markup in the source file, e.g. to put the heading at the centre, the href attribute will contain only the hash sign, `#`. > > ``` > <h2 align="center"> > Second-level heading > </h2> > ``` > ↓ > ``` > <h2 align="center"> ← id attribute is missing! > <a href="#"> ← anchor is empty! > Second-level heading > </a> > </h2> > ``` > It breaks cross-references between articles, making them much less useful, and breaks compatibility with at least Github, where it works. ### Screenshots _No response_
GiteaMirror added the topic/wiki label 2025-11-02 08:08:04 -06:00
Author
Owner

@zeripath commented on GitHub (Feb 3, 2022):

More interestingly the blob_excerpt links don't appear to work for the wiki. I've just noticed this and put up a PR to fix that #18587

@zeripath commented on GitHub (Feb 3, 2022): More interestingly the blob_excerpt links don't appear to work for the wiki. I've just noticed this and put up a PR to fix that #18587
Author
Owner

@zeripath commented on GitHub (Feb 3, 2022):

@fnetX I've edited README.md to:

# wikitesting

hello

<h1 align="center">
    test
</h1>

<h2 align="center">
A test for solving Codeberg bug #489
</h2>

<h2>a headline without further attribute</h2>

## a makrdown headline

and it looks the same as the wiki content. I then added a <h3 id="preset-id">This one has a preset id</h3> and it gets the correct id.

@zeripath commented on GitHub (Feb 3, 2022): @fnetX I've edited README.md to: ```md # wikitesting hello <h1 align="center"> test </h1> <h2 align="center"> A test for solving Codeberg bug #489 </h2> <h2>a headline without further attribute</h2> ## a makrdown headline ``` and it looks the same as the wiki content. I then added a `<h3 id="preset-id">This one has a preset id</h3>` and it gets the correct id.
Author
Owner

@wxiaoguang commented on GitHub (Apr 26, 2023):

It looks like this problem has been resolved?

@wxiaoguang commented on GitHub (Apr 26, 2023): It looks like this problem has been resolved?
Author
Owner

@fnetX commented on GitHub (May 4, 2023):

To be honest, I don't quite understand how it is resolved. Are users supposed to set the id attribute manually for HTML headings? The auto-generated ones still appear to not work.

@fnetX commented on GitHub (May 4, 2023): To be honest, I don't quite understand how it is resolved. Are users supposed to set the id attribute manually for HTML headings? The auto-generated ones still appear to not work.
Author
Owner

@wxiaoguang commented on GitHub (May 4, 2023):

There is reply above and no response for long time. So it's closed after it been marked as needs-feedback for a few days.

Put a sample from GitHub here:

https://github.com/wxiaoguang/playground/wiki

link: https://github.com/wxiaoguang/playground/wiki#------------second-level-heading----

Do you think this heading is acceptable?

@wxiaoguang commented on GitHub (May 4, 2023): There is reply above and no response for long time. So it's closed after it been marked as needs-feedback for a few days. Put a sample from GitHub here: https://github.com/wxiaoguang/playground/wiki link: https://github.com/wxiaoguang/playground/wiki#------------second-level-heading---- Do you think this heading is acceptable?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#8483