mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Make code role highlighting consistent with code-block directive
Fixes https://github.com/sphinx-doc/sphinx/issues/5157
This is factored out of the sphinx-immaterial theme:
1ef121a612/sphinx_immaterial/inlinesyntaxhighlight.py (L1)
See also:
https://github.com/sphinx-doc/sphinx/pull/6916
This commit is contained in:
0
tests/roots/test-reST-code-role/conf.py
Normal file
0
tests/roots/test-reST-code-role/conf.py
Normal file
9
tests/roots/test-reST-code-role/index.rst
Normal file
9
tests/roots/test-reST-code-role/index.rst
Normal file
@@ -0,0 +1,9 @@
|
||||
.. role:: python(code)
|
||||
:language: python
|
||||
:class: highlight
|
||||
|
||||
Inline :python:`def foo(1 + 2 + None + "abc"): pass` code block
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
def foo(1 + 2 + None + "abc"): pass
|
||||
@@ -1718,3 +1718,27 @@ def test_html_signaturereturn_icon(app):
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
|
||||
assert ('<span class="sig-return-icon">→</span>' in content)
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='reST-code-role')
|
||||
def test_html_code_role(app):
|
||||
app.build()
|
||||
content = (app.outdir / 'index.html').read_text()
|
||||
|
||||
common_content = (
|
||||
'<span class="k">def</span> <span class="nf">foo</span>'
|
||||
'<span class="p">(</span>'
|
||||
'<span class="mi">1</span> '
|
||||
'<span class="o">+</span> '
|
||||
'<span class="mi">2</span> '
|
||||
'<span class="o">+</span> '
|
||||
'<span class="kc">None</span> '
|
||||
'<span class="o">+</span> '
|
||||
'<span class="s2">"abc"</span>'
|
||||
'<span class="p">):</span> '
|
||||
'<span class="k">pass</span>')
|
||||
assert ('<p>Inline <code class="code highlight python docutils literal highlight-python">' +
|
||||
common_content + '</code> code block</p>') in content
|
||||
assert ('<div class="highlight-python notranslate">' +
|
||||
'<div class="highlight"><pre><span></span>' +
|
||||
common_content) in content
|
||||
|
||||
@@ -1628,3 +1628,30 @@ def test_latex_container(app, status, warning):
|
||||
result = (app.outdir / 'python.tex').read_text()
|
||||
assert r'\begin{sphinxuseclass}{classname}' in result
|
||||
assert r'\end{sphinxuseclass}' in result
|
||||
|
||||
|
||||
@pytest.mark.sphinx('latex', testroot='reST-code-role')
|
||||
def test_latex_code_role(app):
|
||||
app.build()
|
||||
content = (app.outdir / 'python.tex').read_text()
|
||||
|
||||
common_content = (
|
||||
r'\PYG{k}{def} '
|
||||
r'\PYG{n+nf}{foo}'
|
||||
r'\PYG{p}{(}'
|
||||
r'\PYG{l+m+mi}{1} '
|
||||
r'\PYG{o}{+} '
|
||||
r'\PYG{l+m+mi}{2} '
|
||||
r'\PYG{o}{+} '
|
||||
r'\PYG{k+kc}{None} '
|
||||
r'\PYG{o}{+} '
|
||||
r'\PYG{l+s+s2}{\PYGZdq{}}'
|
||||
r'\PYG{l+s+s2}{abc}'
|
||||
r'\PYG{l+s+s2}{\PYGZdq{}}'
|
||||
r'\PYG{p}{)}'
|
||||
r'\PYG{p}{:} '
|
||||
r'\PYG{k}{pass}')
|
||||
assert (r'Inline \sphinxcode{\sphinxupquote{' + '\n' +
|
||||
common_content + '\n}} code block') in content
|
||||
assert (r'\begin{sphinxVerbatim}[commandchars=\\\{\}]' +
|
||||
'\n' + common_content + '\n' + r'\end{sphinxVerbatim}') in content
|
||||
|
||||
Reference in New Issue
Block a user