Navigation Menu

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

Smart quotes get applied to highlighted inline code expressions #9564

Closed
JustinTArthur opened this issue Aug 20, 2021 · 1 comment · Fixed by #9565
Closed

Smart quotes get applied to highlighted inline code expressions #9564

JustinTArthur opened this issue Aug 20, 2021 · 1 comment · Fixed by #9565
Labels

Comments

@JustinTArthur
Copy link
Contributor

Describe the bug

Given some RST that includes text with a :code: role and a language option, sphinx will produce HTML with highlighting for that text's code language. However, if that highlighting introduces more than one sub-level of output nodes, we fail to detect that the text is part of a no-smartquotes zone and mangle text that is intended to be presented literally.

How to Reproduce

The following RST:

.. role:: python(code)
   :language: python

By setting :python:`foo = 'bar'`, we have assigned a variable.

produces HTML like

By setting
<code class="code python docutils literal notranslate">
  <span class="name"><span class="pre">foo</span></span>
  <span class="operator"><span class="pre">=</span></span>
  <span class="literal string single"><span class="pre">‘bar’</span></span>
</code>, we have assigned a variable.

Notice the right/left single quotes added by Sphinx in ‘bar’. Because the text node is two ancestors away from the document's code node instead of one, it isn't detected as protected from smartquotes.

Expected behavior

Straight single and double-quote characters in inline code expressions should be left alone, regardless of whether or not a specific language option is applied.

docutils' built-in smartquotes transformer correctly avoids the highlighted quotation marks.

Your project

Small Sphinx 4 project sample attached.

Screenshots

No response

OS

macOS

Python version

3.9

Sphinx version

4.1.2

Sphinx extensions

No response

Extra tools

No response

Additional context

No response

@JustinTArthur
Copy link
Contributor Author

smartquotes_code_role_example.zip as requested by the GitHub ticket template.

@JustinTArthur JustinTArthur changed the title Smart quotes gets applied to inline highlighted code expressions Smart quotes gets applied to highlighted inline code expressions Aug 20, 2021
@JustinTArthur JustinTArthur changed the title Smart quotes gets applied to highlighted inline code expressions Smart quotes get applied to highlighted inline code expressions Aug 20, 2021
JustinTArthur added a commit to JustinTArthur/sphinx that referenced this issue Aug 20, 2021
JustinTArthur added a commit to JustinTArthur/sphinx that referenced this issue Aug 20, 2021
JustinTArthur added a commit to JustinTArthur/sphinx that referenced this issue Aug 20, 2021
JustinTArthur added a commit to JustinTArthur/sphinx that referenced this issue Aug 20, 2021
JustinTArthur added a commit to JustinTArthur/sphinx that referenced this issue Aug 21, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant