Skip to content

Syntax Highlighting Errors when Diffing - Fixed Format Fortran #19684

@smf007

Description

@smf007

Description

The chroma library had added a fixed format fortran syntax highlighter back in version v0.9.2, which gitea started using as of v1.15.0-RC1. The fortran fixed format syntax highlighting works for displaying files in gitea, however it is broken when displaying a diff of changes.

This can be see using the try.gitea portal:

The syntax highlighting is correct
https://try.gitea.io/test1765/fortran_test/src/branch/main/fortran_fixed.f

The syntax highlighting is incorrect when doing a diff
https://try.gitea.io/test1765/fortran_test/commit/228401fa1860d7aea71f3511937e49ee39d10938

Gitea Version

Tried both 1.16.4, 1.16.7

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

See https://try.gitea.io/test1765/fortran_test/commit/228401fa1860d7aea71f3511937e49ee39d10938

Git Version

No response

Operating System

ROCKY 8.5 (RHEL 8.5)

How are you running Gitea?

Used pre-built binaries for Linux x64, running on ROCKY Linux 8.5.

Database

No response

Activity

wxiaoguang

wxiaoguang commented on Jun 12, 2022

@wxiaoguang
wxiaoguang

wxiaoguang commented on Jun 13, 2022

@wxiaoguang
wxiaoguang

wxiaoguang commented on Jun 13, 2022

@wxiaoguang
Contributor

Another test shows that the problem is related to github.com/alecthomas/chroma@v0.10.0/lexers/f/fortran_fixed.go, which is used by inline diff highlighter

If you rename the file from test.f to test.f90 (use lexers/f/fortran.go), then the highlight in diff view is correct.

added
type/upstreamThis is an issue in one of Gitea's dependencies and should be reported there
on Jun 13, 2022
wxiaoguang

wxiaoguang commented on Jun 13, 2022

@wxiaoguang
Contributor

Workaround, either:

  • use *.f90
  • [or] set highlight.mapping in app.ini to force the *.f use Fortran instead of FortranFixed lexer.
added and removed
type/upstreamThis is an issue in one of Gitea's dependencies and should be reported there
on Jun 13, 2022
smf007

smf007 commented on Jun 17, 2022

@smf007
Author

Workaround, either:

* use `*.f90`

* [or] set `highlight.mapping` in app.ini to force the `*.f` use `Fortran` instead of `FortranFixed` lexer.

I can confirm that overriding the highlight mapping makes the diff more usable.

Looking at this more closely though, the fixed format highlighting performed by the library is itself incorrect regardless of using fortranfixed or fortran. Fortranfixed is not resolving comments as actual comments. This can be seen in the example, lines 1-5 should be greyed out as comments, but are not https://try.gitea.io/test1765/fortran_test/src/branch/main/fortran_fixed.f So my original statement above that the fixed format highlighting was correct is actually false.

wxiaoguang

wxiaoguang commented on Jun 17, 2022

@wxiaoguang
Contributor

There is a tricky thing in Gitea.

When doing whole file rendering, the extension name is not respected, instead, Gitea will guess what's the language of the source file by its content, so even if the ext name is .f, the full file view can still be rendered correctly like .f90

However, when Gitea is doing inline diff, it's done line by line without the guess, and only use the ext name as the language, then FortranFixed is used for .f, the rendered result is not ideal.

smf007

smf007 commented on Oct 26, 2022

@smf007
Author

Seems I forgot to update this issue. I had done some work upstream in Chroma for the parsing of fortran.

646 & 648 were included in Chroma 2.3.0, and 647 is in master awaiting a version tag.

Chroma 2.3.0 has been merged into Gitea 1.18.0 branch.

As the demo site is kept up to date, I need to check if the Chroma 2.3.0 inclusion has resolved most of this issue.

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

wxiaoguang commented on Jan 22, 2025

@wxiaoguang
Contributor

Is there still any problem? Or should we hard-code *.f as Fortran (but not FortranFixed)?

GiteaBot

GiteaBot commented on Feb 21, 2025

@GiteaBot
Collaborator

We close issues that need feedback from the author if there were no new comments for a month. 🍵

locked as resolved and limited conversation to collaborators on May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue/needs-feedbackFor bugs, we need more details. For features, the feature must be described in more detailissue/workaroundit is or has a workaroundtype/bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @wxiaoguang@smf007@GiteaBot

        Issue actions

          Syntax Highlighting Errors when Diffing - Fixed Format Fortran · Issue #19684 · go-gitea/gitea