1

I tried to use the json lexer in a *.rst document with sphinx. This one works:

.. code-block:: console

  //Comment
  key1: value,
  key2: value2,

But when I try to use json like this:

.. code-block:: json

  //Comment
  key1: value,
  key2: value2,

I get an error

WARNING: Could not lex literal_block as "json". Highlighting skipped.

I checked with pygmentize -L lexers | grep json but this returns, that json is on board. What is the problem here?

0

I was also wondering about this warning!

I looked into it and it turned out that the JSON lexer was available, but my code wasn't actually valid JSON, and therefore Sphinx disabled the lexer for this code snippet.

If you change your code block into valid JSON, highlighting should work again!

Note that (IIRC):

  • JSON doesn't allow comments
  • strings have to be quoted
  • dictionary values have to be enclosed in { and }
  • a comma after the final key-value-pair is not allowed

Note that if a lexer is not available, the warning message is different:

WARNING: Pygments lexer name 'xyz' is not known

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.