Skip to content

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

@fnetX

Description

@fnetX
Contributor

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

Activity

zeripath

zeripath commented on Feb 3, 2022

@zeripath
Contributor

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

zeripath commented on Feb 3, 2022

@zeripath
Contributor

@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.

added
issue/needs-feedbackFor bugs, we need more details. For features, the feature must be described in more detail
on Apr 26, 2023
wxiaoguang

wxiaoguang commented on Apr 26, 2023

@wxiaoguang
Contributor

It looks like this problem has been resolved?

fnetX

fnetX commented on May 4, 2023

@fnetX
ContributorAuthor

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.

wxiaoguang

wxiaoguang commented on May 4, 2023

@wxiaoguang
Contributor

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?

removed
issue/needs-feedbackFor bugs, we need more details. For features, the feature must be described in more detail
on May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zeripath@wxiaoguang@fnetX

        Issue actions

          Wiki heading anchors don't work for HTML headings · Issue #18585 · go-gitea/gitea