HTML anchor on function name #10168

Open
opened 2025-11-02 09:00:06 -06:00 by GiteaMirror · 6 comments
Owner

Originally created by @Utopiah on GitHub (Jan 27, 2023).

Feature Description

Linking to line number is convenient but not semantically reliable. It works on a specific commit but not a file. Consequently and because syntax highlighting already works, providing classes, it would be useful to be able to provide IDs on function name (and possibly other tokens).

Screenshots

No response

Originally created by @Utopiah on GitHub (Jan 27, 2023). ### Feature Description Linking to line number is convenient but not semantically reliable. It works on a specific commit but not a file. Consequently and because syntax highlighting already works, providing classes, it would be useful to be able to provide IDs on function name (and possibly other tokens). ### Screenshots _No response_
GiteaMirror added the type/proposaltype/feature labels 2025-11-02 09:00:06 -06:00
Author
Owner

@JakobDev commented on GitHub (Jan 28, 2023):

That would mean that a ton of different languages needs to be parses

@JakobDev commented on GitHub (Jan 28, 2023): That would mean that a ton of different languages needs to be parses
Author
Owner

@Utopiah commented on GitHub (Jan 28, 2023):

As syntax highlighting already works isn't it already the case for some languages and thus couldn't it start for whatever is already supported?

@Utopiah commented on GitHub (Jan 28, 2023): As syntax highlighting already works isn't it already the case for some languages and thus couldn't it start for whatever is already supported?
Author
Owner

@delvh commented on GitHub (Jan 28, 2023):

Probably not.
I'm not too deep into the syntax highlighting mechanisms myself, but

  1. that's an external library we use. We can only support it if they support it too. I don't know exactly which library at the moment Found it, it's https://github.com/alecthomas/chroma
  2. they probably just run a bunch of regexes against the source code, and if the regex matches, they assign the specific highlighting. If you want something like that, they likely have to revamp an awful amount of code.
@delvh commented on GitHub (Jan 28, 2023): Probably not. I'm not too deep into the syntax highlighting mechanisms myself, but 1. that's an external library we use. We can only support it if they support it too. ~~I don't know exactly which library at the moment~~ Found it, it's https://github.com/alecthomas/chroma 2. they probably just run a bunch of regexes against the source code, and if the regex matches, they assign the specific highlighting. If you want something like that, they likely have to revamp an awful amount of code.
Author
Owner

@zeripath commented on GitHub (Jan 28, 2023):

Chroma should be lexing functions and classes to a common CSS class across languages.

The issue is sticking an ID on these. They're unlikely to be unique.

You're more likely to have a better chance if you extend our js code to then look for these if the provided anchor fragment doesn't match a real element with that id.

@zeripath commented on GitHub (Jan 28, 2023): Chroma should be lexing functions and classes to a common CSS class across languages. The issue is sticking an ID on these. They're unlikely to be unique. You're more likely to have a better chance if you extend our js code to then look for these if the provided anchor fragment doesn't match a real element with that id.
Author
Owner

@delvh commented on GitHub (Jan 28, 2023):

Wait, if they are already doing this, wouldn't it be fairly easy to generate unique IDs by simply using the function signature without any special characters, and adding a prefix? And in the case there is a conflict, appending numbers?

@delvh commented on GitHub (Jan 28, 2023): Wait, if they are already doing this, wouldn't it be fairly easy to generate unique IDs by simply using the function signature without any special characters, and adding a prefix? And in the case there is a conflict, appending numbers?
Author
Owner

@zeripath commented on GitHub (Jan 28, 2023):

It honestly would be simpler to just add the requisite code into c0015979a6/web_src/js/markup/anchors.js (L5)

@zeripath commented on GitHub (Jan 28, 2023): It honestly would be simpler to just add the requisite code into https://github.com/go-gitea/gitea/blob/c0015979a692b795bcf7416196bec01c375d7aa2/web_src/js/markup/anchors.js#L5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#10168