Hugo

[bug?] highlight syntax for functional languages is wrong, but in native pygments is ok

Anybody? Is it a bug? How to fix it today? I can’t make it work correctly.

It’s hard to tell from the bug report what’s causing this. But there are two possible scenarios:

  • Chroma (which Hugo uses for syntax highlight) recognises the different tokens, but the CSS is not applied properly.
    • For instance, keywords and literal strings are given the same colour. Which makes it looks like ‘it doesn’t work properly’.
  • Chroma doesn’t recognise particular tokens in the syntax.

Can you show the Hugo-rendered HTML for the languages you have a trouble with? That way we can determine if it’s point one or two from above.

It also helps if you can tell what’s wrong. The screenshots on GitHub help, but I do not see ‘huge differences’ or something that’s ‘really bad’. I count four differences: atom, swap, thread/sleep, and pmap. But I of course don’t know how your language should look in the first place.

Thanks @Jura.

I updated issue on github about HTML generated by Hugo. It looks like HTML it wrong generated.

but I do not see ‘huge differences’

For example the first word in () is always a function which is called. It should be different colour. def, defn are language functions. Values like 0 should be in different colours. Keywords like :foo.

Generally if it will be done like in http://pygments.org/ it will be good enough.

This is the code from my blog, which I am trying to move to Hugo:
http://clojure.wladyka.eu/posts-output/2016-04-06-share-state.html

It is hard to describe how it should be highlighted. You will have to understand Clojure syntax to understand it probably :slight_smile: At least I am not sure how to describe it to you easy. But the point is it works with https://highlightjs.org/ and http://pygments.org/ but not with Hugo.

I am generating it in md file by:

```clojure
(def counter (atom 0))
(def foo (atom 1))
(defn slow-inc [n]
(swap! counter inc)
(Thread/sleep 200)
(inc n))

(pmap
(fn [_]
(swap! foo slow-inc))
(range 100))

@counter
@foo
=> 1602
=> 101
```

Thanks for the added information!

The problem isn’t with Hugo but with Chroma. Some of the keywords – if that’s how they’re called in Clojure – are not in Chroma’s lexer at this time. So it isn’t a bug or error, but more like a missing feature.

I see you already opened an issue in the Chroma repository. :+1:

Once it gets fixed in Chroma, with the next release of Chroma the fixes also come in the subsequent release of Hugo. :slight_smile:

@Jura
I updated an issue. It looks like in Chroma it works.

Any idea why it doesn’t work? I still suffer this issue.