Skip to content

Commit

Permalink
Close #7849: html: Add html_codeblock_linenos
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Jun 27, 2020
1 parent 03e85df commit c6ce41d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Deprecated
Features added
--------------

* #7849: html: Add :confval:`html_codeblock_linenos` to change the style of
line numbers for code-blocks
* #7853: C and C++, support parameterized GNU style attributes.

Bugs fixed
Expand Down
3 changes: 2 additions & 1 deletion sphinx/builders/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from sphinx import package_dir, __display_version__
from sphinx.application import Sphinx
from sphinx.builders import Builder
from sphinx.config import Config
from sphinx.config import Config, ENUM
from sphinx.deprecation import RemovedInSphinx40Warning
from sphinx.domains import Domain, Index, IndexEntry
from sphinx.environment.adapters.asset import ImageAdapter
Expand Down Expand Up @@ -1226,6 +1226,7 @@ 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', 'table', 'html', ENUM('table', 'inline'))
app.add_config_value('html_math_renderer', None, 'env')
app.add_config_value('html4_writer', False, 'html')

Expand Down
3 changes: 3 additions & 0 deletions sphinx/writers/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ def visit_literal_block(self, node: Element) -> None:
else:
opts = {}

if linenos and self.builder.config.html_codeblock_linenos:
linenos = self.builder.config.html_codeblock_linenos

highlighted = self.highlighter.highlight_block(
node.rawsource, lang, opts=opts, linenos=linenos,
location=(self.builder.current_docname, node.line), **highlight_args
Expand Down
3 changes: 3 additions & 0 deletions sphinx/writers/html5.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ def visit_literal_block(self, node: Element) -> None:
else:
opts = {}

if linenos and self.builder.config.html_codeblock_linenos:
linenos = self.builder.config.html_codeblock_linenos

highlighted = self.highlighter.highlight_block(
node.rawsource, lang, opts=opts, linenos=linenos,
location=(self.builder.current_docname, node.line), **highlight_args
Expand Down

0 comments on commit c6ce41d

Please sign in to comment.