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

Code blocks in Wiki are rendered with arbitrary syntax highlighting instead of none #11825

Closed
1 of 3 tasks
qwertfisch opened this issue Jun 10, 2020 · 3 comments · Fixed by #12047
Closed
1 of 3 tasks
Labels
type/enhancement An improvement of existing functionality
Milestone

Comments

@qwertfisch
Copy link

qwertfisch commented Jun 10, 2020

Description

When adding a code block on a page in the built-in wiki, but with no language given for syntax highlighting, this block will be rendered using an arbitrarily chosen highlighting. Code blocks without selected syntax I will set like this:

```
This is simple text rendered with fixed-width font,
but no syntax highlighting.
```

Even if the text inside the block would contain keywords for some languages, I do not expect them to be highlighted or rendered other than as fixed-width font. In fact when given no language for the code block, I expect the language to be None.

Actual result

When selecting the preview window, or after storing the page, a second later a seemingly arbitrarily chosen syntax highlighting is applied to the block. On the example page I added some keywords (for some languages), and the two blocks are rendered as Cal and Vim, respectively. It seems the highlighting is selected automatically given the content of the block.

Workaround

I can enclose the block with <pre> / </pre> instead of Markdown. Is there otherwise a possibility to have a non-syntaxed code block with Markdown syntax?
Edit: <pre> does not set the content to a fixed-width font, so this is unfortunately no solution.

Is this a bug for Gitea? Or should I file a bug on the Markdown interpreter used (goldmark?).

@zeripath
Copy link
Contributor

This is not the fault of goldmark.

Gitea uses highlightjs for syntax highlighting of code blocks and as far as I understand highlightjs will automatically attempt to detect the language.

It's probable that if you put plaintext after the backticks that would turn it off.

@silverwind
Copy link
Member

silverwind commented Jun 12, 2020

Valid bug. We should put the plaintext class on <code> to prevent hljs from autodetection in case the user did not specify a language in markdown.

@qwertfisch
Copy link
Author

An automatically selected highlighting is welcome – just not when it is not expected. I could not find a documentation of this feature before.

plaintext works and selects the plaintext syntax from hljs, thanks for the advice. Also any other name unknown for hljs would work and use a language-[name] class, which defaults to no highlighting.

mrsdizzie added a commit to mrsdizzie/gitea that referenced this issue Jun 24, 2020
This PR does a few things:

* Remove all traces of highlight.js
* Use chroma library to provide fast syntax hilighting directly on the server
* Provide syntax hilighting for diffs
* Re-style both unified and split diffs views
* Add custom syntax hilighting styling for both regular and arc-green

Fixes go-gitea#7729
Fixes go-gitea#10157
Fixes go-gitea#11825
Fixes go-gitea#7728
Fixes go-gitea#3872
Fixes go-gitea#3682

And perhaps gets closer to go-gitea#9553
@lafriks lafriks added this to the 1.13.0 milestone Jun 30, 2020
@lafriks lafriks added the type/enhancement An improvement of existing functionality label Jun 30, 2020
lafriks added a commit that referenced this issue Jun 30, 2020
* Server-side syntax hilighting for all code

This PR does a few things:

* Remove all traces of highlight.js
* Use chroma library to provide fast syntax hilighting directly on the server
* Provide syntax hilighting for diffs
* Re-style both unified and split diffs views
* Add custom syntax hilighting styling for both regular and arc-green

Fixes #7729
Fixes #10157
Fixes #11825
Fixes #7728
Fixes #3872
Fixes #3682

And perhaps gets closer to #9553

* fix line marker

* fix repo search

* Fix single line select

* properly load settings

* npm uninstall highlight.js

* review suggestion

* code review

* forgot to call function

* fix test

* Apply suggestions from code review

suggestions from @silverwind thanks

Co-authored-by: silverwind <me@silverwind.io>

* code review

* copy/paste error

* Use const for highlight size limit

* Update web_src/less/_repository.less

Co-authored-by: Lauris BH <lauris@nix.lv>

* update size limit to 1MB and other styling tweaks

* fix highlighting for certain diff sections

* fix test

* add worker back as suggested

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Lauris BH <lauris@nix.lv>
ydelafollye pushed a commit to ydelafollye/gitea that referenced this issue Jul 31, 2020
* Server-side syntax hilighting for all code

This PR does a few things:

* Remove all traces of highlight.js
* Use chroma library to provide fast syntax hilighting directly on the server
* Provide syntax hilighting for diffs
* Re-style both unified and split diffs views
* Add custom syntax hilighting styling for both regular and arc-green

Fixes go-gitea#7729
Fixes go-gitea#10157
Fixes go-gitea#11825
Fixes go-gitea#7728
Fixes go-gitea#3872
Fixes go-gitea#3682

And perhaps gets closer to go-gitea#9553

* fix line marker

* fix repo search

* Fix single line select

* properly load settings

* npm uninstall highlight.js

* review suggestion

* code review

* forgot to call function

* fix test

* Apply suggestions from code review

suggestions from @silverwind thanks

Co-authored-by: silverwind <me@silverwind.io>

* code review

* copy/paste error

* Use const for highlight size limit

* Update web_src/less/_repository.less

Co-authored-by: Lauris BH <lauris@nix.lv>

* update size limit to 1MB and other styling tweaks

* fix highlighting for certain diff sections

* fix test

* add worker back as suggested

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Lauris BH <lauris@nix.lv>
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants