Remove leading indentation. If the first line starts with a spaces or tabs, the same whitespace will be removed from each following line in the cell.
(lines)
| 32 | return lines |
| 33 | |
| 34 | def leading_indent(lines): |
| 35 | """Remove leading indentation. |
| 36 | |
| 37 | If the first line starts with a spaces or tabs, the same whitespace will be |
| 38 | removed from each following line in the cell. |
| 39 | """ |
| 40 | if not lines: |
| 41 | return lines |
| 42 | m = _indent_re.match(lines[0]) |
| 43 | if not m: |
| 44 | return lines |
| 45 | space = m.group(0) |
| 46 | n = len(space) |
| 47 | return [l[n:] if l.startswith(space) else l |
| 48 | for l in lines] |
| 49 | |
| 50 | class PromptStripper: |
| 51 | """Remove matching input prompts from a block of input. |