#35 Repo: Undesirable Plain Text Syntax Highlighting

Closed
opened 3 years ago by Ghost · 12 comments
Ghost commented 3 years ago

Maybe because of the pygments implementation, plain text files started to get highlighted.

Test:

gogs.io example 1 - OK
teknik.io example 1
teknik.io example 2
teknik.io example 3

Maybe because of the [pygments implementation](http://git.teknik.io/Teknikode/Teknik/commit/04c2e657ab2a2ee5ff13ec1624439034048e8d11), plain text files started to get highlighted. Test: [gogs.io example 1](https://try.gogs.io/gogs/gogs/src/develop/LICENSE) - OK [teknik.io example 1](https://git.teknik.io/Teknikode/Teknik/src/master/license.txt) [teknik.io example 2](https://git.teknik.io/dmz76/test/src/master/test1.txt) [teknik.io example 3](https://git.teknik.io/dmz76/test/src/master/test2.txt)
Uncled1023 commented 3 years ago
Owner

I checked the commits since the last release of gogs, and I don’t see any that signify a change in the syntax highlighting.

Once thought is that the example on Gogs doesn’t have an extension, while the ones here do. That could be throwing off the syntax highlighting, not sure.

The pygments implementation was only for Pastes, so this issue doesn’t apply to it. The implementation for syntax highlighting in the git repos is handled by Gogs.

I checked the commits since the last release of gogs, and I don't see any that signify a change in the syntax highlighting. Once thought is that the example on Gogs doesn't have an extension, while the ones here do. That could be throwing off the syntax highlighting, not sure. The pygments implementation was only for Pastes, so this issue doesn't apply to it. The implementation for syntax highlighting in the git repos is handled by Gogs.
Ghost commented 3 years ago
Poster

You’re quite right. I assumed maybe it was related to pygments because I researched in advance in gogs issues and found Syntax highlighting is done on plain text LICENSE files which was fixed, but as you suggest, and correctly, it’s only working for files with no extension.

The following example confirms that it’s a gogs issue. I’ll contact them. Thanks and closing.

teknik.io example 4 - OK

[EDIT] Actually the gogs team fixed it only for files specifically named LICENSE! I can’t believe this decision but I already posted a follow up to the syntax highlighting issue.

You're quite right. I assumed maybe it was related to pygments because I researched in advance in gogs issues and found [Syntax highlighting is done on plain text LICENSE files](https://github.com/gogits/gogs/issues/2181) which was fixed, but as you suggest, and correctly, it's only working for files with no extension. The following example confirms that it's a gogs issue. I'll contact them. Thanks and closing. [teknik.io example 4](https://git.teknik.io/dmz76/test/src/master/LICENSE) - OK [EDIT] Actually the gogs team fixed it only for files specifically named `LICENSE`! I can't believe this decision but I already posted a follow up to the syntax highlighting issue.
Uncled1023 commented 3 years ago
Owner

Haha, wow that’s a weird way that they fixed it. Thanks for bringing it to their attention (and mine!)

Haha, wow that's a weird way that they fixed it. Thanks for bringing it to their attention (and mine!)
Ghost commented 3 years ago
Poster

@Uncled1023 In the meantime, since I didn’t get a response yet (I posted it as a new issue in gogs GH page), I found this thread on gogs, which added the ability to map extensions for syntax highlighting in config.

Commit
1e7e092992

Example

[highlight.mapping]
.toml=ini

Now, since the objective is to not highlight plain text, what should the example above be like? Not sure if this solves it.

[EDIT] Maybe leaving the value empty as in .txt=? I know highlight.js has a nohighlight CSS class but that would require a CSS txt extension attribute selector hack.

@Uncled1023 In the meantime, since I didn't get a response yet (I posted it as a new issue in gogs GH page), I found [this](https://github.com/gogits/gogs/issues/2103) thread on gogs, which added the ability to map extensions for syntax highlighting in config. Commit https://github.com/gogits/gogs/commit/1e7e092992164acc243ec01859509eaa2207196d Example ``` [highlight.mapping] .toml=ini ``` Now, since the objective is to **not highlight** plain text, what should the example above be like? Not sure if this solves it. [EDIT] Maybe leaving the value empty as in `.txt=`? I know highlight.js has a `nohighlight` CSS class but that would require a CSS `txt` extension attribute selector hack.
Ghost commented 3 years ago
Poster

@Uncled1023 Maybe my guess was right. According to Unknwon, Gog’s dev, there’s probably a way to disable highlighting for the .txt extension, using highlightjs built-in nohighlight class in Gog’s app.ini.

What do you think about it?

[highlight.mapping]
.txt=nohighlight

EDIT: BTW, they didn’t fix it only for LICENSE files. Specific filenames can be ignored by highlighting.

@Uncled1023 Maybe my guess was right. According to Unknwon, Gog's dev, there's probably a way to [disable highlighting](https://github.com/gogits/gogs/issues/2181#issuecomment-268517064) for the `.txt` extension, using highlightjs built-in `nohighlight` class in Gog's `app.ini`. What do you think about it? ``` [highlight.mapping] .txt=nohighlight ``` EDIT: BTW, they didn't fix it only for `LICENSE` files. Specific filenames can be [ignored](https://github.com/gogits/gogs/blob/master/modules/template/highlight/highlight.go#L16) by highlighting.
Uncled1023 commented 3 years ago
Owner

Huh interesting. I can test it out to see if it works. I think it will as Unknwon said.

Huh interesting. I can test it out to see if it works. I think it will as Unknwon said.
Ghost commented 3 years ago
Poster

OK, let me know the outcome.

OK, let me know the outcome.
Ghost commented 3 years ago
Poster

Somewhat fixed in develop branch. Closing.

Somewhat [fixed](https://github.com/gogits/gogs/issues/3865#issuecomment-275482620) in `develop` branch. Closing.
Ghost commented 2 years ago
Poster

@Uncled1023

Since you switched to Gitea, can you try adding to app.ini

[highlight.mapping]
.txt=nohighlight

to see if syntax highlighting is disabled on plain text files?

@Uncled1023 Since you switched to Gitea, can you try adding to `app.ini` ``` [highlight.mapping] .txt=nohighlight ``` to see if syntax highlighting is disabled on plain text files?
Uncled1023 commented 2 years ago
Owner

Alright, thanks. Let me see how it works.

Alright, thanks. Let me see how it works.
Uncled1023 commented 2 years ago
Owner

Ok, should be working now.

Ok, should be working now.
Ghost commented 2 years ago
Poster

Finally. Thanks, plain text files look better now. Closing.

Finally. Thanks, plain text files look better now. Closing.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
Cancel
Save
There is no content yet.