Skip to content
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

Support doctest in Python lexer #1932

Merged
merged 1 commit into from Apr 2, 2023

Conversation

tancnle
Copy link
Collaborator

@tancnle tancnle commented Feb 14, 2023

Add support to highlight doctest in Python lexer.

Before After
before after

Resolves #920

@tancnle
Copy link
Collaborator Author

tancnle commented Feb 14, 2023

👋🏼 @Erotemic could you verify if this addresses the reported issue? 🙏🏼

@Erotemic
Copy link

Erotemic commented Feb 14, 2023

This looks great!

I'm perfectly happy with this as-is. The only thing I might suggest is that the "want" part of the doctest where you specify the expected result would be more readable if it was distinguished from the rest of the string by a different color. For example vim does it this way:

image

The logic would be that a "want" statement starts after the last >>> or ... prefix (except in the case where the line is only ... in which case it should be interpreted as an ellipsis - but that is an edge case that could be ignored) and ends whenever there is a blank newline.

However, if that's difficult to implement, then this addresses 99% of the problem and is a huge readability improvement! I can't wait to be able to read my doctests on gitlab!

@tancnle
Copy link
Collaborator Author

tancnle commented Feb 19, 2023

Thank you for the insights @Erotemic. I have rejigged the PR to provide better support for test output. I have also ensured the lexer can distinguish between ... as a prompt and a builtin. Let me know what you think.

@tancnle
Copy link
Collaborator Author

tancnle commented Feb 19, 2023

I can't wait to be able to read my doctests on gitlab

I believe GitLab only uses Rouge for language detection, not for syntax highlighting. It has switched to Highlight JS for syntax highlighting (see doc).

@Erotemic
Copy link

Let me know what you think.

That looks much better. I would call this feature complete.

It has switched to Highlight JS for syntax highlighting (see doc).

Ah, good to know. Well more doctest support in general is better, so thank you for implementing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Highlight Python doctests within docstrings
2 participants