Syntax highlighting detects wrong language with function keyword

#1

This is a markdown-related bug that may end up being common in Nengo code:

nengo.Connection(a, b, function=foo)  # bar*(pi*(gamma))

with nengo.Simulator(model, dt=dt) as sim:
    sim.run(1.0)

It has something to do with the function keyword argument, in conjunction with some number of brackets afterwards (achieved by the comment above). I believe it is being auto-detected as the wrong language, because a work-around is to write:

```python
< code here >
```

nengo.Connection(a, b, function=foo)  # bar*(pi*(gamma))

with nengo.Simulator(model, dt=dt) as sim:
    sim.run(1.0)

Not sure what can be done about it on this end, but if we could for instance bias markdown towards thinking it’s Python whenever unsure that might be good. This might be commonplace since function is frequently used as a keyword argument in Nengo code.

0 Likes

#2

Discourse uses highlight.js for syntax highlighting, so if anyone really wants to dig into it, they can try to fix their automatic language detection feature.

In the meantime, there’s unfortunately no way in Discourse to set a default syntax highlighting language. We could turn off the automatic syntax highlighting detection, which would encourage people to make sure they specify a language.

Another option Discourse exposes is to limit the set of languages that can be highlighted. I went through and removed a bunch that we are unlikely to ever use; right now we have:

  • bash
  • css
  • diff
  • xml
  • ini
  • json
  • javascript
  • python

enabled. Having pared it down, that block now gets recognized as JavaScript. I think because of Nengo GUI we should probably keep JavaScript enabled, so this seems the best we can do for now.

0 Likes