Remove common indentation of code blocks.

This commit is contained in:
Sergio Martínez Portela 2022-08-27 13:33:47 +02:00
parent 74493fa79d
commit 89bf34ed46

View File

@ -288,7 +288,20 @@ def render_list_item(element, acc):
def render_code_block(element, acc):
acc.append('<pre><code>')
acc.append(html.escape(element.lines))
content = html.escape(element.lines)
# Remove indentation common to all lines
base_indentation = min([
len(l) - len(l.lstrip(' '))
for l in content.split('\n')
if len(l.strip()) > 0
])
content_lines = [
l[base_indentation:]
for l in content.split('\n')
]
acc.append('\n'.join(content_lines))
acc.append('</code></pre>')
def render_results_block(element, acc):