# Code fences don't seem to deal with C comments

**URL:** https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339
**Category:** Support
**Created:** [2015年九月16日 05:47 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339 "2015-09-16T05:47:35Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![elijah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elijah/32/104055_2.png) [@elijah](https://meta.discourse.org/u/elijah)
#### Post date: [2015年九月16日 05:47 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/1 "2015-09-16T05:47:35Z")

</div>

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?

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

```

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

```

```c
/* foo.c make comments: have fun
/* (c) never by no one
/* compile with cc or gcc or whatever
*/

```

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2015年九月16日 05:50 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/2 "2015-09-16T05:50:37Z")

</div>

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

Look at your site settings for a full list.

---

<div class="post-metadata">

### Author: ![elijah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elijah/32/104055_2.png) [@elijah](https://meta.discourse.org/u/elijah)
#### Post date: [2015年九月16日 05:52 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/3 "2015-09-16T05:52:22Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2015年九月16日 05:58 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/4 "2015-09-16T05:58:36Z")

</div>

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.

```plaintext
"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…

---

<div class="post-metadata">

### Author: ![elijah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elijah/32/104055_2.png) [@elijah](https://meta.discourse.org/u/elijah)
#### Post date: [2015年九月16日 06:03 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/5 "2015-09-16T06:03:05Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2015年九月16日 06:49 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/6 "2015-09-16T06:49:25Z")

</div>

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

---

<div class="post-metadata">

### Author: ![elijah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elijah/32/104055_2.png) [@elijah](https://meta.discourse.org/u/elijah)
#### Post date: [2015年九月16日 17:45 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/7 "2015-09-16T17:45:13Z")

</div>

[https://highlightjs.org/](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?

---

<div class="post-metadata">

### Author: ![axp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/axp/32/116685_2.png) [@axp](https://meta.discourse.org/u/axp)
#### Post date: [2015年九月16日 17:55 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/8 "2015-09-16T17:55:42Z")

</div>

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

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2015年九月16日 18:08 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/9 "2015-09-16T18:08:27Z")

</div>

> [@axp](#):
>
> … and how we can add highlight for PowerShell for example? Is it possible?

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

---

<div class="post-metadata">

### Author: ![elijah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elijah/32/104055_2.png) [@elijah](https://meta.discourse.org/u/elijah)
#### Post date: [2015年九月16日 18:22 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/10 "2015-09-16T18:22:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![johnmuhl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johnmuhl/32/43413_2.png) [@johnmuhl](https://meta.discourse.org/u/johnmuhl)
#### Post date: [2015年九月16日 18:40 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/11 "2015-09-16T18:40:31Z")

</div>

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

```plaintext
echo 'no language'
X = N + 3

```

```bash
echo 'language bash'
X = N + 3

```

```plaintext
console.log('no language')
var x = n + 3

```

```plaintext
console.log('language js')
var x = n + 3

```

```plaintext
puts "no language"
x = n + 3

```

```ruby
puts "language ruby"
x = n + 3

```

---

<div class="post-metadata">

### Author: ![rumpelsepp](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@rumpelsepp](https://meta.discourse.org/u/rumpelsepp)
#### Post date: [2015年九月16日 18:50 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/12 "2015-09-16T18:50:12Z")

</div>

> [@johnmuhl](#):
>
> it usually guesses right.

it usually guesses ~~right~~ false.

```plaintext
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.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2015年九月16日 20:24 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/13 "2015-09-16T20:24:56Z")

</div>

> [@elijah](#):
>
> Can you explain how the users of Discourse can access that? (Hint: I bet you can’t.)

Hey, I already answered that here:

> [@Code fences don't seem to deal with C comments](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/4):
>
> 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…

not fair…

---

<div class="post-metadata">

### Author: ![elijah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elijah/32/104055_2.png) [@elijah](https://meta.discourse.org/u/elijah)
#### Post date: [2015年九月16日 20:49 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/14 "2015-09-16T20:49:28Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2015年九月16日 20:53 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/15 "2015-09-16T20:53:03Z")

</div>

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

---

<div class="post-metadata">

### Author: ![elijah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elijah/32/104055_2.png) [@elijah](https://meta.discourse.org/u/elijah)
#### Post date: [2015年九月16日 21:04 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/16 "2015-09-16T21:04:10Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2015年九月16日 21:08 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/17 "2015-09-16T21:08:56Z")

</div>

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

````

---

<div class="post-metadata">

### Author: ![elijah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elijah/32/104055_2.png) [@elijah](https://meta.discourse.org/u/elijah)
#### Post date: [2015年九月16日 21:20 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/18 "2015-09-16T21:20:28Z")

</div>

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

```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.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2015年九月16日 21:29 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/19 "2015-09-16T21:29:12Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2015年九月16日 21:35 UTC](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339/20 "2015-09-16T21:35:37Z")

</div>

It is worth opening this as an issue with highlight on this [Issues · highlightjs/highlight.js · GitHub](https://github.com/isagalaev/highlight.js/issues)

[下一頁](https://meta.discourse.org/t/code-fences-dont-seem-to-deal-with-c-comments/33339.md?page=2)
