From d8665942d07de5807edd89e8bfbeb4c1b93b159e Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 14 Sep 2020 11:30:10 +0100 Subject: [PATCH] simplify highlight method --- rich/syntax.py | 10 ++++------ rich/text.py | 1 - 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/rich/syntax.py b/rich/syntax.py index fe0a03f5..d060ab30 100644 --- a/rich/syntax.py +++ b/rich/syntax.py @@ -173,18 +173,16 @@ class Syntax(JupyterMixin): style = style + Style(bgcolor=self._pygments_style_class.background_color) return style - def highlight(self, code: str = None) -> Text: + def highlight(self, code: str) -> Text: """Highlight code and return a Text instance. Args: - code (Optional[str], optional). Highlight code if a str is given, or - None to use self.code. + code (str). Code to highlight. Returns: Text: A text instance containing syntax highlight. """ - if code is None: - code = self.code + default_style = self._get_default_style() try: lexer = get_lexer_by_name(self.lexer_name) @@ -255,7 +253,7 @@ class Syntax(JupyterMixin): code = self.code if self.dedent: code = textwrap.dedent(code) - text = self.highlight() + text = self.highlight(self.code) if text.plain.endswith("\n"): text.plain = text.plain[:-1] if not self.line_numbers: diff --git a/rich/text.py b/rich/text.py index b64908dc..bd3c7ce5 100644 --- a/rich/text.py +++ b/rich/text.py @@ -875,7 +875,6 @@ class Text(JupyterMixin): (offset, offset + len(line)) for offset, line in zip(divide_offsets, new_lines) ] - for span in self._spans: line_index = (span.start // average_line_length) % len(line_ranges)