From: Vladimír Vondruš Date: Mon, 8 Jun 2020 23:58:08 +0000 (+0200) Subject: documentation/doxygen,m.code: unify code whitespace stripping. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=401ff081c7e542a6a206af004d5c7b96801bd30a;p=blog.git 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. --- 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