Skip to content

Commit

Permalink
Fix #3426 — allow disabling line numbers in code blocks (#3431)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwpolska authored Jul 5, 2020
1 parent 9150ee7 commit 4fb667f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Features
Bugfixes
--------

* Default to no line numbers in code blocks, honor CodeHilite
requesting no line numbers. Listing pages still use line numbers
(Issue #3426)
* Remove duplicate MathJax config in bootstrap themes (Issue #3427)
* Fix ``doit`` requirement to ``doit>=0.32.0`` (Issue #3422)

Expand Down
4 changes: 3 additions & 1 deletion nikola/plugins/task/listings.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ def render_listing(in_name, out_name, input_folder, output_folder, folders=[], f
except Exception:
lexer = TextLexer()
fd.seek(0)
code = highlight(fd.read(), lexer, utils.NikolaPygmentsHTML(in_name))
code = highlight(
fd.read(), lexer,
utils.NikolaPygmentsHTML(in_name, linenos='table'))
title = os.path.basename(in_name)
else:
code = ''
Expand Down
4 changes: 4 additions & 0 deletions nikola/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,11 @@ def __init__(self, anchor_ref=None, classes=None, **kwargs):
anchor_ref, lang=LocaleBorg().current_lang, force=True)
self.nclasses = classes
kwargs['cssclass'] = 'code'
if not kwargs.get('linenos'):
# Default to no line numbers (Issue #3426)
kwargs['linenos'] = False
if kwargs.get('linenos') not in {'table', 'inline', 'ol', False}:
# Map invalid values to table
kwargs['linenos'] = 'table'
kwargs['anchorlinenos'] = kwargs['linenos'] == 'table'
kwargs['nowrap'] = False
Expand Down

0 comments on commit 4fb667f

Please sign in to comment.