mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Revert `html_codeblock_linenos_style
` removal (#10922)
This commit is contained in:
parent
e70a0fac6d
commit
592b46c431
@ -1065,6 +1065,20 @@ that use Sphinx's HTMLWriter class.
|
||||
|
||||
.. versionadded:: 1.8
|
||||
|
||||
.. confval:: html_codeblock_linenos_style
|
||||
|
||||
The style of line numbers for code-blocks.
|
||||
|
||||
* ``'table'`` -- display line numbers using ``<table>`` tag
|
||||
* ``'inline'`` -- display line numbers using ``<span>`` tag (default)
|
||||
|
||||
.. versionadded:: 3.2
|
||||
.. versionchanged:: 4.0
|
||||
|
||||
It defaults to ``'inline'``.
|
||||
|
||||
.. deprecated:: 4.0
|
||||
|
||||
.. confval:: html_context
|
||||
|
||||
A dictionary of values to pass into the template engine's context for all
|
||||
|
@ -23,7 +23,7 @@ from sphinx import __display_version__, package_dir
|
||||
from sphinx import version_info as sphinx_version
|
||||
from sphinx.application import Sphinx
|
||||
from sphinx.builders import Builder
|
||||
from sphinx.config import Config
|
||||
from sphinx.config import ENUM, Config
|
||||
from sphinx.deprecation import RemovedInSphinx70Warning, deprecated_alias
|
||||
from sphinx.domains import Domain, Index, IndexEntry
|
||||
from sphinx.environment import BuildEnvironment
|
||||
@ -1371,6 +1371,8 @@ def setup(app: Sphinx) -> Dict[str, Any]:
|
||||
app.add_config_value('html_search_scorer', '', None)
|
||||
app.add_config_value('html_scaled_image_link', True, 'html')
|
||||
app.add_config_value('html_baseurl', '', 'html')
|
||||
app.add_config_value('html_codeblock_linenos_style', 'inline', 'html', # RemovedInSphinx70Warning # NOQA
|
||||
ENUM('table', 'inline'))
|
||||
app.add_config_value('html_math_renderer', None, 'env')
|
||||
app.add_config_value('html4_writer', False, 'html')
|
||||
|
||||
|
@ -446,11 +446,14 @@ class HTMLTranslator(SphinxTranslator, BaseTranslator):
|
||||
return super().visit_literal_block(node)
|
||||
|
||||
lang = node.get('language', 'default')
|
||||
linenos = node.get('linenos', False) and "inline"
|
||||
linenos = node.get('linenos', False)
|
||||
highlight_args = node.get('highlight_args', {})
|
||||
highlight_args['force'] = node.get('force', False)
|
||||
opts = self.config.highlight_options.get(lang, {})
|
||||
|
||||
if linenos and self.config.html_codeblock_linenos_style:
|
||||
linenos = self.config.html_codeblock_linenos_style
|
||||
|
||||
highlighted = self.highlighter.highlight_block(
|
||||
node.rawsource, lang, opts=opts, linenos=linenos,
|
||||
location=node, **highlight_args
|
||||
|
@ -404,11 +404,14 @@ class HTML5Translator(SphinxTranslator, BaseTranslator):
|
||||
return super().visit_literal_block(node)
|
||||
|
||||
lang = node.get('language', 'default')
|
||||
linenos = node.get('linenos', False) and "inline"
|
||||
linenos = node.get('linenos', False)
|
||||
highlight_args = node.get('highlight_args', {})
|
||||
highlight_args['force'] = node.get('force', False)
|
||||
opts = self.config.highlight_options.get(lang, {})
|
||||
|
||||
if linenos and self.config.html_codeblock_linenos_style:
|
||||
linenos = self.config.html_codeblock_linenos_style
|
||||
|
||||
highlighted = self.highlighter.highlight_block(
|
||||
node.rawsource, lang, opts=opts, linenos=linenos,
|
||||
location=node, **highlight_args
|
||||
|
@ -1598,8 +1598,21 @@ def test_html_scaled_image_link(app):
|
||||
context)
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='reST-code-block')
|
||||
def test_html_codeblock_linenos_style(app):
|
||||
@pytest.mark.sphinx('html', testroot='reST-code-block',
|
||||
confoverrides={'html_codeblock_linenos_style': 'table'})
|
||||
def test_html_codeblock_linenos_style_table(app):
|
||||
app.build()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
|
||||
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
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='reST-code-block',
|
||||
confoverrides={'html_codeblock_linenos_style': 'inline'})
|
||||
def test_html_codeblock_linenos_style_inline(app):
|
||||
app.build()
|
||||
content = (app.outdir / 'index.html').read_text(encoding='utf8')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user