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

Closed
opened 2025-11-02 06:27:50 -06:00 by GiteaMirror · 3 comments
Owner

Originally created by @qwertfisch on GitHub (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?).

Originally created by @qwertfisch on GitHub (Jun 10, 2020). - Gitea version (or commit ref): 1.11.5 - Can you reproduce the bug at https://try.gitea.io: - [X] Yes: https://try.gitea.io/qwertfisch/markdown-test/wiki/Code-blocks - [ ] No - [ ] Not relevant ## 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](https://try.gitea.io/qwertfisch/markdown-test/wiki/Code-blocks) 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?).
GiteaMirror added the type/enhancement label 2025-11-02 06:27:50 -06:00
Author
Owner

@zeripath commented on GitHub (Jun 12, 2020):

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.

@zeripath commented on GitHub (Jun 12, 2020): 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.
Author
Owner

@silverwind commented on GitHub (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.

@silverwind commented on GitHub (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.
Author
Owner

@qwertfisch commented on GitHub (Jun 12, 2020):

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.

@qwertfisch commented on GitHub (Jun 12, 2020): 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#5525