Code fences don't seem to deal with C comments

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
*/
1 Like

I think what you are looking for is ```cpp , there is no `c

Look at your site settings for a full list.

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?

1 Like

Ideally we should get an autocomplete thing going there like emoji/mention, maybe one day…

You can see the list by typing Discourse.SiteSettings.highlighted_languages into dev tools.

"apache|bash|cs|cpp|css|coffeescript|diff|xml|http|ini|json|java|javascript|makefile|markdown|nginx|objectivec|ruby|perl|php|python|sql|handlebars|scss"

Clearly not something we expect you to do…

1 Like

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.

1 Like

It’s not a Discourse implementation. Google search for highlight.js

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?

3 Likes

… and how we can add highlight for PowerShell for example? Is it possible?

1 Like

That’s what the highlighted_languages site setting is for. You can tell which languages you want to support.

1 Like

Can you explain how the users of Discourse can access that? (Hint: I bet you can’t.)

There is some kind of auto-detection so if you leave the language off it usually guesses right.

echo 'no language'
X = N + 3
echo 'language bash'
X = N + 3
console.log('no language')
var x = n + 3
console.log('language js')
var x = n + 3
puts "no language"
x = n + 3
puts "language ruby"
x = n + 3
1 Like

it usually guesses right false.

Sep 16 20:02:59 naboo NetworkManager[688]: <info>  dhclient started with pid 21499
Sep 16 20:02:59 naboo dhclient[21499]: DHCPREQUEST on wlp3s0 to 255.255.255.255 port 67
Sep 16 20:02:59 naboo dhclient[21499]: DHCPACK from 192.168.178.1
Sep 16 20:02:59 naboo NetworkManager[688]: <info>    address 192.168.178.22
Sep 16 20:02:59 naboo NetworkManager[688]: <info>    plen 24 (255.255.255.0)
Sep 16 20:02:59 naboo NetworkManager[688]: <info>    gateway 192.168.178.1
Sep 16 20:02:59 naboo NetworkManager[688]: <info>    server identifier 192.168.178.1
Sep 16 20:02:59 naboo NetworkManager[688]: <info>    lease time 864000
Sep 16 20:02:59 naboo NetworkManager[688]: <info>    nameserver '192.168.178.1'
Sep 16 20:02:59 naboo NetworkManager[688]: <info>    domain name 'fritz.box'
Sep 16 20:02:59 naboo NetworkManager[688]: <info>  (wlp3s0): DHCPv4 state changed unknown -> bound
Sep 16 20:02:59 naboo NetworkManager[688]: <info>  (wlp3s0): device state change: ip-config -> ip-check (reason 'none') [70 80 0]
Sep 16 20:02:59 naboo NetworkManager[688]: <info>  (wlp3s0): device state change: ip-check -> secondaries (reason 'none') [80 90 0]

My recommended default highlighting is plain text. People posting server logs or shell commands end up with strange, colored text.

1 Like

Hey, I already answered that here:

not fair…

1 Like

You’ve implied that it is a site setting and that makes it sound like what is true for here might not be true on Boingboing or wherever else.

It is true everywhere, that command you would run in console may return different results depending on which site you run it on.

1 Like

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.

/* example.c -- here is an example of quoting
 * a single simple c comment
 */

You are over thinking this… you don’t need to post anything other than the fence (three backticks)

```
/* 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/
*/

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.

1 Like

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.

It is worth opening this as an issue with highlight on this https://github.com/isagalaev/highlight.js/issues

1 Like