sphinx
sphinx copied to clipboard
escaping curly braces in samp text role broken
Describe the bug
Escaping of curly braces in the samp text role was introduced in #4909, but it does not seem to be able to handle both escaped and non-escaped curly braces in the same sample.
How to Reproduce
- :samp:`\{ literal, {variable} \}`
- :samp:`\{ literal \}, {variable}`
- :samp:`{variable}, \{ literal \}`
- :samp:`{ variable, \{variable\} }`
Expected behavior
Ignoring any extra space in the rendering below, I expect the above to be rendered as ...
{ literal,variable}{ literal },variablevariable, { literal }variable, {variable}
But instead, it renders as ...
literal, {variable}literal , variablevariable, literalvariable, {variable}
Your project
any
Screenshots
No response
OS
Mac
Python version
3.7.9
Sphinx version
5.0.2
Sphinx extensions
No response
Extra tools
No response
Additional context
No response
I just ran into the same issue with python version 3.11.4 and sphinx version 7.2.6.
The issue is caused, by the fact, that we have a quotation `` around it, hence the backslash needs its own masking on the text level (Here the curly braces don't need to be escaped). Hence, while the issues isn't fixed, I'd like to provide a workaround how @rdzman's example behaves as expected, simply use two backslash each time to preserve one backslash for the moment it is needed to escape the curly brace:
- :samp:`\\{ literal, {variable} \\}`
- :samp:`\\{ literal \\}, {variable}`
- :samp:`{variable}, \\{ literal \\}`
- :samp:`{ variable, \\{variable\\} }`
Encountered the same issue. Opened a PR to update the docs #11987