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

Spurious bold and italic due to * and **kwargs in function signature #57

Open
Elizafox opened this issue Feb 8, 2021 · 6 comments
Open

Comments

@Elizafox
Copy link

Elizafox commented Feb 8, 2021

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.

@marshallward
Copy link
Owner

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.

@marshallward
Copy link
Owner

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.

@marshallward
Copy link
Owner

(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?

@marshallward
Copy link
Owner

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.

@codeandfire
Copy link

Hi, I'm facing the same issue when asterisks occur within code-blocks. Is there any fix for this?

@marshallward
Copy link
Owner

Not at the moment; unfortunantely I have a lot going on, and this project is rather far down the list.

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

No branches or pull requests

3 participants