-
-
Notifications
You must be signed in to change notification settings - Fork 67
Improve code syntax highlighting and formatting in Sphinx #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
One suggestion from @swzCuroverse: https://github.com/carbon-app/carbon |
Getting some good results changing Sphinx settings. Looks like we won't need anything added to the theme 🎉 |
I was using Before and after for comparison, updating the pull request soon. Other improvements:
Unfortunately the |
…hting and formatting
Last thing I'll try after lunch is to make the lexer recognize more Linux commands. It highlights Glad that @swzCuroverse raised this issue during the review, since I had to modify about 20 code blocks. It would have been a much bigger task if we already had written a lot more sections of the user guide 😵💫 |
Going to leave the extra commands highlighting for another time. I customized the from pygments.token import Name
from pygments.lexers.shell import BashSessionLexer
class CwlBashSessionLexer(BashSessionLexer):
def __init__(self, **options):
super(CwlBashSessionLexer, self).__init__(**options)
self._innerLexerCls.tokens['basic'].append(
(r'\b(pip|python|cwltool|cwl-runner)(?=[\s)`])', Name.Builtin)
)
lexers['console'] = CwlBashSessionLexer() The lexer used for the At least the new syntax highlighting must make it a lot easier for readers to distinguish commands and output. |
…hting and formatting
I tried using different styles for pygments, but Shell scripts are not easy to parse visually. I thought it wasn't really good, and @swzCuroverse 's review confirmed that the current output is not good enough.
In the image above, the three command-line commands are being rendered in Sphinx by pygments (MyST vs. rst doesn't really matter here I think). I had to add the
$
before the command to distinguish when the code block includes output. But adding prefixes like$
is not considered a good practice as it makes it harder for users to copy-and-paste commands.This issue is to find a better way to render commands. GitHub produces a good output. It would be good to find one that:
The text was updated successfully, but these errors were encountered: