myst-vs-code icon indicating copy to clipboard operation
myst-vs-code copied to clipboard

Add reference syntax highlighting grammar

Open chrisjsewell opened this issue 5 years ago • 5 comments

Myst is designed to be CommonMark compliant, therefore standard Markdown syntax highlighters will work with Myst and handle the common syntaxes. However, it would be desired to have an 'extended' syntax highlighter, to cover the additional syntax introduced by Myst.

The de facto standard for syntax grammar is the TextMate grammar file, with support in Eclipse, Atom, VSCode, Sublime, etc (jupyterlab/jupyterlab#5504 also discusses their potential incorporation). Therefore, it would be good to have a reference implementation (tested somehow?) in this package.

Here are some helpful links:

  • https://www.apeth.com/nonblog/stories/textmatebundle.html
  • https://benparizek.com/notebook/notes-on-how-to-create-a-language-grammar-and-custom-theme-for-a-textmate-bundle
  • https://medium.com/@model_train/creating-universal-syntax-highlighters-with-iro-549501698fd2

chrisjsewell avatar Feb 22 '20 02:02 chrisjsewell

It should also be considered whether the specific syntaxes discussed in ExecutableBookProject/sphinx-notebook#12 would be incorporated here. For example with:

```{execute} python
print('hi')
```

It would be desired that the block content was syntax highlighted as python code.

Perhaps there could be a script that auto-generated grammar files with additional highlighting rules for specific directives.

chrisjsewell avatar Feb 22 '20 02:02 chrisjsewell

I think it sounds useful - how is this different from the LSP stuff?

Is the idea that the textmate grammar file would be the "official" reference implementation, then?

choldgraf avatar Feb 22 '20 07:02 choldgraf

how is this different from the LSP stuff?

This is essentially a pre-cursor to a full LSP. LSP uses TextMate bundles for static syntax highlighting (there's actually no way yet to do it dynamically microsoft/language-server-protocol#18). The LSP then builds on this to add dynamic stuff like document outlines, auto-completion, linting, etc.

Is the idea that the textmate grammar file would be the "official" reference implementation, then?

Yep, then it could be used by editor specific extension packages, like for VS Code or Jupyter Lab (hopefully).

chrisjsewell avatar Feb 22 '20 08:02 chrisjsewell

FYI @jstac @mmcky (see the readme for use)

chrisjsewell avatar Mar 18 '20 17:03 chrisjsewell

Beautiful! @mtiley, @najuzilu, if you're using VS Code for the transfer project, this will significantly increase your QOL.

jstac avatar Mar 18 '20 18:03 jstac