Skip to content

Commit

Permalink
Merge pull request ipython#1921 from bfroehle/_1890_magic_arguments_d…
Browse files Browse the repository at this point in the history
…ocstring

magic_arguments: dedent but otherwise preserve indentation.

Previously magic_arguments stripped all whitespace at the beginning of each line, interfering with formatting syntax which relies on indentation to give context (e.g., code blocks). Now the docstring text is passed through dedent to strip the global indentation before being handed off to `RawDescriptionHelpFormatter` which preserves any remaining indentation.

Thanks to @rkern for suggesting the solution approach.

Closes ipythongh-1890.
  • Loading branch information
fperez committed Jun 12, 2012
2 parents 29dc2c6 + df97f2d commit 673e533
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion IPython/core/magic_arguments.py
Expand Up @@ -50,7 +50,13 @@ def magic_cool(self, arg):
from IPython.external import argparse
from IPython.core.error import UsageError
from IPython.utils.process import arg_split
from IPython.utils.text import dedent

class MagicHelpFormatter(argparse.RawDescriptionHelpFormatter):
""" A HelpFormatter which dedents but otherwise preserves indentation.
"""
def _fill_text(self, text, width, indent):
return argparse.RawDescriptionHelpFormatter._fill_text(self, dedent(text), width, indent)

class MagicArgumentParser(argparse.ArgumentParser):
""" An ArgumentParser tweaked for use by IPython magics.
Expand All @@ -62,7 +68,7 @@ def __init__(self,
epilog=None,
version=None,
parents=None,
formatter_class=argparse.HelpFormatter,
formatter_class=MagicHelpFormatter,
prefix_chars='-',
argument_default=None,
conflict_handler='error',
Expand Down

0 comments on commit 673e533

Please sign in to comment.