Syntax highlighting


Hi! I noticed that automatic syntax highlighting here is often wrong which is probably due to the Google’s syntax highlighter inherited from the original Stack Overflow engine. I happen to be a maintainer of another library highlight.js that does explicitly support Rust and we’re probably going to improve it even more as two of the core devs are now trying out Rust (me, being one of them). May be use it here instead?


Do you know how to replace the discourse syntax highlighter with yours?


We use highlight.js, thank you heaps for it

I am working today on adding a site setting that allows admins to select which highlighted languages are enabled, once that is done rust will be enabled here.


Oh, good to hear then! :slight_smile:

While enabling languages in the admin interface is one way to do it, there’s another possibility that we specifically designed for: let the user to specify language names as tags and then use the whole bulk of them in hljs.configure({languages: [...]}) to make this preference per-post, rather than per-site.

(Though we should probably move the discussion to the Discourse dev forum.)


Yeah, there are a bunch of tricky design issues I have here that ended up leading me to the design I just checked in (cdn concerns, multi hosting, caching)

we defer load the bundle, but since stuff like mathmatica is 60k minified I just wanted to avoid having a bundle that is too big. also having all the langs in lang-auto could end up giving you a bigger chance at getting a miss.

As it stands the users can either go for lang-auto with a ``` or they can pinpoint the lang with ```rust and so on.


rust syntax highlighting is now enabled here and default :heart: !

use std;

/* Factorial */
fn fac(n: int) -> int {
    let s: str = "This is
a multi-line string.

It ends with an unescaped '\"'.";
    let c: char = 'Ф';
    let r: str = r##" raw string "##;

    let result = 1, i = 1;
    while i <= n { // No parens around the condition
        result *= i;
        i += 1;
    ret result;

pure fn pure_length<T>(ls: list<T>) -> uint { /* ... */ }

type t = map::hashtbl<int,str>;
let x = id::<int>(10);

// Define some modules.
#[path = ""]
mod foo;

impl <T> Seq<T> for [T] {
    fn len() -> uint { vec::len(self) }
    fn iter(b: fn(T)) {
        for elt in self { b(elt); }

enum list<T> {
    Cons(T, @list<T>);

let a: list<int> = Cons(7, @cons(13, @nil));

struct Baz<'a> {
    baz: &'a str,

'h: for i in range(0,10) {
    'g: loop {
        if i % 2 == 0 { continue 'h; }
        if i == 9 { break 'h; }
        break 'g;