Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Syntax highlighting in forum posts

A topic by leafo created May 25, 2022 Views: 2,347 Replies: 3
Viewing posts 1 to 3
Admin (1 edit) (+3)

We’ve enabled syntax highlighting support for forum posts for communities. (Any place where a comment is rendered inside of itch.io’s UI)

Syntax highlighting is performed client-side using the Prism library. We’ve exported the library with every single language it supports. You can activate syntax highlighting by having a pre tag with the class language-XXX on it (where XXX is the language you wish to highlight for.

local function hello_world()
  print("Hello world")
end

For markdown we support using the ```language syntax that is available on other platforms like GitHub.

For those using the rich text editor, you will have to manually edit the HTML to add the class at the time being.

Note: This is not yet available in comments yet, because we need to test compatibility with themed pages.

(1 edit)

Looks great! Are there plans to add (basic, non-syntax-highlighted) styling for inline code as well?

Admin (2 edits)

You can use the language css class on a <code> tag: print(3.14).

Are you looking for something else? The inline <code> tag already will use a monospace font

(4 edits)

With the syntax highlighting, it looks like you also get a smaller font size (which looks better with a monospace font), as well as a different background color. So that’s cool.

Ideally, both of those would also be set when using inline code from markdown backticks as well. Right now, that just gets size 18 monospace, no background or border to distinguish it from surrounding text.

  • Markdown inline code: hello
  • HTML inline code: hello
  • HTML inline code with language class: hello