-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Highlighting appears to be lost for code-blocks from markdown sources with Sphinx v8.2.0+/e65bbb96a and myst_parser #13207
Comments
Sorry I forgot to attach zip file here it is |
I am adding a simpler mwe not using |
I looked at the MRE but I didn't build it because I'm not a myst user. Having read the # test highlighting for code-block in markdown source
This is a `markdown` file.
Is this code-block highlighted?
```
def foo(x):
return x * x
``` usually wouldn't this have to be written as(?): ```python
def foo(x):
return x * x
``` Just pointing this out as its worth mentioning. |
@electric-coder for info, with |
(...)
Standard MD source fences aren't part of the usual reST options for Showing code examples. I'm making a further educated guess that PR 13151 caused something to break on the myst side, likely the mechanism that reads and applies the more general Sphinx
Given how massive PR #13151 and the underlying issue #13072 are, it might be better to cross-post this at the myst repo as they'll want a heads up and in all likelihood it'll be easier for them to apply a fix/update on their side.
I know that feeling :| |
The simplest reproducer is thus: from sphinx.environment import _CurrentDocument
temp_data = {}
current_document = _CurrentDocument()
assert temp_data.get('highlight_language', ...) is ...
assert current_document.get('highlight_language', ...) == '' # not ...! #13151 changed a few instances of -node['language'] = self.env.temp_data.get(
- 'highlight_language', self.config.highlight_language
-)
+node['language'] = (
+ self.env.current_document.highlight_language
+ or self.config.highlight_language
+) A |
Myst could apply the following change: - name = self.sphinx_env.temp_data.get(
- "highlight_language", self.sphinx_env.config.highlight_language
- )
+ name = (
+ self.sphinx_env.temp_data.get("highlight_language")
+ or self.sphinx_env.config.highlight_language
+ ) I'm struggling initially to think of a nice way to change Let me know any thoughts/ideas. A |
How about reverting the _CurrentDocument PR for now until we find a good alternative?
It will probably defeat the purpose of the new class. However, what you can do is to have an At least, you won't need to maintain a separate set of attributes. |
I'd prefer not to take drastic action... Note that I haven't yet found an instance of 'breakage' (failure to build), for example the problem here with myst is a quality-of-life one rather than critical. But it is less than ideal. A |
Heya guys, FYI myst only uses it once, so I'm ok to put in backport logic there for this |
Closing as MyST will fix. A |
Describe the bug
After updating Sphinx on Jan 4, 2025, it seems highlighting for code-blocks originating in markdown sources is not applied (
myst_parser
is used). I first observed this in a more complicated way in a big project with extra hacks to customize rendering, but could reduce it to a fairly minimal one using onlymyst_parser
andhighlight_language
(the latter because due to original code-blocks uselatex
but the problem is not related to the latex builder).How to Reproduce
Unzip the small attached project (see #13207 (comment)) and execute
make html O="-E"
with current release Sphinx 8.1.0 or a checkout of current dev at at least Sphinx v8.2.0+/e65bbb96a. In the latter case, highlighting is lost for the code in markdown file. With parent commit Sphinx v8.2.0+/c7eaf175e, the highlighting is there.Environment Information
UPDATE: the problem also shows with
myst-parser 4.0.0
.Sphinx extensions
Additional context
Relates #13151
The text was updated successfully, but these errors were encountered: