-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from mpacer/pretty_articles
Pretty articles
- Loading branch information
Showing
7 changed files
with
91 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import textwrap | ||
|
||
def dedent(text): | ||
"""Equivalent of textwrap.dedent that ignores unindented first line. | ||
This means it will still dedent strings like: | ||
'''foo | ||
is a bar | ||
''' | ||
For use in wrap_paragraphs. | ||
Taken from https://github.com/ipython/ipython_genutils/text.py | ||
""" | ||
|
||
if text.startswith('\n'): | ||
# text starts with blank line, don't ignore the first line | ||
return textwrap.dedent(text) | ||
|
||
# split first line | ||
splits = text.split('\n',1) | ||
if len(splits) == 1: | ||
# only one line | ||
return textwrap.dedent(text) | ||
|
||
first, rest = splits | ||
# dedent everything but the first line | ||
rest = textwrap.dedent(rest) | ||
return '\n'.join([first, rest]) |