Uh oh!
There was an error while loading. Please reload this page.
Properly highlight docstrings - #83
Conversation
ZDBioHazard
commented
May 22, 2022
This seems to work for me, but I needed to add My colorscheme has an aggressive |
wmvanvliet
commented
Jan 20, 2023
Thanks @ZDBioHazard! I've been looking for that fix. |
rnjudge
commented
Jul 22, 2025
Is this PR still under review? Rending docstrings as regular strings in the code as the same color is an eyesore for me.. would love to see this merged! |
wmvanvliet
commented
Jul 23, 2025
last commit to this repo was 5 years ago. I guess this is dead. You could do what I did and fork this repo and merge in all the PRs you like. |
Another attempt at #45 and #57, namely to properly highlight docstrings as comments.
For now, this implementation is very ugly, but it actually works. It only highlights things that should be docstrings without touching other types of multiline strings. This is accomplished by checking for
:characters and combining that withnextgroup=pythonDocStringto interpret the first directly following multiline string as a docstring. Another case is added for the first multiline string appearing at the top of the file.See https://gist.github.com/wmvanvliet/36471bb456151d93b86c402b64684b0a for a bunch of challenging test cases.
The implementation is messy right now to work around a specific problem. Any pointers on how to solve this more elegantly are greatly appreciated. The problem is that
nextgroup=pythonDocString skipemptywill skip newlines, but not spaces in its search for the docstring, and so it will only find it when the docstring starts on the first column of a line. For now, the workaround is to match+^\s*"""+as a docstring, i.e. also match the leading whitespace, but this causes the docstring rule to have precedence over the normal+"""+multiline pattern. Ideally, the multiline rule should take precedence and have this precedence temporarily overwritten by the presence of a:mark.