python-sphinxrestructuredtexttmlanguage

How to add a custom tmLanguage syntax to Sphinx/RST


Is there a method to import a tmLanguage.json into Sphinx to add support for a new/custom language for RST?


Solution

  • There is not directly; if necessary you'll have to write a lexer for a new language in Python. I say if necessary because Sphinx's syntax highlighting is provided under the hood by Pygments, which supports a huge number of languages; you just need to turn support on in Sphinx using the highlight_language config value. The short names for all the various lexers are shown here.

    If, somehow, your language doesn't have a lexer already, there are instructions on how to write your own. It's largely (but not entirely) a process of translating the Oniguruma regexes in the .tmLanguage.json file to Python-flavored ones.

    One would also hope that you'd contribute it to the pygments Github project, too.