chiark / gitweb /
m.code: fix AnsiLexer to actually do the right thing with pygments 2.12+.
authorVladimír Vondruš <mosra@centrum.cz>
Mon, 16 Sep 2024 11:55:48 +0000 (13:55 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Mon, 16 Sep 2024 11:58:02 +0000 (13:58 +0200)
That extra removed argument did make it "work", but due to the internals
being different, all ANSI output was additionally wrapped in
<div class="highlight">. Now it's not anymore.

documentation/doxygen.py
plugins/ansilexer.py
plugins/m/code.py

index 93accf172314841726614c4080ab633c64e96611..17faec3c81fa533db17131b8effc196a9a5d83ea 100755 (executable)
@@ -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)
 
index 4df25dcefb9957245be5a3745adfa6674a60e1c1..3268c6956bd13c67cca6a3dbe398176ea2e4bd05 100644 (file)
@@ -290,12 +290,8 @@ class HtmlAnsiFormatter(HtmlFormatter):
         '(?P<Suffix>")'
     )
 
-    # 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
index c2fc028615fb28ed18a2715ccd033aefe4361dc9..e6c764b52d71aefaf6097e9a4554510025dfcc67 100644 (file)
@@ -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)