2024-11-22 15:54:26 -06:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2025-01-06 00:56:10 -06:00
|
|
|
import pygments
|
2024-01-17 18:08:30 -06:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
2024-08-11 08:58:56 -05:00
|
|
|
@pytest.mark.sphinx(
|
|
|
|
'html',
|
|
|
|
testroot='reST-code-block',
|
|
|
|
confoverrides={'html_codeblock_linenos_style': 'table'},
|
|
|
|
)
|
2024-01-17 18:08:30 -06:00
|
|
|
def test_html_codeblock_linenos_style_table(app):
|
|
|
|
app.build()
|
|
|
|
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
|
|
|
|
2024-08-11 08:58:56 -05:00
|
|
|
assert (
|
|
|
|
'<div class="linenodiv"><pre><span class="normal">1</span>\n'
|
|
|
|
'<span class="normal">2</span>\n'
|
|
|
|
'<span class="normal">3</span>\n'
|
|
|
|
'<span class="normal">4</span></pre></div>'
|
|
|
|
) in content
|
2024-01-17 18:08:30 -06:00
|
|
|
|
|
|
|
|
2024-08-11 08:58:56 -05:00
|
|
|
@pytest.mark.sphinx(
|
|
|
|
'html',
|
|
|
|
testroot='reST-code-block',
|
|
|
|
confoverrides={'html_codeblock_linenos_style': 'inline'},
|
|
|
|
)
|
2024-01-17 18:08:30 -06:00
|
|
|
def test_html_codeblock_linenos_style_inline(app):
|
|
|
|
app.build()
|
|
|
|
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
|
|
|
|
|
|
|
assert '<span class="linenos">1</span>' in content
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='reST-code-role')
|
|
|
|
def test_html_code_role(app):
|
2025-01-06 00:56:10 -06:00
|
|
|
if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 19):
|
|
|
|
sp = '<span class="w"> </span>'
|
|
|
|
else:
|
|
|
|
sp = ' '
|
|
|
|
|
2024-01-17 18:08:30 -06:00
|
|
|
app.build()
|
|
|
|
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
|
|
|
|
|
|
|
common_content = (
|
2025-01-06 00:56:10 -06:00
|
|
|
f'<span class="k">def</span>{sp}<span class="nf">foo</span>'
|
2024-01-17 18:08:30 -06:00
|
|
|
'<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> '
|
2024-08-11 08:58:56 -05:00
|
|
|
'<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
|