Let’s say I have a block of code that is copied from one file to a new blank file. The code from the original file is indented as it should be, however I want to un-indent the code when placed in a new blank file. However, I only want to un-indent to the base indention, meaning I don’t want to remove ALL indentations. Make sense?
For example, when pasting a code block into a newly created file, it might look like this:
<h1>Title</h1>
<div>
<p>This is a nested paragraph</p>
<ul>
<li>Even deeper!</li>
</lu>
</div>
I’m wanting to create a function, with regex and/or python, that will take the text above and turn it into this:
<h1>Title</h1>
<div>
<p>This is a nested paragraph</p>
<ul>
<li>Even deeper!</li>
</lu>
</div>
The only difference is the lead indentation.
Any ideas or help will be greatly appreciated!
Look at the
dedentfunction in thetextwrapmodule: http://docs.python.org/library/textwrap.html#textwrap.dedent