Codeberg/Community
54
325
Fork
You've already forked Community
12

Markdown renderer's linkifier prepends id attribute with user-content-? #1850

Closed
opened 2025年04月16日 13:57:43 +02:00 by trwnh · 5 comments

Comment

Recently looking at https://codeberg.org/fediverse/fep/src/branch/main/fep/888d/fep-888d.md and noticed some Markdown rendering issues that I don't remember being there half a year ago or so...

For example, https://codeberg.org/fediverse/fep/src/branch/main/fep/888d/fep-888d.md#exampleB behaves like so:

Upon a fresh page load or refresh, it seemingly navigates to the correct section.

However, inspecting the HTML, we see that there are some errors.

The following Markdown input:

<section id="exampleB" resource="https://w3id.org/fep/888d/exampleB" typeof="owl:ObjectProperty">
<h3>exampleB</h3>

Produces the following HTML:

<section id="user-content-exampleB">
<h3><a class="anchor" href="#"><svg ...>...</svg></a>exampleB</h3>

Note that the id="exampleB" somehow becomes id="user-content-exampleB". This has two noticeable side effects:

  1. An HTML parser no longer finds anything when searching for an element with the selector *[id="exampleB"].
  2. Changing the fragment component in the URL bar and navigating there does not scroll the browser to the correct section anymore.
### Comment Recently looking at https://codeberg.org/fediverse/fep/src/branch/main/fep/888d/fep-888d.md and noticed some Markdown rendering issues that I don't remember being there half a year ago or so... For example, https://codeberg.org/fediverse/fep/src/branch/main/fep/888d/fep-888d.md#exampleB behaves like so: Upon a fresh page load or refresh, it seemingly navigates to the correct section. However, inspecting the HTML, we see that there are some errors. The following Markdown input: ```md <section id="exampleB" resource="https://w3id.org/fep/888d/exampleB" typeof="owl:ObjectProperty"> <h3>exampleB</h3> ``` Produces the following HTML: ```html <section id="user-content-exampleB"> <h3><a class="anchor" href="#"><svg ...>...</svg></a>exampleB</h3> ``` Note that the `id="exampleB"` somehow becomes `id="user-content-exampleB"`. This has two noticeable side effects: 1. An HTML parser no longer finds anything when searching for an element with the selector `*[id="exampleB"]`. 2. Changing the fragment component in the URL bar and navigating there does not scroll the browser to the correct section anymore.

@trwnh wrote in #1850 (comment):

An HTML parser no longer finds anything when searching for an element with the selector *[id="exampleB"].

The prefix of user-content- in the ID has been there for years, so this should not be a new problem if anyone was using such selectors.

Refreshing the page does not scroll the browser to the correct section anymore.

Please elaborate more on this issue, I am not able to reproduce the issue from this description. There's javascript code that ensures that navigating or reloading to #exampleB will scroll to #user-content-exampleB.


As far as I am aware this is not new behavior and is also very unlikely to change, the user-content prefix is there for security reasons.

@trwnh wrote in https://codeberg.org/Codeberg/Community/issues/1850#issue-1305878: > An HTML parser no longer finds anything when searching for an element with the selector `*[id="exampleB"]`. The prefix of `user-content-` in the ID has been there for years, so this should not be a new problem if anyone was using such selectors. > Refreshing the page does not scroll the browser to the correct section anymore. Please elaborate more on this issue, I am not able to reproduce the issue from this description. There's javascript code that ensures that navigating or reloading to `#exampleB` will scroll to `#user-content-exampleB`. --- As far as I am aware this is not new behavior and is also very unlikely to change, the `user-content` prefix is there for security reasons.
Author
Copy link

There's javascript code that ensures that navigating or reloading to #exampleB will scroll to #user-content-exampleB.

ah, that might be it. although i can reproduce this even when javascript is enabled.

steps to reproduce:

  1. Open https://codeberg.org/fediverse/fep/src/branch/main/fep/888d/fep-888d.md
  2. Append #exampleB to the URL in your browser and hit enter
  3. Note that the page doesn't scroll

Happening in Firefox 138 on Linux for me.

> There's javascript code that ensures that navigating or reloading to #exampleB will scroll to #user-content-exampleB. ah, that might be it. although i can reproduce this even when javascript is enabled. steps to reproduce: 1) Open https://codeberg.org/fediverse/fep/src/branch/main/fep/888d/fep-888d.md 2) Append #exampleB to the URL in your browser and hit enter 3) Note that the page doesn't scroll Happening in Firefox 138 on Linux for me.

@trwnh wrote in #1850 (comment):

Append #exampleB to the URL in your browser and hit enter

Yeah this case would not be handled by the code, but is this commonly done, manually appending the hash? Shouldn't be too hard to add code for this, but prefer not to if it's not strictly needed.

@trwnh wrote in https://codeberg.org/Codeberg/Community/issues/1850#issuecomment-3835526: > Append #exampleB to the URL in your browser and hit enter Yeah this case would not be handled by the code, but is this commonly done, manually appending the hash? Shouldn't be too hard to add code for this, but prefer not to if it's not strictly needed.
Author
Copy link

is this commonly done, manually appending the hash?

i don't know about if anyone else does it, but i commonly do it to test if anchors work or to skip to different parts of a page when there isn't a table of contents or sticky sidebar menu of some sort.

although the id not being present in the HTML output directly is probably a bigger issue, especially for no-js users.

> is this commonly done, manually appending the hash? i don't know about if anyone else does it, but i commonly do it to test if anchors work or to skip to different parts of a page when there isn't a table of contents or sticky sidebar menu of some sort. although the `id` not being present in the HTML output directly is probably a bigger issue, especially for no-js users.
Owner
Copy link

forgejo/forgejo#5346 is the respective upstream issue. There has been a WIP pull request that can be picked up.

https://codeberg.org/forgejo/forgejo/issues/5346 is the respective upstream issue. There has been a WIP pull request that can be picked up.
Sign in to join this conversation.
No Branch/Tag specified
main
No results found.
Labels
Clear labels
accessibility

Reduces accessibility and is thus a "bug" for certain user groups on Codeberg.
bug

Something is not working the way it should. Does not concern outages.
bug
infrastructure

Errors evidently caused by infrastructure malfunctions or outages
Codeberg

This issue involves Codeberg's downstream modifications and settings and/or Codeberg's structures.
contributions welcome

Please join the discussion and consider contributing a PR!
docs

No bug, but an improvement to the docs or UI description will help
duplicate

This issue or pull request already exists
enhancement

New feature
infrastructure

Involves changes to the server setups, use `bug/infrastructure` for infrastructure-related user errors.
legal

An issue directly involving legal compliance
licence / ToS

involving questions about the ToS, especially licencing compliance
please chill
we are volunteers

Please consider editing your posts and remember that there is a human on the other side. We get that you are frustrated, but it's harder for us to help you this way.
public relations

Things related to Codeberg's external communication
question

More information is needed
question
user support

This issue contains a clearly stated problem. However, it is not clear whether we have to fix anything on Codeberg's end, but we're helping them fix it and/or find the cause.
s/Forgejo

Related to Forgejo. Please also check Forgejo's issue tracker.
s/Forgejo/migration

Migration related issues in Forgejo
s/Pages

Issues related to the Codeberg Pages feature
s/Weblate

Issue is related to the Weblate instance at https://translate.codeberg.org
s/Woodpecker

Woodpecker CI related issue
security

involves improvements to the sites security
service

Add a new service to the Codeberg ecosystem (instead of implementing into Gitea)
upstream

An open issue or pull request to an upstream repository to fix this issue (partially or completely) exists (i.e. Gitea, Forgejo, etc.)
wontfix

Codeberg's current set of contributors are not planning to spend time on delegating this issue.
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
3 participants
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
Codeberg/Community#1850
Reference in a new issue
Codeberg/Community
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?