]> source.dussan.org Git - gitea.git/commit
Fix user-defined markup links targets (#29305) (#29666)
authorGiteabot <teabot@gitea.io>
Fri, 8 Mar 2024 16:53:36 +0000 (00:53 +0800)
committerGitHub <noreply@github.com>
Fri, 8 Mar 2024 16:53:36 +0000 (16:53 +0000)
commitbfc7c8a5985825ec28f3feefe1d050ec52525097
tree020414d2e6c70a524e2f90bf1e631fc012e3ffc6
parent1f897637441a9a5c43e01b84e374d836d9260a00
Fix user-defined markup links targets (#29305) (#29666)

Backport #29305 by @DanielMatiasCarvalho

This seeks to fix the bug reported on issue #29196.

Cause:
ID's with custom characters (- , _ , etc.), were not linking correctly
in the Markdown file when rendered in the browser because the ID in the
respective destinies would be different than the one in anchor, while
for IDs with only letters, the ID would be the same.

Fix:
It was suggested that to fix this bug, it should more or less like
GitHub does it. While in gitea the anchors would be put in HTML like
this:
```
<p dir="auto"><a href="#user-content-_toc152597800" rel="nofollow">Review</a></p>
<p dir="auto"><a href="#user-content-_toc152597802" rel="nofollow">Staging</a></p>
<p dir="auto"><a href="#user-content-_toc152597803" rel="nofollow">Development</a></p>
<p dir="auto"><a href="#user-content-_toc152597828" rel="nofollow">Testing</a></p>
<p dir="auto"><a href="#user-content-_toc152597829" rel="nofollow">Unit-tests</a></p>

```
In GitHub, the same anchor's href properties would be the same without
"user-content-" trailing behind.

So my code made sure to change those anchors, so it would not include
"user-content-" and then add respective Event Listeners so it would
scroll into the supposed places.

Fixes: #29196
Co-authored-by: DC <106393991+DanielMatiasCarvalho@users.noreply.github.com>
Co-authored-by: silverwind <me@silverwind.io>
web_src/js/markup/anchors.js