-
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.
add pretty _repr_html_ to article to make links when displayed in not…
…ebook Add utils module for the dedent method & home for future utilities
- Loading branch information
Showing
2 changed files
with
85 additions
and
30 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
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]) |