-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
I know this is somewhat of a minor edge case, but as of 1.1, there is no way to embed literal "{" characters in the :samp: text role.
I gave a shot at fixing this myself, and came up with the attached patch, which rewrites sphinx.roles.emph_literal_role() so it behaves as follows:
- '{' and '}' still start and end emphasized variable sections
- only now the backslash acts as an escape character... a backslash followed by a '{', '}', or another backslash, inserts a literal character.
- empty '{}' groups, unterminated '{' sections, and blackslashes followed by any any other character will all now result in an error.
This allows embedding special characters anywhere in :samp:, and shouldn't affect any existing documents, as long as they don't currently embed any literal backslashes or have malformed samp strings such as :samp:
a{b
.
Also, just to note: since docutils already processes backslash escapes, this requires :samp: text in rst files to use a double-escape to enable this feature... For example, :samp:
a{b{x}}c
in a document would result in the nodesText("a"), emphasis("b{x}"), Text("c")
.
Despite the double-escape requirement, I couldn't think of anything else that seemed appropriate as an escape character. I did also try "{{"-style escapes, ala Python's str.format()
command, but this quickly proved to have way to ambiguous a grammar for the purposes of :samp:
.
I hope this patch is acceptable, if not, please let me know if there's anything I can do to fix it.
- Bitbucket: https://bitbucket.org/birkenfeld/sphinx/issue/789
- Originally reported by: Eli Collins
- Originally created at: 2011-10-11T22:42:37.547