Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HolyC Syntax Highlighting? #22904

Closed
ghost opened this issue Feb 14, 2023 · 14 comments
Closed

HolyC Syntax Highlighting? #22904

ghost opened this issue Feb 14, 2023 · 14 comments
Labels
type/proposal The new feature has not been accepted yet but needs to be discussed first. type/upstream This is an issue in one of Gitea's dependencies and should be reported there

Comments

@ghost
Copy link

ghost commented Feb 14, 2023

Feature Description

Would it be possible to get HolyC syntax highlighting for Gitea? I am working on a Git site dedicated around the language, but the fact that there is no syntax highlighting really takes away from the general aesthetic.

HolyC is really similar to C in terms of syntax except for really variables and function names. Below is a screenshot of said implementation on GitHub.

I understand this may be a very niche topic, and likely may not be added, however in that case, could I atleast be provided with documentation on writing the syntax highlighting manually? Thanks.

Screenshots

Screenshot_2023-02-14-04-34-09_1920x1080

@ghost ghost added type/feature Completely new functionality. Can only be merged if feature freeze is not active. type/proposal The new feature has not been accepted yet but needs to be discussed first. labels Feb 14, 2023
@JakobDev
Copy link
Contributor

You might want to create a Issue for Chroma, which is the Syntax Highlighter used by Gitea. If you want it to do yourself, you can find the Lexer for C here. If you have good knowledge of the Syntax, you can create a Lexer for HolyC based on this and make a PR.

@wxiaoguang
Copy link
Contributor

Workaround: or use gitattributes to tell the highlighter that some files are C code. Like this one:

@ghost
Copy link
Author

ghost commented Feb 14, 2023

You might want to create a Issue for Chroma, which is the Syntax Highlighter used by Gitea. If you want it to do yourself, you can find the Lexer for C here. If you have good knowledge of the Syntax, you can create a Lexer for HolyC based on this and make a PR.

Ah my nightmare, Regex. I knew I'd have to learn it eventually. Honestly though, thank you so much for this, I don't think HolyC will be that hard to manufacture using this. Appreciate it.

@silverwind
Copy link
Member

silverwind commented Feb 14, 2023

If it works with c syntax, you could contribute the addition of the file extension (assuming it has a unique one) to chroma's c lexer and gitea will then automatically pick it up based on the file extension after we update chroma.

@silverwind
Copy link
Member

silverwind commented Feb 14, 2023

As per github-linguist/linguist#4512, Github does match it based on the .hc extension, so unless this extension is already in use at Chroma somewhere else, it should be possible to get it added.

@ghost
Copy link
Author

ghost commented Feb 14, 2023

Realistically, this looks like it should be a breeze to do considering it seems that the GitHub format is very similar to Chroma. From what @silverwind linked, I found this: https://github.com/codingdandy/holyc.tmbundle which should be sufficient.

@silverwind
Copy link
Member

Yeah, so the job is to start with https://github.com/alecthomas/chroma/blob/master/lexers/embedded/c.xml and adapt the individual rules based on https://github.com/codingdandy/holyc.tmbundle/blob/master/Syntaxes/HolyC.tmLanguage to create the chroma lexer.

My earlier idea of just adding an alias to the C lexer is not right, the language is too different from C to be considered an alias.

@ghost
Copy link
Author

ghost commented Feb 15, 2023

I've gone ahead and made a pull request for this on Chroma: alecthomas/chroma#750

@silverwind
Copy link
Member

Thanks, so we just need to wait until next chroma release and then update it.

@ghost
Copy link
Author

ghost commented Feb 15, 2023

Is that it @silverwind? I thought I had to edit "go-enry" or something

@lunny lunny added type/upstream This is an issue in one of Gitea's dependencies and should be reported there and removed type/feature Completely new functionality. Can only be merged if feature freeze is not active. labels Feb 16, 2023
@silverwind
Copy link
Member

For the syntax highlighting, chroma is enough.

https://github.com/go-enry/go-enry is used for the language stats bar, but it may be that they already support HolyC given that they source some data from linguist, but if you like, please double-check.

@ghost
Copy link
Author

ghost commented Feb 17, 2023

For the syntax highlighting, chroma is enough.

https://github.com/go-enry/go-enry is used for the language stats bar, but it may be that they already support HolyC given that they source some data from linguist, but if you like, please double-check.
Alrighty, looks like HolyC is already there. Is there any way to force my gitea build to use the latest of Chroma, not the latest version since my PR wasn't packaged but instead the branch?

Well I'm not sure if that worked, I figured I could do:

go get -u github.com/alecthomas/chroma
go mod tidy
TAGS="bindata sqlite sqlite_unlock_notify" make build

However on a repo it's still recoginzed as "PlainText":
Git
I'm not sure if I was unable to get the latest commit, or if my additions dont work.

@silverwind
Copy link
Member

Try:

go get -u github.com/alecthomas/chroma/v2@3ac94eea73f5de1bf6c864b9a7f4089514415090

@ghost
Copy link
Author

ghost commented Feb 19, 2023

That worked! Thanks all!

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/proposal The new feature has not been accepted yet but needs to be discussed first. type/upstream This is an issue in one of Gitea's dependencies and should be reported there
Projects
None yet
Development

No branches or pull requests

4 participants