How do I select a language in code blocks?


(Dan Fabulich) #1

Is there a way to suggest a <code> highlighting language in a Discourse post? SE uses a magic HTML comment; that mechanism doesn’t appear to work in Discourse.


Post format reference documentation
(Sam Saffron) #2
3.times do |stuff|
  stuff.do
end
3.times do |stuff|
  stuff.do
end
```
3.times do |stuff|
  stuff.do
end
```

```ruby
3.times do |stuff|
  stuff.do
end
```

(Dan Fabulich) #3

Nice trick! That triple backtick thing is also different from StackExchange; I believe it’s a Github-flavored Markdown innovation.

What language names are supported with triple backtick?


(Sam Saffron) #4

Most of the languages here https://highlightjs.org/


(Dan Fabulich) #5

Why not all? Where’s the supported list?

(I note that cs works but csharp doesn’t. objectivec works but objc doesn’t.)


(Sam Saffron) #6

we use the default package, Getting highlight.js we need to add a facility to allow people to customise and select more stuff if they wish, PR in this department welcome.


Adding additional languages to highlight.js used by Discourse
(Dan Fabulich) #7

Looks like the magic is in app/assets/javascripts/discourse/dialects/code_dialect.js

var acceptableCodeClasses =
  ["lang-auto", "1c", "actionscript", "apache", "applescript", "avrasm", "axapta", "bash", "brainfuck",
   "clojure", "cmake", "coffeescript", "cpp", "cs", "css", "d", "delphi", "diff", "xml", "django", "dos",
   "erlang-repl", "erlang", "glsl", "go", "handlebars", "haskell", "http", "ini", "java", "javascript",
   "json", "lisp", "lua", "markdown", "matlab", "mel", "nginx", "objectivec", "parser3", "perl", "php",
   "profile", "python", "r", "rib", "rsl", "ruby", "rust", "scala", "smalltalk", "sql", "tex", "text",
   "vala", "vbscript", "vhdl"];

I might do a PR just to add in all of the other aliases in CSS classes reference — highlight.js 9.12.0 documentation, e.g. csharp, html, and c++.


(Sam Saffron) #8

Sure, but confirm the js pack has it implemented, I don’t think we have all languages.