From dec671abd953dd2a4baa5839763d0be381685342 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 22 May 2018 23:42:56 +0900 Subject: [PATCH] Fix #4927: Display a warning when invalid values are passed to linenothreshold option of highlight directive --- CHANGES | 2 ++ sphinx/directives/code.py | 10 ++-------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 5f777ae7d..c9e1413b3 100644 --- a/CHANGES +++ b/CHANGES @@ -113,6 +113,8 @@ Features added * #4866: Wrap graphviz diagrams in ``
`` tag * Add :event:`viewcode-find-source` event to viewcode extension. * #4785: napoleon: Add strings to translation file for localisation +* #4927: Display a warning when invalid values are passed to linenothreshold + option of highlight directive Bugs fixed ---------- diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py index 713e5ad0c..20ad5a20c 100644 --- a/sphinx/directives/code.py +++ b/sphinx/directives/code.py @@ -45,18 +45,12 @@ class Highlight(SphinxDirective): optional_arguments = 0 final_argument_whitespace = False option_spec = { - 'linenothreshold': directives.unchanged, + 'linenothreshold': directives.positive_int, } def run(self): # type: () -> List[nodes.Node] - if 'linenothreshold' in self.options: - try: - linenothreshold = int(self.options['linenothreshold']) - except Exception: - linenothreshold = 10 - else: - linenothreshold = sys.maxsize + linenothreshold = self.options.get('linenothreshold', sys.maxsize) return [addnodes.highlightlang(lang=self.arguments[0].strip(), linenothreshold=linenothreshold)]