-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Inline code is not syntax highlighted #5157
Comments
Does |
Unfortunately it doesn't. That correctly applies the short class names in HTML and syntax highlighting works if youalso add the It does not work for LaTeX output. .. role:: js(code)
:language: js
:js:`window.addEventListener(function() { return false; });`
.. code-block:: js
window.addEventListener(function() { return false; }); is converted to: \sphinxcode{\sphinxupquote{\DUrole{nb}{window}\DUrole{p}{.}\DUrole{nx}{addEventListener}\DUrole{p}{(}\DUrole{kd}{function}\DUrole{p}{()} \DUrole{p}{\{} \DUrole{k}{return} \DUrole{kc}{false}\DUrole{p}{;} \DUrole{p}{\});}}}
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{n+nb}{window}\PYG{p}{.}\PYG{n+nx}{addEventListener}\PYG{p}{(}\PYG{k+kd}{function}\PYG{p}{(}\PYG{p}{)} \PYG{p}{\PYGZob{}} \PYG{k}{return} \PYG{k+kc}{false}\PYG{p}{;} \PYG{p}{\PYGZcb{}}\PYG{p}{)}\PYG{p}{;}
\end{sphinxVerbatim} Only the code block (not the inline code) has highlighting |
Yes, current version of Sphinx does not support inline highlighting on LaTeX output. So we need to improve LaTeX writer (or pygments bridge?) to support it. cc: @jfbu |
I've created a PR with a possible implementation. Please review or rewrite as necessary. |
Could adding This would still need the "highlight" class to work with the current CSS styles.
If this is too cumbersome, a change in the CSS selectors or a patch that adds "highlight" to Code nodes ("literal" nodes with "code" class in the Docutils document tree) may help. For inline syntax highlight in LaTeX, definitions for "\DUrolenx", "\DUrolekd", ... are required. |
Fixes sphinx-doc#5157 This is factored out of the sphinx-immaterial theme: https://github.com/jbms/sphinx-immaterial/blob/1ef121a612d4f5afc2a9ca9c4e3f20fca89065e8/sphinx_immaterial/inlinesyntaxhighlight.py#L1 See also: sphinx-doc#6916
Fixes sphinx-doc#5157 This is factored out of the sphinx-immaterial theme: https://github.com/jbms/sphinx-immaterial/blob/1ef121a612d4f5afc2a9ca9c4e3f20fca89065e8/sphinx_immaterial/inlinesyntaxhighlight.py#L1 See also: sphinx-doc#6916
Fixes sphinx-doc#5157 This is factored out of the sphinx-immaterial theme: https://github.com/jbms/sphinx-immaterial/blob/1ef121a612d4f5afc2a9ca9c4e3f20fca89065e8/sphinx_immaterial/inlinesyntaxhighlight.py#L1 See also: sphinx-doc#6916
Fixes sphinx-doc#5157 This is factored out of the sphinx-immaterial theme: https://github.com/jbms/sphinx-immaterial/blob/1ef121a612d4f5afc2a9ca9c4e3f20fca89065e8/sphinx_immaterial/inlinesyntaxhighlight.py#L1 See also: sphinx-doc#6916
Fixes sphinx-doc#5157 This is factored out of the sphinx-immaterial theme: https://github.com/jbms/sphinx-immaterial/blob/1ef121a612d4f5afc2a9ca9c4e3f20fca89065e8/sphinx_immaterial/inlinesyntaxhighlight.py#L1 See also: sphinx-doc#6916
Fixed by #10251. It will be released as v5.0. |
Problem
It is not possible to apply syntax highlighting to inline literals or code.
The docutils documentation provides a way to do this using the
role
directive to define a new role, based on thecode
role, but the resulting HTML contains classes like.keyword
instead of classes like.highlight .k
which are used in Pygments CSS.Expected results
Sphinx to provide a
code
role that applies proper classes for Pygments to style.There is an extension to add this, but it is from 2013 (so maybe out of date with recent Sphinx), and it does not contain code to generate highlighting in LaTeX.
Reproducible project / your project
Environment info
The text was updated successfully, but these errors were encountered: