From fcb44ca1a614c2f4104f63a970c7f8a37ac1e257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Tue, 20 Dec 2022 00:56:53 +0100 Subject: [PATCH] Apply "unindent" to highlighted code blocks too. --- scripts/generate.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/generate.py b/scripts/generate.py index 589d4f3..ed8bc2b 100644 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -462,6 +462,12 @@ def render_block(content, acc, _class, is_code): acc.append('') # Remove indentation common to all lines + acc.append(unindent(content)) + if is_code: + acc.append('') + acc.append('') + +def unindent(content): base_indentation = min([ len(l) - len(l.lstrip(' ')) for l in content.split('\n') @@ -471,18 +477,15 @@ def render_block(content, acc, _class, is_code): l[base_indentation:] for l in content.split('\n') ] - - acc.append('\n'.join(content_lines)) - if is_code: - acc.append('') - acc.append('') + return '\n'.join(content_lines) def render_code_block(element, acc, headline, graph): code = element.lines + if element.arguments is not None and len(element.arguments) > 0 : try: lexer = pygments.lexers.get_lexer_by_name(element.arguments.split()[0], stripall=True) - content = pygments.highlight(code, + content = pygments.highlight(unindent(code), lexer, pygments.formatters.HtmlFormatter() )