The discussion addresses issues with Discourse code fences failing to correctly highlight C comments when the content inside resembles code. elijah reports that using c fences sometimes results in incorrect syntax highlighting, whereas cpp works as expected. sam clarifies that Discourse does not support a language tag named ‘c’, suggesting users use ‘cpp’ instead. The conversation reveals that the list of supported languages is controlled by the highlighted_languages site setting, which is not visible to regular users but can be accessed via browser developer tools sam. codinghorror notes that Discourse relies on the highlight.js library for syntax highlighting.
The root cause is identified by isagalaev, the author of highlight.js, who explains that the library’s heuristics can fail when code inside a comment looks like executable code. He confirms that explicitly setting the language (e.g., cpp) is the correct workaround. The community discusses the limitations of auto-detection and the lack of a user-friendly list of supported languages elijah. Finally, johnmuhl points out that Discourse’s Markdown implementation does not fully adhere to the CommonMark standard, meaning advanced features like using longer fences to escape backticks may not work as expected.
Each of these is ```c new line and comment then a close fence but all look different. Am I doing it wrong, or is this a bug?
/* example.c -- here is an example of quoting
* a single simple c comment
*/
/*
To use this program, compile it -- if you can -- and then type something like:
chan -n 5000 -d 2 < input.txt
In this case, it will produce 5000 words of output, checking two-word groups. (The explanation above describes two-word generation. If you type "-d 3", the program will find three-word groups, and so on. Greater depths make more sense, but they require more input text and take more time to process.)
http://www.eblong.com/zarf/markov/
*/
/* foo.c make comments: have fun
/* (c) never by no one
/* compile with cc or gcc or whatever
*/
Whose site settings? I’m a discourse user, not admin. Anything that’s hidden in adminland is outside of my view. Is there a list of these for regular users to know what names / labels to use?
It’s okay not to have an auotcomplete thing, I find the Discourse implentation very clunky (but as it could be me, I have not raised the issue), but a non hidden list of syntax-known languages would be nice. I can see from that list, that I would have guessed wrong for makefiles, too. (I’d think of it as “make”.) And I have to wonder if “bash” is really bash or the whole sh/(d)ash/ksh/bash family.
https://highlightjs.org/ says “135 languages”. The box in Sam’s post has 24. If Discourse is not going to have the full set, how will I know what I can use, short of experimentation?
Ah, maybe I was being dense, but I hadn’t realized you meant “dev tools” in my browser, I thought it was some Discourse interface. Opening the Firefox web console and entering that does show the list quoted above.
It’s a command I am likely to never remember without a cheat sheet.
/*
To use this program, compile it -- if you can -- and then type something like:
chan -n 5000 -d 2 < input.txt
In this case, it will produce 5000 words of output, checking two-word groups. (The explanation above describes two-word generation. If you type "-d 3", the program will find three-word groups, and so on. Greater depths make more sense, but they require more input text and take more time to process.)
http://www.eblong.com/zarf/markov/
*/
I dunno. That doesn’t look like it dectected a C (or to be pedantic, C preprocessor) comment.
Edit:
Is it just highlight.js weirdness? Let’s label that cpp:
/*
To use this program, compile it -- if you can -- and then type something like:
chan -n 5000 -d 2 < input.txt
In this case, it will produce 5000 words of output, checking two-word groups. (The explanation above describes two-word generation. If you type "-d 3", the program will find three-word groups, and so on. Greater depths make more sense, but they require more input text and take more time to process.)
http://www.eblong.com/zarf/markov/
*/
Nope, that looks fine. I think the guessing is failing. Which is why I wanted to label it in the first place.
I see, it’s because you have something that looks like code inside the comment. Anyway, in the vast majority of cases highlight will guess the code correctly without having to look up and type in the actual language shortcode.