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() )