feat: add data-lexer-name attribute to file-info-entry - #37791
Conversation
| {{end}} | ||
| {{if .LexerName}} | ||
| <div class="file-info-entry"> | ||
| <div class="file-info-entry" data-lexer-name="{{.LexerName}}"> |
There was a problem hiding this comment.
Since the new attribute is not used in the current code base, it needs a clear comment to describe why it is added, otherwise it would be removed in the future again when some people find that it is not used.
|
By the way, if your customized highlighting is a general requirement, it's better to add it in Gitea or upstream Chroma https://github.com/alecthomas/chroma |
|
At its core, Chroma is a lexer ported from Python's Pygments rather than being based on an Abstract Syntax Tree (AST). Because of this, its inability to recognize certain syntax is a fundamental flaw baked into its design. To work around this inherent limitation, I am planning to use frontend CSS to manually supplement and patch up the syntax that Chroma fails to recognize. |
That's a huge work. Not only frontend CSS, you also need frontend syntax parser, a lot of details then. By the way, could you show some bad cases which need to be patched? |
|
TBH, IMO it's arguable whethere they are really "bad cases" If you'd really like to patch them, what's your plan? how would the CSS selector be used? |
|
I see your description, but how to? What will you write to replace the |
So you are fighting with Chroma's highlighting result, such case should be fixed by upstream Chroma. |
|
I do not need to fight with Chroma's highlighting result. |
Chroma can't resolve this token issue like 'Port'. |
|
If I want to provide different colors for keywords in different languages, what's a better way? |
"nx" means "NameOther", you will highlight all "nx" symbols appearing in Golang source code in the end, it's impossible to only highlight the fields like "Port" in the struct. I don't think it is a right approach, while I won't block this change as long as it doesn't cause new problems and it is maintainable ( #37791 (review) ) |
|




This makes it easy to customize syntax highlighting.
e.g., in templates/custom/header.tmpl.