Remove common indentation of code blocks.
This commit is contained in:
parent
74493fa79d
commit
89bf34ed46
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user