user_guide icon indicating copy to clipboard operation
user_guide copied to clipboard

CWL examples could have better syntax highlighting

Open mr-c opened this issue 2 years ago • 10 comments

Sphinx uses pygments for code highlighting

https://pygments.org/docs/lexerdevelopment/

(see also https://github.com/common-workflow-language/common-workflow-language/issues/784 )

mr-c avatar Oct 10 '22 11:10 mr-c

Sphinx uses pygments for code highlighting

https://pygments.org/docs/lexerdevelopment/

(see also common-workflow-language/common-workflow-language#784 )

I noticed yaml is currently used as the lexer in the guide, @kinow picked it. Are you suggesting a new lexer is created for pygments?

smyja avatar Oct 10 '22 14:10 smyja

Sphinx uses pygments for code highlighting https://pygments.org/docs/lexerdevelopment/ (see also common-workflow-language/common-workflow-language#784 )

I noticed yaml is currently used as the lexer in the guide, @kinow picked it. Are you suggesting a new lexer is created for pygments?

Yes, we need a better lexer to distinguish between CWL keywords and user supplied names and values

mr-c avatar Oct 10 '22 15:10 mr-c

Sphinx uses pygments for code highlighting https://pygments.org/docs/lexerdevelopment/ (see also common-workflow-language/common-workflow-language#784 )

I noticed yaml is currently used as the lexer in the guide, @kinow picked it. Are you suggesting a new lexer is created for pygments?

Yes, we need a better lexer to distinguish between CWL keywords and user supplied names and values

Okay, I'll create a repo and tag you to review once I'm done before creating a pr in the pygments repo.

smyja avatar Oct 10 '22 15:10 smyja

So this seems to be doable -

  • First you need to make a new lexer for pygments (https://pygments.org/docs/lexers/)
  • You can either try to add it to the pygments open source project OR you can change the code to refer to it a local lexer which might be a good stop-gap solution
  • To make the lexer - instead of developing it from scratch there is a tool to convert existing vim-highlighting to lexer - since we have an existing vim plugin for CWL -- you can convert to the the proper format, test it out, if it looks good then we are set
  • https://github.com/manabuishii/vim-cwl
  • https://github.com/honza/vim2pygments
  • https://stackoverflow.com/questions/48615629/how-to-include-pygments-styles-in-a-sphinx-project thoughts @kinow

swzCuroverse avatar Dec 20 '22 12:12 swzCuroverse

@Mackenzie-OO7 is going to work on this.

swzCuroverse avatar Dec 20 '22 13:12 swzCuroverse

Everything sounds right to me @swzCuroverse . Great job with the action plan! I did not have time, so I just used YAML. But it is definitely a very interesting task to anyone interested in programming (and compilers, interpreters, programming languages, and so on).

kinow avatar Dec 20 '22 13:12 kinow

So this seems to be doable -

  • First you need to make a new lexer for pygments (https://pygments.org/docs/lexers/)
  • You can either try to add it to the pygments open source project OR you can change the code to refer to it a local lexer which might be a good stop-gap solution
  • To make the lexer - instead of developing it from scratch there is a tool to convert existing vim-highlighting to lexer - since we have an existing vim plugin for CWL -- you can convert to the the proper format, test it out, if it looks good then we are set
  • https://github.com/manabuishii/vim-cwl
  • https://github.com/honza/vim2pygments
  • https://stackoverflow.com/questions/48615629/how-to-include-pygments-styles-in-a-sphinx-project thoughts @kinow

Hi, I ran into an issue while trying to convert the vim plugin. When I try to generate the css file by running ./pygmentize -S cwl -f html -a .highlight > cwl.css I get the error: /usr/bin/env: ‘python2’: No such file or directory

Mackenzie-OO7 avatar Dec 21 '22 04:12 Mackenzie-OO7

Looks like the version of pygmentise you are using needs Python 2. Some software older than a few years might have a Python 2 version, but also a newer Python 3. You need to confirm the version you have installed and try to update to a newer version, if available.

If you are using the instructions from https://github.com/honza/vim2pygments, I see one of their commits from 9 years ago has this message "make it work with python 3+". So it should work.

kinow avatar Dec 21 '22 08:12 kinow

Looks like the version of pygmentise you are using needs Python 2. Some software older than a few years might have a Python 2 version, but also a newer Python 3. You need to confirm the version you have installed and try to update to a newer version, if available.

If you are using the instructions from https://github.com/honza/vim2pygments, I see one of their commits from 9 years ago has this message "make it work with python 3+". So it should work.

I have Python 3 installed. Yup, I'm following the instructions from https://github.com/honza/vim2pygments, and I got that error.

Mackenzie-OO7 avatar Dec 21 '22 08:12 Mackenzie-OO7

In looking forward - it looks like this might just create a style instead of a lexer that is needed. Let me do a little more research - although the style might be useful.

swzCuroverse avatar Dec 22 '22 21:12 swzCuroverse