chiark / gitweb /
documentation/doxygen,m.code: unify code whitespace stripping.
authorVladimír Vondruš <mosra@centrum.cz>
Mon, 8 Jun 2020 23:58:08 +0000 (01:58 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Mon, 8 Jun 2020 23:59:44 +0000 (01:59 +0200)
For some reason due to an accident m.code wasn't strip leading
whitespace in inline code. Of course no test caught this.

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

index 464758375a99b058283704c47b5e0ca725dd1242..4e82f243cc582e81eb90a9f917971955f33880e3 100755 (executable)
@@ -1239,10 +1239,10 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET.
                 formatter = ansilexer.HtmlAnsiFormatter()
             else:
                 formatter = HtmlFormatter(nowrap=True)
-            highlighted = highlight(code, lexer, formatter)
+
+            highlighted = highlight(code, lexer, formatter).rstrip()
             # Strip whitespace around if inline code, strip only trailing
             # whitespace if a block
-            highlighted = highlighted.rstrip()
             if not code_block: highlighted = highlighted.lstrip()
             out.parsed += '<{0} class="{1}{2}">{3}</{0}>'.format(
                 'pre' if code_block else 'code',
index 65e153027b29923e3abdca9d6ca63b591dab6c3f..c854176f7c408419aefde324f21ec6b36c02ed69 100644 (file)
@@ -76,19 +76,21 @@ def _highlight(code, language, options, *, is_block, filters=[]):
     f = filters_pre.get(lexer.name)
     if f: code = f(code)
 
-    parsed = highlight(code, lexer, formatter).rstrip()
-    if not is_block: parsed.lstrip()
+    highlighted = highlight(code, lexer, formatter).rstrip()
+    # Strip whitespace around if inline code, strip only trailing whitespace if
+    # a block
+    if not is_block: highlighted = highlighted.lstrip()
 
     global filters_post
     # First apply local post filters, if any
     for filter in filters:
         f = filters_post.get((lexer.name, filter))
-        if f: parsed = f(parsed)
+        if f: highlighted = f(highlighted)
     # Then a global post filter, if any
     f = filters_post.get(lexer.name)
-    if f: parsed = f(parsed)
+    if f: highlighted = f(highlighted)
 
-    return class_, parsed
+    return class_, highlighted
 
 class Code(Directive):
     required_arguments = 1