-
Notifications
You must be signed in to change notification settings - Fork 197
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
Fix smartquote logic #479
Comments
thanks @chrisjsewell -- If I understand correctly I see your issue re: |
According to docutils, smartquotes also contains:
This is also referenced in the Sphinx documentation for smartquotes. The myst-parser documentation includes I am using Sphinx+MyST and did not want replacements or smartquotes. I created a simple project to find a solution. The conf.py contains:
myst-parser FAQ - Disable Markdown syntax for the parser But My work around is to double escape It would be helpful if sphinx 7.3.7 |
I'm surprised no one has noticed this before, but I've just realised there are some "conflicts" in how smartquotes are handled; between myst (via markdown-it), docutils and sphinx.
Within myst-parser, enabling the "smartquotes" extension (e.g. via
myst_enable_extensions = ["smartquotes"]
, enables the markdown-it smartquotes rule:MyST-Parser/myst_parser/main.py
Lines 252 to 254 in 2b3a931
You can see its tested behaviour here: https://raw.githubusercontent.com/executablebooks/markdown-it-py/master/tests/test_port/fixtures/smartquotes.md,
i.e. this is applied before converting to docutils AST
With docutils, the MyST parser is inheriting the docutils RST parser:
MyST-Parser/myst_parser/docutils_.py
Line 166 in 2b3a931
Because of this, it also currently inherits its transforms, for which RST adds the
SmartQuote
transform: https://github.com/chrisjsewell/docutils/blob/8adab0660b2097b4f3c32cef7e5ff4cb3c72b084/docutils/docutils/parsers/rst/__init__.py#L177-L179This does approximately the same thing, and is turned off by default, so for example:
we could perhaps remove this transform, i.e.:
For sphinx though, removing the
SmartQuote
transform would not matter, because it already does this: https://github.com/sphinx-doc/sphinx/blob/eed0730b4ba3bd2fbd34f2d6ab555ba876c77717/sphinx/parsers.py#L72-L80,in order to replace it with
SphinxSmartQuotes
: https://github.com/sphinx-doc/sphinx/blob/eed0730b4ba3bd2fbd34f2d6ab555ba876c77717/sphinx/transforms/__init__.py#L323By contrast with docutils, sphinx smartquotes are on by default 😬 : https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-smartquotes,
so even if you don't enable the myst-parser smartquotes extension, quotes will still be converted, unless you set
smartquotes = False
There are ways of disabling, for instance by setting
document.settings.smart_quotes = False
in the parser.Not decided on what the best behaviour here should be yet, I imagine though there should be only one "source of truth" for enabling/disabling smart quotes:
myst_enable_extensions = ["smartquotes"]
dynamically change the docutils/sphinx config in the parserPerhaps the
SmartQuote
transform is more "optimised" for docutils/sphinx use, but the pro of the markdown-it rule, is that it is not tightly coupled to docutils, so you can use it in other "myst implementations", e.g.: https://github.com/executablebooks/myst-vs-code/blob/c8c96542171ebe6ccdd896cf8337a5ffffeb73d4/src/extension.ts#L1also related #424
cc @choldgraf, @mmcky, etc and anyone else's thoughts welcome
The text was updated successfully, but these errors were encountered: