From 401ff081c7e542a6a206af004d5c7b96801bd30a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 9 Jun 2020 01:58:08 +0200 Subject: [PATCH] documentation/doxygen,m.code: unify code whitespace stripping. 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 | 4 ++-- plugins/m/code.py | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/documentation/doxygen.py b/documentation/doxygen.py index 46475837..4e82f243 100755 --- a/documentation/doxygen.py +++ b/documentation/doxygen.py @@ -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}'.format( 'pre' if code_block else 'code', diff --git a/plugins/m/code.py b/plugins/m/code.py index 65e15302..c854176f 100644 --- a/plugins/m/code.py +++ b/plugins/m/code.py @@ -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 -- 2.30.2