From 37f9e9fda9b0225202e405f583448c6ac640f23c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 16 Sep 2024 13:55:48 +0200 Subject: [PATCH] m.code: fix AnsiLexer to actually do the right thing with pygments 2.12+. That extra removed argument did make it "work", but due to the internals being different, all ANSI output was additionally wrapped in
. Now it's not anymore. --- documentation/doxygen.py | 2 +- plugins/ansilexer.py | 8 ++------ plugins/m/code.py | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/documentation/doxygen.py b/documentation/doxygen.py index 93accf17..17faec3c 100755 --- a/documentation/doxygen.py +++ b/documentation/doxygen.py @@ -1366,7 +1366,7 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET. class_ = 'm-code' if isinstance(lexer, ansilexer.AnsiLexer): - formatter = ansilexer.HtmlAnsiFormatter() + formatter = ansilexer.HtmlAnsiFormatter(nowrap=True) else: formatter = HtmlFormatter(nowrap=True) diff --git a/plugins/ansilexer.py b/plugins/ansilexer.py index 4df25dce..3268c695 100644 --- a/plugins/ansilexer.py +++ b/plugins/ansilexer.py @@ -290,12 +290,8 @@ class HtmlAnsiFormatter(HtmlFormatter): '(?P")' ) - # Pygments 2.12+ doesn't have the outfile parameter anymore - def wrap(self, source, outfile=None): - return self._wrap_code(source) - - def _wrap_code(self, source): - for i, t in source: + def _format_lines(self, tokensource): + for i, t in HtmlFormatter._format_lines(self, tokensource): if i == 1: # it's a line of formatted code t = self._ansi_color_re.sub(self._replace_ansi_class, t) yield i, t diff --git a/plugins/m/code.py b/plugins/m/code.py index c2fc0286..e6c764b5 100644 --- a/plugins/m/code.py +++ b/plugins/m/code.py @@ -94,7 +94,7 @@ def _highlight(code, language, options, *, is_block, filters=[]): del options['hl-lines'] if isinstance(lexer, ansilexer.AnsiLexer): - formatter = ansilexer.HtmlAnsiFormatter(**options) + formatter = ansilexer.HtmlAnsiFormatter(nowrap=True, **options) else: formatter = HtmlFormatter(nowrap=True, **options) -- 2.30.2