vim-restructuredtext
vim-restructuredtext copied to clipboard
Spurious bold and italic due to * and **kwargs in function signature
When an asterisk (*) appears in a function signature, the highlighter goes haywire:
examples:
.. py:class:: FooClass(foo, bar, *, baz)
...
.. py:method:: FooMethod(a, b, **kwargs)
...
Escaping these results in the backslashes appearing in the final output, so that's not an option. It really is intended to work like this.
Anywhere function signatures can appear, the syntax highlighter ought to ignore formatting. Note that lines can also continue with backslashes.
I can reproduce this. The error is in rstExDirective
blocks.
I believe that we can fix this by including the entire line in the start
prefix, rather than just the .. py:class::
. Replacing
start=+' . s:ReferenceName . '::_s+'
with
start=+' . s:ReferenceName . '::.*\_s+'
(i.e. inserting .*
after ::
) crudely works, although this is probably too aggressive. But something like that appears to work.
I'm not yet sure if we want to include the entire directive in the block's start
, but it does resolve the problem and is better than the current situation. I will continue to look into this to make sure it doesn't break anything else.
While I think this is probably the right fix, this change also exacerbates many issues with nested directives, many of which are outlined in other various issues.
Another way to put it is that this error happens to obscure some more serious errors.
I made a few basic attempts to resolve those other issues, but unfortunately I'm still unsure how to fix this one. What needs to happen is the method in rstLiteralBlock
needs to be duplicated in the directives, but it's not as simple as just implementing these in rstExDirective
, due to the deeper and overlapping definitions of various directives.
I'll have a crack at it this weekend and see how it goes.
(Finally looking at this 10 months later...)
Removing @rstCruft
from rstExDirectives
seems to also resolve this issue, and is probably closer to the correct solution.
Defining a new "cruft" which excludes rstEmphasis
and rstStrongEmphasis
might be what we want here.
Are there any directive headers which would use syntax highlighting? I can't think of any, but Niko must have added it for a reason?
The above suggestion would not work. Everything after ::
is currently considered rstExDirective
, including the body text, and there are many directives whose contents would use markup like rstEmphasis
.
As a one-line example, this would need to support highlighting:
.. note:: This *does* have **highlighting**
Part of the issue may be that py:class
is not a recognized reST directive, although it is almost certainly recognized by Sphinx.
I think that the only solution here is to carve out an exception for things like py:class
. But some discussion on the proper syntax is needed. The py:*
cases are simpler since they are defined by Sphinx, but user-defined directives are also possible. Perhaps those are unsolvable.
Hi, I'm facing the same issue when asterisks occur within code-blocks. Is there any fix for this?
Not at the moment; unfortunantely I have a lot going on, and this project is rather far down the list.