diff --git a/scripts/generate.py b/scripts/generate.py index 944c57a..01aef10 100644 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -288,7 +288,20 @@ def render_list_item(element, acc): def render_code_block(element, acc): acc.append('
')
- 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('
')
def render_results_block(element, acc):